Ask the Delphi Pro 10-Minute Solutions
 |
Disabling the System Keys from Your Application
By Brendan Delumpa
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?
This solution is pretty quick.... The best way I've seen yet to disable the system keys from your application 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) are disabled. You can perform this trickery by calling a WinAPI function, SystemParametersInfo. For a more in-depth discussion about this function, 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:
BOOL SystemParametersInfo(
UINT uiAction, // system parameter to query or set
UINT uiParam, // depends on action to be taken
PVOID pvParam, // depends on action to be taken
UINT fWinIni // user profile update flag
);
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:
To disable the keystrokes, write this:
SystemParametersInfo(SPI_SCREENSAVERRUNNING, 1, @ptr, 0);
To enable the keystrokes, write this:
SystemParametersInfo(SPI_SCREENSAVERRUNNING, 0, @ptr, 0);
Not much to it, is there? Thanks to the folks on the Borland Forums for providing this information!
|
|
|