|
|
Title | Lock the computer and trap the mouse so the user cannot move it outside of the form |
Description | This example shows how to lock the computer and trap the mouse so the user cannot move it outside of the form in Visual Basic 6. It uses the SystemParametersInfo API function to tell the system a screen saver is running. That disables Alt-Tab and Ctl-Alt-Del. |
Keywords | lock computer, screen saver, mouse, trap mouse |
Categories | Windows, Miscellany |
|
|
Thanks to Chris Wagg.
The program uses the ClipCursor API function to confine the mouse to the form. It then uses the SystemParametersInfo API function to tell the system a screen saver is running. That disables Alt-Tab and Ctl-Alt-Del. The user can see what's on the screen but cannot get the mouse out of the form.
|
|
Private Sub cmdLockWorkstation_Click()
Dim window As RECT
cmdLockWorkstation.Enabled = False
cmdUnlockWorkstation.Enabled = True
cmdExit.Enabled = False
' Restrict the mouse to this window.
GetWindowRect hwnd, window
ClipCursor window
' Tell the system a screen saver is running.
SystemParametersInfo SPI_SCREENSAVERRUNNING, True, 0, 0
End Sub
|
|
To unlock the computer, the program uses the ClipCursor API function to free the mouse. It then calls the SystemParametersInfo API function to indicate that no screen saver is running.
|
|
Private Sub cmdUnlockWorkstation_Click()
cmdLockWorkstation.Enabled = True
cmdUnlockWorkstation.Enabled = False
cmdExit.Enabled = True
' Free the mouse
ClipCursorByNum 0&
' Tell the system no screen saver is running.
SystemParametersInfo SPI_SCREENSAVERRUNNING, False, 0, 0
End Sub
|
|
|
|
|
|