本帖最后由 pusofalse 于 2012-2-29 03:15 编辑
#include <MsgSpy.au3>
#include <WinAPI.au3>
Const $WM_COMMAND = 0x111
Const $BUTTON_ID = 1
_SPY_InitLibrary()
_SPY_ListenPort($SPY_OBJECT_WINDOW)
Send("#r")
Local $hWnd = WinWait("运行")
Local $hMsgHandler = DllCallBackRegister("_SpyMsgHandler", "none", "ptr;long;ptr;hwnd;long;long;lparam;lresult")
Local $pMsgHandler = DllCallBackGetPtr($hMsgHandler)
Local $aMsgFilter[1] = [$WM_COMMAND]
Local $pMsgFilter = _SPY_CreateMsgFilter($aMsgFilter, $SPY_MSG_OK)
Local $tContext = DllStructCreate("long ButtonID;bool End")
Local $pContext = DllStructGetPtr($tContext)
DllStructSetData($tContext, "ButtonID", $BUTTON_ID)
DllStructSetData($tContext, "End", 0)
Local $pObject = _SPY_CreateObject($hWnd, $pMsgHandler, $pMsgFilter, $pContext)
_SPY_CreateChannel($pObject)
_SPY_SignalObject($pObject)
While DllStructGetData($tContext, "End") = 0 And WinExists($hWnd)
Sleep(100)
WEnd
_SPY_UnsignalObject($pObject)
_SPY_CloseChannel($pObject)
_SPY_CloseObject($pObject)
DllCallBackFree($hMsgHandler)
Func _SpyMsgHandler($pObject, $iObjectType, $pContext, $hWnd, $iMsg, $iwParam, $ilParam, $iResult)
If ($iMsg = $WM_COMMAND) Then
Local $tContext = DllStructCreate("long ButtonID;bool End", $pContext)
If DllStructGetData($tContext, "ButtonID") == $iwParam Then
MsgBox(0, "OK", "You clicked the button.")
DllStructSetData($tContext, "End", 1)
EndIf
EndIf
EndFunc ;==>_SpyMsgHandler
在“运行”对话框里点“确定”,会截取到点击消息。 |