VB6 如何禁止WIN鍵 (工具列)

如何禁止 WIN鍵 (工具列)

因本人要製作 桌面鎖

目前已學會

★ALT+F4★無效化

★ALT+TAB★無效化

★CTRL+ALT+DELETE ( . ) ★無效化

★ALT+ESC★無效化

但就是 按鍵盤的 WIN鍵 就可以破解了 ..請問有禁止win建的源碼麻??

已更新項目:

感謝 世賢 的答案 已經完成囉~ 你有即時通麻!?

1 個解答

評分
  • 世賢
    Lv 7
    9 年前
    最佳解答

    http://zhidao.baidu.com/question/106839197.html

    2011-11-14 20:18:37 補充:

    '在表單

    Option Explicit

    Private Sub Form_Load()

     ' 安裝鉤子

     lHook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf CallKeyHookProc, App.hInstance, 0)

    End Sub

    Private Sub Form_Unload(Cancel As Integer)

     ' 卸載鉤子

     UnhookWindowsHookEx lHook

    End Sub

    '在模組

    Option Explicit

    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 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

    Public lHook As Long

    Dim p As KBDLLHOOKSTRUCT

    '鍵盤鉤子

    Public Function CallKeyHookProc(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.flags And LLKHF_ALTDOWN) <> 0) Or _

    2011-11-14 20:19:50 補充:

       ((p.vkCode = VK_ESCAPE) And ((GetKeyState(VK_CONTROL) And &H8000) <> 0)) Or _

       ((p.vkCode = 91) Or (p.vkCode = 92) Or (p.vkCode = 93))

       '判斷是否按下了:TAB+ALT、Esc+ALT、Alt(Alt+F4)、Esc+Ctrl、左右 Win 和徽標鍵

      End If

     End If

    2011-11-14 20:20:31 補充:

     If fEatKeystroke Then

      ' 設置為 1 可以屏蔽按鍵

      CallKeyHookProc = 1

     Else

      CallKeyHookProc = CallNextHookEx(0, nCode, wParam, ByVal lParam)

     End If

    End Function

    回答未完整的補充至意見

還有問題?馬上發問,尋求解答。