|
- Option Explicit Public Declare Function RegisterShellHookWindow Lib "user32" (ByVal hwnd As Long) As Long ''use in NT5
- Option Explicit
- Public Declare Function RegisterShellHookWindow Lib "user32" (ByVal hwnd As Long) As Long ''use in NT5
- Public Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (ByVal lpString As String) As Long
- Public Declare Function DeregisterShellHookWindow Lib "user32" (ByVal hwnd As Long) As Long
- Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
- Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
- Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
- Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthW" (ByVal hwnd As Long) As Long
- Private Const HSHELL_WINDOWCREATED = 1 '' 顶级窗体被创建
- Private Const HSHELL_WINDOWDESTROYED = 2 '' 顶级窗体即将被关闭
- Private Const HSHELL_ACTIVATESHELLWINDOW = 3 '' SHELL 的主窗体将被激活
- Private Const HSHELL_WINDOWACTIVATED = 4 '' 顶级窗体被激活
- Private Const HSHELL_GETMINRECT = 5 '' 顶级窗体被最大化或最小化(本例未用)
- Private Const HSHELL_REDRAW = 6 '' Windows 任务栏被刷新
- Private Const HSHELL_TASKMAN = 7 '' 任务列表的内容被选中
- Private Const HSHELL_LANGUAGE = 8 '' 中英文切换或输入法切换
- Private Const HSHELL_SYSMENU = 9 ''显示系统菜单
- Private Const HSHELL_ENDTASK = 10 ''顶级窗体被强制关闭
- Private Const HSHELL_ACCESSIBILITYSTATE = 11
- Private Const HSHELL_APPCOMMAND = 12 ''没有被程序处理的APPCOMMAND。见WM_APPCOMMAND
- Private Const HSHELL_WINDOWREPLACED = 13 ''wParam=被替换的顶级窗口的hWnd
- Private Const HSHELL_WINDOWREPLACING = 14 ''wParam=替换顶级窗口的窗口hWnd
- Private Const HSHELL_HIGHBIT = &H8000& ''掩码
- Private Const HSHELL_FLASH = (HSHELL_REDRAW Or HSHELL_HIGHBIT) ''标题闪烁
- Private Const HSHELL_RUDEAPPACTIVATED = (HSHELL_WINDOWACTIVATED Or HSHELL_HIGHBIT) ''不知道干吗的
- Public Const GWL_WNDPROC = -4
- Private Const MAX_PATH = 260
- Public Shell_Hook_Msg_ID As Long
- Public LogWinOldProc As Long
- Public Function WndProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
- Dim strCapTion As String
- Select Case wMsg
- Case Shell_Hook_Msg_ID
- Dim szTmp As String
- Select Case wParam
- Case HSHELL_WINDOWACTIVATED
- szTmp = String(MAX_PATH, vbNullChar)
- Call GetWindowText(lParam, szTmp, MAX_PATH)
- strCapTion = Left$(szTmp, GetWindowTextLength(lParam))
- If InStr(strCapTion, "Windows 图片和传真查看器") <> 0 Then
- MsgBox "抓图瞬间,这个时候可以抓图" '---------这里可以换成窗体事件 比如:Form1.Timer1.Enabled = True TIMER 控件的控制属性
- End If
- If InStr(LCase(strCapTion), "acdsee") <> 0 Then
- MsgBox "抓图瞬间,这个时候可以抓图"
- End If
- If InStr(strCapTion, "画图") <> 0 Then
- MsgBox "抓图瞬间,这个时候可以抓图"
- End If
- End Select
- End Select
- WndProc = CallWindowProc(LogWinOldProc, hwnd, wMsg, wParam, lParam)
- End Function
- Option Explicit
- Private Sub Form_Load()
- Shell_Hook_Msg_ID = RegisterWindowMessage("SHELLHOOK")
- RegisterShellHookWindow (Me.hwnd) '' 调用未公开的函数进行注册
- LogWinOldProc = SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf WndProc)
- End Sub
- Private Sub Form_Unload(Cancel As Integer)
- DeregisterShellHookWindow Me.hwnd
- SetWindowLong Me.hwnd, GWL_WNDPROC, LogWinOldProc
- End Sub
复制代码 |
|