|
-
Mar 30th, 2011, 09:49 AM
#1
Need some help understanding this advanced code which uses threading, pointers, etc..
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:
Public Function LockSystemAndShow(ByVal myDForm As Form) As Boolean
myForm = myDForm
'Dim owner As Control = TryCast(Form1.Button1, Control)
Dim scr As Screen
'If owner Is Nothing Then
scr = Screen.PrimaryScreen
'Else
'scr = Screen.FromControl(owner)
'End If
Dim background As Bitmap = New Bitmap(scr.Bounds.Width, scr.Bounds.Height)
Using g As Graphics = Graphics.FromImage(background)
g.CopyFromScreen(0, 0, 0, 0, scr.Bounds.Size)
Using br As Brush = New SolidBrush(Color.FromArgb(192, Color.Black))
g.FillRectangle(br, scr.Bounds)
End Using
'If owner IsNot Nothing Then
' Dim form As Form = owner.FindForm()
' g.CopyFromScreen(form.Location, form.Location, form.Size)
' Using br As Brush = New SolidBrush(Color.FromArgb(128, Color.Black))
' g.FillRectangle(br, New Rectangle(Form.Location, Form.Size))
'End Using
'End If
End Using
Dim originalThread As IntPtr
Dim originalInput As IntPtr
Dim newDesktop As IntPtr
originalThread = GetThreadDesktop(Thread.CurrentThread.ManagedThreadId)
originalInput = OpenInputDesktop(0, False, DESKTOP_SWITCHDESKTOP)
newDesktop = CreateDesktop("Desktop" & Guid.NewGuid().ToString(), Nothing, Nothing, 0, GENERIC_ALL, Nothing)
SetThreadDesktop(newDesktop)
SwitchDesktop(newDesktop)
Dim newThread As Thread = New Thread(AddressOf NewThreadMethod)
newThread.CurrentCulture = Thread.CurrentThread.CurrentCulture
newThread.CurrentUICulture = Thread.CurrentThread.CurrentUICulture
newThread.Start(New abcLockSystemParameters(newDesktop, background))
newThread.Join()
SwitchDesktop(originalInput)
SetThreadDesktop(originalThread)
CloseDesktop(newDesktop)
CloseDesktop(originalInput)
Return True 'Result
End Function
Private Sub NewThreadMethod(ByVal params As Object)
Dim v As abcLockSystemParameters = DirectCast(params, abcLockSystemParameters)
SetThreadDesktop(v.NewDesktop)
Using f As Form = New BackgroundForm(v.Background)
f.Show()
myForm.ShowDialog() '~~~~ Show the login screen here
f.BackgroundImage = Nothing
Application.DoEvents()
Thread.Sleep(250)
End Using
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...
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|