示例:
#include <WinApi.au3>
#include <Constants.au3>
#Include <GuiEdit.au3>
Global Const $WM_SYSCOMMAND = 0x0112
Global Const $WM_LBUTTONUP = 0x0202
$gui = GUICreate("测试", 700, 600)
$edit = GUICtrlCreateEdit("你好这是一个测试哈哈",50,50,300,100)
GUISetState() ;显示窗口
GUIRegisterMsg($WM_SYSCOMMAND,"WM_SYSCOMMAND")
$wProcOld = GUIRegisterMsgEx($edit, "_MyWindowProc") ;窗口子类化
While 1
Sleep(100)
WEnd
Func WM_SYSCOMMAND($hWnd, $sMsg, $sWParam, $slParam)
Switch $sWParam
Case 61536 ;$SC_CLOSE
Exit
EndSwitch
EndFunc
Func GUIRegisterMsgEx($ctrID, $funcName) ;控件id,函数名
Local $wProcNew = DllCallbackRegister($funcName, "ptr", "hwnd;uint;long;ptr")
Local $wProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle($ctrID), $GWL_WNDPROC, DllCallbackGetPtr($wProcNew))
Return $wProcOld
EndFunc ;==>GUIRegisterMsgEx
Func _MyWindowProc($hWnd, $uiMsg, $wParam, $lParam)
Switch $uiMsg
Case $WM_LBUTTONUP
$sel = _GUICtrlEdit_GetSel($edit)
MsgBox(0,"","你选择了:"&StringMid(GUICtrlRead($edit),$sel[0]+1,$sel[1]-$sel[0]))
EndSwitch
;向默认窗口进程传递未处理过的消息
Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $uiMsg, $wParam, $lParam)
EndFunc ;==>_MyWindowProc
|