Author: Lou Adler
When my application is running, I'd like to prevent users from using Ctrl-Alt-Del
and Alt- Tab. What's the best way to do this?
Answer:
This is pretty quick one... The best way I've seen yet is to trick Windows into
thinking that a screen saver is running. When Windows thinks a screensaver is
active, Ctrl-Alt-Del and Alt-Tab (Win95 only for this) are disabled. You can
perform this trickery by calling a WinAPI function, SystemParametersInfo. For a
more in-depth discussion about what this function does, I encourage you to refer to
the online help.
In any case, SystemParametersInfo takes four parameters. Here's its C declaration
from the Windows help file:
1 BOOL SystemParametersInfo(
2 UINT uiAction, // system parameter to query or set
3 UINT uiParam, // depends on action to be taken
4 PVOID pvParam, // depends on action to be taken
5 UINT fWinIni // user profile update flag
6 );
For our purposes we'll set uiAction to SPI_SCREENSAVERRUNNING, uiParam to 1 or 0 (1
to disable the keys, 0 to re-enable them), pvParam to a "dummy" pointer address,
then fWinIni to 0. Pretty straight-forward. Here's what you do:
7
8 //To disable the keystrokes, write this:
9
10 SystemParametersInfo(SPI_SCREENSAVERRUNNING, 1, @ptr, 0);
11
12 //To enable the keystrokes, write this:
13
14 SystemParametersInfo(SPI_SCREENSAVERRUNNING, 0, @ptr, 0);
Not much to it, is there? Thanks to the folks on the Borland Forums for providing this information!
|