
How-To... - Disable ALT+TAB and CTRL+ALT+DEL in your VB App
I can't really think of much point of disabling these keys in an application, apart from a screensaver, and an interactive screensaver, or an application you don't want closed down or the focus lost(like a nag screen). But, here is details on how to do it.
The way to do it is to make Windows think that the screensaver is active when your application is running, using the SystemsParamatersInfo API. This API call lets you change lots of windows things such as icons, wallpaper, and colours. Here we will use it to fool Windows into thinking the screensaver is active.
On a new form, insert the following code:-
'Modified version of KB #154868...
Private Declare Function
SystemParametersInfo Lib "user32" _
Alias "SystemParametersInfoA" (ByVal
uAction As Long, _
ByVal uParam As Long,
lpvParam As Any, ByVal
fuWinIni As Long) As Long
Private Const SPI_SCREENSAVERRUNNING
= 97
Dim ret As
Integer
Dim pOld As Boolean
Private Sub Form_Load()
'The line below calls the function and passes
'the constant and TRUE to fool Windows into thinking
'the screensaver is running and FALSE to do the opposite...
ret = SystemParametersInfo(SPI_SCREENSAVERRUNNING, True,
pOld, 0)
End Sub
Private Sub Form_Unload(Cancel
As Integer)
'NOTE: THIS MUST BE SET TO FALSE WHEN
'THE FORM OR APP CLOSES
'If you do not set it to false, these keys will not work
'with any app, or with anything in the Windows Environment...
ret = SystemParametersInfo(SPI_SCREENSAVERRUNNING, False,
pOld, 0)
End Sub
Finishing up...
Run the program and try any of the two key combos. Remember, when running it through the VB Environment, to click the X on the programs title bar, rather than the STOP button. The Call to 'turn the screensaver off' is in the Unload sub.
You can download this example by clicking here