Author: Land island Studio
In Windows 98, we know that systemparametersinfo (spi_setfasttaskswitch, 1, @ temp, 0); is used to shield win + Ctrl + Del, however, this method won't work in NT operating systems such as Windows XP/Windows 2000. Here I will provide you with a new method that uses the hook interception method, to block system buttons. This example contains detailed source code and demo programs.
Source code and demo programs.
The code for implementation is as follows:
{*************************************** ****************************************
Xotecexpress visual component library [Land island Studio]
Copyright (c) 2008 xotec studio. [pengjunli]
By: pengjunli build: 2008-06
E-mail: iinsnian@126.com XOtec@vip.QQ.com QQ: 442801172
**************************************** ***************************************}
Unit unit2;
Interface
Uses
Windows, messages, sysutils, variants, classes;
Type
Tagkbdllhookstruct = packed record
Vkcode: DWORD;
Scancode: DWORD;
Flags: DWORD;
Time: DWORD;
Dwextrainfo: DWORD;
End;
KBDLLHOOKSTRUCT = tagkbdllhookstruct;
Pkbdllhookstruct = ^ KBDLLHOOKSTRUCT;
Const
Wh_keyboard_ll = 13;
Llkhf_altdown = $20;
// Use the Hook method to shield system buttons
Function disabletaskkeys (Disable: Boolean): Boolean;
Implementation
VaR
Hhklowlevelkybd: hhook;
{Lowlevelkeyboardproc}
Function lowlevelkeyboardproc (ncode: integer; wparam: wparam; lparam: lparam): lresult; stdcall;
VaR
Featkeystroke: bool;
P: pkbdllhookstruct;
Begin
Result: = 0;
Featkeystroke: = false;
P: = pkbdllhookstruct (lparam );
If (ncode = hc_action) Then // when the ncode value is hc_action, it indicates that the wparam and lparam parameters include the key message.
Begin
// Intercept the key message and test whether the key is Ctrl + ESC, ALT + tab, and ALT + ESC.
Case wparam
Wm_keydown, wm_syskeydown, wm_keyup, wm_syskeyup:
Featkeystroke: =
(P. vkcode = vk_tab) and (P. flags and llkhf_altdown) <> 0) or // Alt + Tab
(P. vkcode = vk_escape) and (P. flags and llkhf_altdown) <> 0) or //
(P. vkcode = vk_lwin) or (P. vkcode = vk_rwin) or (P. vkcode = vk_apps) or // shield the win button
(P. vkcode = vk_escape) and (getkeystate (vk_control) and $8000) <> 0) or
(P. vkcode = vk_f4) and (P. flags and llkhf_altdown) <> 0) or
(P. vkcode = vk_space) and (P. flags and llkhf_altdown) <> 0) or
(P. vkcode = vk_control) and (P. vkcode = llkhf_altdown and P. Flags) and (P. vkcode = vk_delete )));
End;
End;
If featkeystroke = true then
Result: = 1;
If ncode <> 0 then
Result: = callnexthookex (0, ncode, wparam, lparam );
End;
{Disabletaskkeys}
Function disabletaskkeys (Disable: Boolean): Boolean;
Begin
Result: = false;
If (hhklowlevelkybd = 0) and disable then
Begin
Hhklowlevelkybd: = setwindowshookexw (wh_keyboard_ll, lowlevelkeyboardproc, hinstance, 0); // set the hook
Result: = hhklowlevelkybd <> 0; // The setting is successful.
End else if not disable and (hhklowlevelkybd <> 0) then
Begin
If unhookwindowshookex (hhklowlevelkybd) Then // uninstall the keyboard hook
Begin
Result: = true;
Hhklowlevelkybd: = 0;
End;
End;
End;
End.