Hi guys..

I had recently(2 months before ) found some code for locking the screen. Here's the link to that code submission in our CodeBank : http://www.vbforums.com/showthread.php?t=639579

I wish to get a clear idea of what it actually does. As it is a bit advanced code for me, I need your help.

Here's the main part of the code:
vb.net Code:
  1. Public Function LockSystemAndShow(ByVal myDForm As Form) As Boolean
  2.         myForm = myDForm
  3.  
  4.         'Dim owner As Control = TryCast(Form1.Button1, Control)
  5.         Dim scr As Screen
  6.         'If owner Is Nothing Then
  7.         scr = Screen.PrimaryScreen
  8.         'Else
  9.         'scr = Screen.FromControl(owner)
  10.         'End If
  11.         Dim background As Bitmap = New Bitmap(scr.Bounds.Width, scr.Bounds.Height)
  12.         Using g As Graphics = Graphics.FromImage(background)
  13.  
  14.             g.CopyFromScreen(0, 0, 0, 0, scr.Bounds.Size)
  15.             Using br As Brush = New SolidBrush(Color.FromArgb(192, Color.Black))
  16.                 g.FillRectangle(br, scr.Bounds)
  17.             End Using
  18.  
  19.             'If owner IsNot Nothing Then
  20.             ' Dim form As Form = owner.FindForm()
  21.             ' g.CopyFromScreen(form.Location, form.Location, form.Size)
  22.             ' Using br As Brush = New SolidBrush(Color.FromArgb(128, Color.Black))
  23.             ' g.FillRectangle(br, New Rectangle(Form.Location, Form.Size))
  24.             'End Using
  25.             'End If
  26.  
  27.         End Using
  28.  
  29.         Dim originalThread As IntPtr
  30.         Dim originalInput As IntPtr
  31.         Dim newDesktop As IntPtr
  32.  
  33.         originalThread = GetThreadDesktop(Thread.CurrentThread.ManagedThreadId)
  34.         originalInput = OpenInputDesktop(0, False, DESKTOP_SWITCHDESKTOP)
  35.  
  36.         newDesktop = CreateDesktop("Desktop" & Guid.NewGuid().ToString(), Nothing, Nothing, 0, GENERIC_ALL, Nothing)
  37.         SetThreadDesktop(newDesktop)
  38.         SwitchDesktop(newDesktop)
  39.  
  40.         Dim newThread As Thread = New Thread(AddressOf NewThreadMethod)
  41.         newThread.CurrentCulture = Thread.CurrentThread.CurrentCulture
  42.         newThread.CurrentUICulture = Thread.CurrentThread.CurrentUICulture
  43.         newThread.Start(New abcLockSystemParameters(newDesktop, background))
  44.         newThread.Join()
  45.  
  46.         SwitchDesktop(originalInput)
  47.         SetThreadDesktop(originalThread)
  48.  
  49.         CloseDesktop(newDesktop)
  50.         CloseDesktop(originalInput)
  51.  
  52.         Return True 'Result
  53.  
  54.     End Function
  55.  
  56.     Private Sub NewThreadMethod(ByVal params As Object)
  57.         Dim v As abcLockSystemParameters = DirectCast(params, abcLockSystemParameters)
  58.         SetThreadDesktop(v.NewDesktop)
  59.         Using f As Form = New BackgroundForm(v.Background)
  60.             f.Show()
  61.             myForm.ShowDialog()  '~~~~ Show the login screen here
  62.             f.BackgroundImage = Nothing
  63.             Application.DoEvents()
  64.             Thread.Sleep(250)
  65.         End Using
  66.     End Sub
Looks like pretty easy one, isn't it ? But it's a tough one for me.

Can you please help me to understand this code ?

Thanks in advance...