目前钩链的钩子信息传递到下一个钩子程序
#Include <WinAPI.au3>
_WinAPI_CallWindowProc($lpPrevWndFunc, $hWnd, $Msg, $wParam, $lParam)
$lpPrevWndFunc | 先前的窗口进程指针. 如果这个值是通过调用 _WinAPI_GetWindowLong 函数和设置其 $iIndex 参数值为 $GWL_WNDPROC 或 $DWL_DLGPROC 获得, 它实际上是任何一个窗口或对话框程序的地址, 或对 _WinAPI_CallWindowProc 才有的特殊意义内值. |
$hWnd | 接收消息的窗口程序句柄 |
$Msg | 指定消息 |
$wParam | 指定附加消息的特定信息,这个参数的内容取决于 $Msg 参数值的信息 |
$lParam | 指定附加消息的特定信息,这个参数的内容取决于 $Msg 参数值的信息 |
返回指定消息处理的结果且取决于对信息的发送 |
在MSDN中搜索
#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <GuiMenu.au3>
#include <WinAPI.au3>
Global $ContextMenu, $CommonMenuItem, $FileMenuItem, $ExitMenuItem
Global $hGui, $cInput, $wProcOld
_Main()
Func _Main()
Local $cInput2, $wProcNew, $DummyMenu
$hGui = GUICreate("Type or paste some stuff", 400, 200, -1, -1, $WS_THICKFRAME, -1)
$cInput = GUICtrlCreateInput("", 20, 20, 360, 20)
$cInput2 = GUICtrlCreateInput("", 20, 50, 360, 20)
GUICtrlCreateLabel("abcd", 1, 1, 30, 18)
GUICtrlSetCursor(-1, 9)
$wProcNew = DllCallbackRegister("_MyWindowProc", "ptr", "hwnd;uint;long;ptr")
$wProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle($cInput), $GWL_WNDPROC, DllCallbackGetPtr($wProcNew))
_WinAPI_SetWindowLong(GUICtrlGetHandle($cInput2), $GWL_WNDPROC, DllCallbackGetPtr($wProcNew))
;_WinAPI_SetWindowLong(GUICtrlGetHandle($cInput3), $GWL_WNDPROC, DllCallbackGetPtr($wProcNew)) and so on
$DummyMenu = GUICtrlCreateDummy()
$ContextMenu = GUICtrlCreateContextMenu($DummyMenu)
$CommonMenuItem = GUICtrlCreateMenuItem("Common", $ContextMenu)
$FileMenuItem = GUICtrlCreateMenuItem("File", $ContextMenu)
GUICtrlCreateMenuItem("", $ContextMenu)
$ExitMenuItem = GUICtrlCreateMenuItem("Exit", $ContextMenu)
GUISetState(@SW_SHOW)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
EndFunc ;==>_Main
Func do_clever_stuff_with_clipboard($hWnd)
Local $sData
$sData = ClipGet()
If @error Then Return 0;clip data is not text or clip empty
;do whatever
$sData = StringUpper($sData)
;set text
GUICtrlSetData(_WinAPI_GetDlgCtrlID($hWnd), $sData);or _GUICtrlEdit_SetText($hWnd, $sData)
Return 1
EndFunc ;==>do_clever_stuff_with_clipboard
; Show a menu in a given GUI window which belongs to a given GUI ctrl
Func ShowMenu($hWnd, $nContextID)
Local $iSelected = _GUICtrlMenu_TrackPopupMenu(GUICtrlGetHandle($nContextID), $hWnd, -1, -1, -1, -1, 2)
Switch $iSelected
Case $CommonMenuItem
ConsoleWrite("Common" & @CRLF)
Case $FileMenuItem
ConsoleWrite("File" & @CRLF)
Case $ExitMenuItem
ConsoleWrite("Exit" & @CRLF)
EndSwitch
EndFunc ;==>ShowMenu
Func _MyWindowProc($hWnd, $uiMsg, $wParam, $lParam)
Switch $uiMsg
Case $WM_PASTE
Return do_clever_stuff_with_clipboard($hWnd)
Case $WM_CONTEXTMENU
If $hWnd = GUICtrlGetHandle($cInput) Then
ShowMenu($hGui, $ContextMenu)
Return 0
EndIf
Case $WM_SETCURSOR
GUICtrlSetCursor(_WinAPI_GetDlgCtrlID($hWnd), 5);;set Ibeam cursor
Return 1;;and don't let default windowproc mess things up
EndSwitch
;pass the unhandled messages to default WindowProc
Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $uiMsg, $wParam, $lParam)
EndFunc ;==>_MyWindowProc