请问怎样屏蔽alt+F4,ctrl+alt+del,alt+tab
我曾经这样屏蔽alt+F4
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
cancel=1
End Sub
但总感觉不是太彻底。
至于怎样屏蔽ctrl+alt+del,alt+tab我是根本不知道,请高手赐教!
对于没打过sp1和sp2补丁的xp系统,方法如下:
把以下代码放入vb的模块中:
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Public Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Public Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public Const HC_ACTION = 0
Public Const WM_KEYDOWN = &H100
Public Const WM_KEYUP = &H101
Public Const WM_SYSKEYDOWN = &H104
Public Const WM_SYSKEYUP = &H105
Public Const VK_TAB = &H9
Public Const VK_CONTROL = &H11
Public Const VK_ESCAPE = &H1B
Public Const VK_F4 = vbKeyF4
Public Const WH_KEYBOARD_LL = 13
Public Const LLKHF_ALTDOWN = &H20
Public Type KBDLLHOOKSTRUCT
vkCode As Long
scanCode As Long
flags As Long
time As Long
dwExtraInfo As Long
End Type
Dim p As KBDLLHOOKSTRUCT
Public Function LowLevelKeyboardProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim fEatKeystroke As Boolean
If (nCode = HC_ACTION) Then
If wParam = WM_KEYDOWN Or wParam = WM_SYSKEYDOWN Or wParam = WM_KEYUP Or wParam = WM_SYSKEYUP Then
CopyMemory p, ByVal lParam, Len(p)
fEatKeystroke = _
((p.vkCode = VK_TAB) And ((p.flags And LLKHF_ALTDOWN) <> 0)) Or _
((p.vkCode = VK_ESCAPE) And ((p.flags And LLKHF_ALTDOWN) <> 0)) Or _
((p.vkCode = VK_ESCAPE) And ((GetKeyState(VK_CONTROL) And &H8000) <> 0)) Or _
((p.vkCode = 91) Or (p.vkCode = 92) Or (p.vkCode = 93)) Or _
((p.vkCode = VK_F4) And (p.flags And LLKHF_ALTDOWN) <> 0) '加入这行代码屏弊Alt+F4
End If
End If
If fEatKeystroke Then
LowLevelKeyboardProc = -1
Else
LowLevelKeyboardProc = CallNextHookEx(0, nCode, wParam, ByVal lParam)
End If
End Function
然后先在窗体的声明中加入:
Dim hhkLowLevelKybd As Long
在窗体的load事件中写上:
hhkLowLevelKybd = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf LowLevelKeyboardProc, App.hInstance, 0)
在窗体的unload事件中写上:
If hhkLowLevelKybd <> 0 Then UnhookWindowsHookEx hhkLowLevelKybd
以上代码在没有打过sp1和sp2补丁的xp系统中,可以屏蔽掉xp中所有定义的系统热键(包括CTRL+ESC、ALT+TAB、ALT+F4、WIN键+任何键的组合、CTRL+ALT+DEL、等等)
对于打过sp1和sp2补丁的xp系统,以上代码不能屏蔽CTRL+ALT+DEL组合键。但是可以这样:
在窗体中的load事件中加入:
s = Environ("windir")
s = s + "\system32\taskmgr.exe"
Open s For Random Lock Read As #1
在窗体的unload事件中加入:
Close #1
就可以实现屏蔽CTRL+ALT+DEL组合键,再组合上面的代码,就可以屏蔽掉xp系统中所有已经定义的系统热键了。