home *** CD-ROM | disk | FTP | other *** search
- VERSION 4.00
- Begin VB.Form Form1
- Appearance = 0 'Flat
- BackColor = &H80000005&
- BorderStyle = 1 'Fixed Single
- Caption = "Ctrl Esc Blocker"
- ClientHeight = 2325
- ClientLeft = 1095
- ClientTop = 1485
- ClientWidth = 4440
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 700
- size = 8.25
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- ForeColor = &H80000008&
- Height = 2730
- Left = 1035
- LinkTopic = "Form1"
- ScaleHeight = 2325
- ScaleWidth = 4440
- Top = 1140
- Width = 4560
- Begin VB.CheckBox Check1
- Appearance = 0 'Flat
- BackColor = &H80000005&
- Caption = "Block Ctrl-Esc"
- ForeColor = &H80000008&
- Height = 285
- Left = 120
- TabIndex = 3
- Top = 1260
- Value = 1 'Checked
- Width = 1575
- End
- Begin VB.CommandButton Exit
- Appearance = 0 'Flat
- BackColor = &H80000005&
- Caption = "Exit"
- Height = 555
- Left = 3000
- TabIndex = 0
- Top = 1680
- Width = 1305
- End
- Begin DwshkLibDemo.WinHook WinHook2
- Left = 690
- Top = 1680
- _Version = 262144
- _ExtentX = 847
- _ExtentY = 847
- _StockProps = 0
- Notify = 0
- RegMessage1 = ""
- RegMessage2 = ""
- RegMessage3 = ""
- RegMessage4 = ""
- RegMessage5 = ""
- Monitor = 6
- HookType = 4
- Messages = "CTRL_ESC.frx":0000
- Keys = "CTRL_ESC.frx":042C
- End
- Begin DwshkLibDemo.WinHook WinHook1
- Left = 120
- Top = 1680
- _Version = 262144
- _ExtentX = 847
- _ExtentY = 847
- _StockProps = 0
- Notify = 0
- RegMessage1 = ""
- RegMessage2 = ""
- RegMessage3 = ""
- RegMessage4 = ""
- RegMessage5 = ""
- Monitor = 6
- HookEnabled = -1 'True
- Messages = "CTRL_ESC.frx":0454
- Keys = "CTRL_ESC.frx":0884
- End
- Begin VB.Label Label2
- Appearance = 0 'Flat
- BackColor = &H80000005&
- Caption = "This allows you to bring up the system Task List only from the System-Switch To menu command."
- ForeColor = &H80000008&
- Height = 405
- Left = 90
- TabIndex = 2
- Top = 690
- Width = 4245
- End
- Begin VB.Label Label1
- Appearance = 0 'Flat
- BackColor = &H80000005&
- Caption = "This sample program prevents the Ctl+Esc key from bringing up the system TaskList."
- ForeColor = &H80000008&
- Height = 465
- Left = 360
- TabIndex = 1
- Top = 90
- Width = 3675
- End
- Attribute VB_Name = "Form1"
- Attribute VB_Creatable = False
- Attribute VB_Exposed = False
- Option Explicit
- Private Declare Sub dwDWORDto2Integers Lib "dwspy32.dll" (ByVal l&, lw%, lh%)
- Private Declare Function GetVersion Lib "kernel32.dll" () As Long
- Private Declare Function GetForegroundWindow Lib "user32.dll" () As Long
- Private Declare Function SetForegroundWindow Lib "user32.dll" (ByVal hwnd As Long) As Long
- Dim foregroundwin As Long
- Const WM_SYSCOMMAND = &H112&
- Const WM_HOTKEY = &H312&
- Const SC_TASKLIST = &HF130&
- Const MOD_CONTROL = &H2
- Const VK_ESCAPE = &H1B
- Private Sub Check1_Click()
- If Check1.Value Then
- ' prevent the Ctl+Esc key from bringing up the task list
- WinHook1.HookEnabled = True
- Else
- WinHook1.HookEnabled = False
- End If
- End Sub
- Private Sub Exit_Click()
- Unload Me
- End Sub
- Private Sub Form_Load()
- Dim loword As Integer, hiword As Integer, l As Long
- If Check1.Value Then
- ' prevent the Ctl+Esc key from bringing up the task list
- WinHook1.HookEnabled = True
- Else
- WinHook1.HookEnabled = False
- End If
- ' check if Windows NT
- l = GetVersion()
- Debug.Print Hex$(l)
- dwDWORDto2Integers l, loword, hiword
- If hiword And &H8000 Then Exit Sub ' not Windows NT
- WinHook2.HookEnabled = True
- End Sub
- Private Sub WinHook1_WndMessage(wnd As Long, msg As Long, wp As Long, lp As Long, nodef As Integer)
- Dim loword As Integer, hiword As Integer, l As Long
- ' So far, we found two situations that may occur when the user presses the Ctl+Esc key.
- ' In Windows 95, a WM_SYSCOMMAND message is sent to the Program Manager application (yes
- ' there is such a thing, it's just hidden) to open the "Start" menu. In Windows NT, a
- ' WM_HOTKEY message is sent to the Task Manager application (it also exists, but is also
- ' hidden) to display the Task List. Also, if you double-click the desktop in Windows NT,
- ' a WM_SYSCOMMAND with the SC_TASKLIST flag will be generated. This situation is handled
- ' exactly the same as if the user hit Ctl+Esc in Windows 95. This application shows how
- ' to discard these messages and prevent the default Ctl+Esc command from happening.
- ' You cannot use tbe Keyboard Hook to throw the Ctrl-Esc key message away
- ' because these messages are sent before the Key message.
- If msg = WM_SYSCOMMAND Then
- If wp = SC_TASKLIST Then
- ' Set nodef to True to prevent other windows hooks from processing the message
- ' and set msg to 0 (Windows will ignore the message if it is 0). Refer to the
- ' SpyWorks-VB manual's section on the nodef parameter in SBCHOOK.VBX on why
- ' we cannot just set nodef = True.
- nodef = True
- msg = 0
- End If
- End If
- If msg = WM_HOTKEY Then
- dwDWORDto2Integers lp, loword, hiword
- ' Make sure it's the Ctl+Esc keys
- If (loword = MOD_CONTROL) And (hiword = VK_ESCAPE) Then
- ' Set nodef to True to prevent other windows hooks from processing the message
- ' and set msg to 0 (Windows will ignore the message if it is 0). Refer to the
- ' SpyWorks-VB manual's section on the nodef parameter in SBCHOOK.VBX on why
- ' we cannot just set nodef = True.
- nodef = True
- msg = 0
-
- ' One side effect in Windows NT with the Ctl+Esc key is that focus is lost
- ' from the current application even when you prevent the hot key message
- ' from being sent. Therefore, we need to keep track of the foreground window
- ' and set the focus back to that window.
-
- ' Normally, you do not want to change the focus in the middle of a message, but
- ' in this case the focus was never actually set. A safer method is to use the
- ' PostEvent.
- l = SetForegroundWindow(foregroundwin)
- End If
- End If
- End Sub
- Private Sub WinHook2_WndMessage(wnd As Long, msg As Long, wp As Long, lp As Long, nodef As Integer)
- Dim loword As Integer, hiword As Integer
- Dim hfwnd As Long
- ' keeps track of the active foreground window so we can set it back
- ' if ctl+esc is hit while running in Windows NT
- dwDWORDto2Integers wp, loword, hiword
- hfwnd = GetForegroundWindow()
- If hfwnd <> 0 Then foregroundwin = hfwnd
- End Sub
-