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!

 
Other 10-Minute Solutions
 Trapping Messages Sent to an Application
 Getting the Number of Records From a Fixed-Length ASCII File
 Performing Incremental Searches with a TListbox
 Resizing the Drop-down List of a TComboBo
 Disabling the System Keys from Your Application
 Making A Secondary Form Independent of the Main Form
 Creating a System Tray Application
 Opening and Closing a CD Tray
 Hiding an Application from Windows
 Make a List Box Track the Mouse
 Running a Program at Startup
 Creating A Skin Component
 Dynamically Load Components From Packages at Run Time
 Obtain All Values from Multivalue Input Fields in WebBroker Applications
 Migrate Your BDE Applications to Linux with dbExpress
 Create a Multiline Button Component
 Update and Maintain dbExpress's Unidirectional, Read-Only Datasets
 Use ActionBands to Enable End Users to Customize Your Delphi Applications
 Produce HTML Reporting Output with WebBroker Components
  Convert XML Documents into Different Formats with the XSL Template Language


Ask the Delphi Pro | Who is the Pro? | Usage Policies | Ask a Question | Search | Feedback


Sponsored Links


Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map
Jupiterweb networks

internet.comearthweb.comDevx.comClickZ

Search Jupiterweb:

Jupitermedia Corporation has four divisions:
JupiterWeb, JupiterResearch, JupiterEvents, and JupiterImages

Copyright 2004 Jupitermedia Corporation All Rights Reserved.
Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Jupitermedia Corporate Info | Newsletters | Tech Jobs | E-mail Offers