Sign in to follow this  
Followers 0
wolf9228

GUICtrlSetOnEventEx

1 post in this topic

#1 ·  Posted (edited)

GUICtrlSetOnEventEx.zip

Example 1
Button.au3

#Include <GuiButton.au3>
#Include "GUICtrlSetOnEventEx.au3"
; GUICtrlSetOnEventEx($Control_ID_HWnd,$NotificationCode,$Function)
;$NotificationCode ==> (WM_COMMAND Notification Code And WM_NOTIFY Notification Code)
;$Function ==> ($ControlID,$NotificationCode) ; Return :Note use

GUICreate("My GUI Button")
$Button_1 = GUICtrlCreateButton("Clicked Button 1", 10,30,200,30,$BS_NOTIFY)
GUICtrlSetOnEventEx($Button_1,$BN_CLICKED,"ClickedButton_1")
GUICtrlSetOnEventEx($Button_1,$BN_SETFOCUS,"SetFocusButton_1")
GUICtrlSetOnEventEx($Button_1,$BN_KILLFOCUS,"KillFocusButton_1")
GUICtrlSetOnEventEx($Button_1,$BCN_HOTITEMCHANGE,"HotitemChanegButton_1")
$Button_2 = GUICtrlCreateButton("Dblclk Button 2", 10,70,200,30,$BS_NOTIFY)
GUICtrlSetOnEventEx($Button_2,$BN_DBLCLK,"DblclkButton_2")
GUICtrlSetOnEventEx($Button_2,$BN_SETFOCUS,"SetFocusButton_2")
GUICtrlSetOnEventEx($Button_2,$BN_KILLFOCUS,"KillFocusButton_2")
GUICtrlSetOnEventEx($Button_2,$BCN_HOTITEMCHANGE,"HotitemChanegButton_2")

$Button_3 = GUICtrlCreateButton("Button 3", 10,110,200,30)
GUISetState()
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $Button_3
MsgBox(0, 'Testing', 'Button 3 was pressed')
EndSelect
WEnd
Exit


Func ClickedButton_1($ControlID,$NotificationCode)
$WPARAM = OnEventExGetWParam($ControlID,$NotificationCode)
$LPARAM = OnEventExGetLParam($ControlID,$NotificationCode)
$HWND = OnEventExGetHWND($ControlID,$NotificationCode)
MsgBox(0,"MSG","Clicked Button_1")
EndFunc

Func SetFocusButton_1($ControlID,$NotificationCode)
$WPARAM = OnEventExGetWParam($ControlID,$NotificationCode)
$LPARAM = OnEventExGetLParam($ControlID,$NotificationCode)
$HWND = OnEventExGetHWND($ControlID,$NotificationCode)
TrayTip("MSG", "SetFocus Button_1", 5, 1)
EndFunc

Func KillFocusButton_1($ControlID,$NotificationCode)
$WPARAM = OnEventExGetWParam($ControlID,$NotificationCode)
$LPARAM = OnEventExGetLParam($ControlID,$NotificationCode)
$HWND = OnEventExGetHWND($ControlID,$NotificationCode)
TrayTip("MSG", "KillFocus Button_1", 5, 1)
EndFunc

Func HotitemChanegButton_1($ControlID,$NotificationCode)
$WPARAM = OnEventExGetWParam($ControlID,$NotificationCode)
$LPARAM = OnEventExGetLParam($ControlID,$NotificationCode)
$HWND = OnEventExGetHWND($ControlID,$NotificationCode)
TrayTip("MSG", "HotitemChaneg Button_1", 5, 1)
EndFunc

Func DblclkButton_2($ControlID,$NotificationCode)
$WPARAM = OnEventExGetWParam($ControlID,$NotificationCode)
$LPARAM = OnEventExGetLParam($ControlID,$NotificationCode)
$HWND = OnEventExGetHWND($ControlID,$NotificationCode)
MsgBox(0,"MSG","Dblclk Button_2")
EndFunc

Func SetFocusButton_2($ControlID,$NotificationCode)
$WPARAM = OnEventExGetWParam($ControlID,$NotificationCode)
$LPARAM = OnEventExGetLParam($ControlID,$NotificationCode)
$HWND = OnEventExGetHWND($ControlID,$NotificationCode)
TrayTip("MSG", "SetFocus Button_2", 5, 1)
EndFunc

Func KillFocusButton_2($ControlID,$NotificationCode)
$WPARAM = OnEventExGetWParam($ControlID,$NotificationCode)
$LPARAM = OnEventExGetLParam($ControlID,$NotificationCode)
$HWND = OnEventExGetHWND($ControlID,$NotificationCode)
TrayTip("MSG", "KillFocus Button_2", 5, 1)
EndFunc

Func HotitemChanegButton_2($ControlID,$NotificationCode)
$WPARAM = OnEventExGetWParam($ControlID,$NotificationCode)
$LPARAM = OnEventExGetLParam($ControlID,$NotificationCode)
$HWND = OnEventExGetHWND($ControlID,$NotificationCode)
TrayTip("MSG", "HotitemChaneg Button_2", 5, 1)
EndFunc

Examples 2
ComboBox.au3

#include <GUIComboBox.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#Include "GUICtrlSetOnEventEx.au3"
; GUICtrlSetOnEventEx($Control_ID_HWnd,$NotificationCode,$Function)
;$NotificationCode ==> (WM_COMMAND Notification Code And WM_NOTIFY Notification Code)
;$Function ==> ($ControlID,$NotificationCode) ; Return :Note use
$hGUI = GUICreate("(UDF) ComboBox Create", 400, 296)
$ComboBox = _GUICtrlComboBox_Create($hGUI, "", 2, 2, 396, 296)
GUICtrlSetOnEventEx($ComboBox,$CBN_CLOSEUP,"CLOSEUP")
GUICtrlSetOnEventEx($ComboBox,$CBN_DROPDOWN,"DROPDOWN")
GUICtrlSetOnEventEx($ComboBox,$CBN_SELCHANGE,"SELCHANGE")
GUISetState()
_GUICtrlComboBox_BeginUpdate($ComboBox)
_GUICtrlComboBox_AddDir($ComboBox, "", $DDL_DRIVES, False)
_GUICtrlComboBox_EndUpdate($ComboBox)
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()

Func CLOSEUP($ControlID,$NotificationCode)
$WPARAM = OnEventExGetWParam($ControlID,$NotificationCode)
$LPARAM = OnEventExGetLParam($ControlID,$NotificationCode)
$HWND = OnEventExGetHWND($ControlID,$NotificationCode)
MsgBox(0,"MSG","CLOSEUP")
EndFunc

Func DROPDOWN($ControlID,$NotificationCode)
$WPARAM = OnEventExGetWParam($ControlID,$NotificationCode)
$LPARAM = OnEventExGetLParam($ControlID,$NotificationCode)
$HWND = OnEventExGetHWND($ControlID,$NotificationCode)
MsgBox(0,"MSG","DROPDOWN")
EndFunc

Func SELCHANGE($ControlID,$NotificationCode)
$WPARAM = OnEventExGetWParam($ControlID,$NotificationCode)
$LPARAM = OnEventExGetLParam($ControlID,$NotificationCode)
$HWND = OnEventExGetHWND($ControlID,$NotificationCode)
MsgBox(0,"MSG","SELCHANGE")
EndFunc

GUICtrlSetOnEventEx.au3

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $NotifyStruct = 0 , $TagNotifyStruct = ""
; GUICtrlSetOnEventEx($Control_ID_HWnd,$NotificationCode,$Function)
;$NotificationCode ==> (WM_COMMAND Notification Code And WM_NOTIFY Notification Code)
;$Function ==> ($ControlID,$NotificationCode) ; Return :Note use
Func GUICtrlSetOnEventEx($Control_ID_HWnd,$NotificationCode,$Function)
$handle = DLLCallbackRegister($Function,"none","int;int")
if $handle = 0 Then Return False
DllCallbackFree($handle)
if IsHWnd($Control_ID_HWnd) Then
$hWnd = $Control_ID_HWnd
$ControlID = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", $hWnd)
If @error Then Return False
$ControlID = $ControlID[0]
if Not ($ControlID) Then Return False
Else
$ControlID = $Control_ID_HWnd
$hWnd = GUICtrlGetHandle($ControlID)
if Not IsHWnd($hWnd) Then Return False
EndIf
$iNotificationCode = $NotificationCode
if StringInStr($NotificationCode,"-") Then _
$iNotificationCode = StringReplace($NotificationCode,"-","A")
if Not IsDllStruct($NotifyStruct) Then
Local $count = 1
$Len = StringLen($Function)
$TagNotifyStruct = _
"int count;WPARAM WPARAM;LPARAM LPARAM;int Test;int " & String($hWnd & $iNotificationCode) &  _
";HWND HWND" & String($count) &  ";int ControlID" & String($count) & ";int NotificationCode" & _
String($count) & ";char Function" & String($count) & "[" & String($Len) & "]"
$NotifyStruct = DllStructCreate($TagNotifyStruct)
DllStructSetData($NotifyStruct,"count",$count)
DllStructSetData($NotifyStruct,String($hWnd & $iNotificationCode),$count)
DllStructSetData($NotifyStruct,"HWND" & String($count),$hWnd)
DllStructSetData($NotifyStruct,"ControlID" & String($count),$ControlID)
DllStructSetData($NotifyStruct,"NotificationCode" & String($count),$NotificationCode)
DllStructSetData($NotifyStruct,"Function" & String($count),$Function)
Else
$count = DllStructGetData($NotifyStruct,String($hWnd & $iNotificationCode))
if ($count) Then Return False
Local $count = DllStructGetData($NotifyStruct,"count") + 1
$Len = StringLen($Function)
$TagNotifyStruct &= _
";int " & String($hWnd & $iNotificationCode) & ";HWND HWND" & String($count) & _
";int NotificationCode" & String($count) & ";int ControlID" & String($count) & _
";char Function" & String($count) & "[" & String($Len) & "]"
$iLength = DllStructGetSize($NotifyStruct)
$iNotifyStruct = DllStructCreate($TagNotifyStruct)
DllCall("kernel32.dll","none","RtlMoveMemory","ptr",DllStructGetPtr($iNotifyStruct) _
,"ptr",DllStructGetPtr($NotifyStruct),"ulong_ptr",$iLength)
$NotifyStruct = $iNotifyStruct
DllStructSetData($NotifyStruct,"count",$count)
DllStructSetData($NotifyStruct,String($hWnd & $iNotificationCode),$count)
DllStructSetData($NotifyStruct,"HWND" & String($count),$hWnd)
DllStructSetData($NotifyStruct,"ControlID" & String($count),$ControlID)
DllStructSetData($NotifyStruct,"NotificationCode" & String($count),$NotificationCode)
DllStructSetData($NotifyStruct,"Function" & String($count),$Function)
EndIf
GUIRegisterMsg($WM_NOTIFY,"OnEventExProc")
GUIRegisterMsg($WM_COMMAND,"OnEventExProc")
Return True
EndFunc

Func OnEventExProc($hWnd,$Msg,$wParam,$lParam)
Select
Case $Msg = $WM_NOTIFY
Local $OnEventExtagNMHDR = "hwnd hWndFrom;uint_ptr IDFrom;INT Code"
$tNMHDR = DllStructCreate($OnEventExtagNMHDR, $lParam)
$MsgHwnd = DllStructGetData($tNMHDR, "hWndFrom")
$MsgCode = DllStructGetData($tNMHDR, "Code")
Case $Msg = $WM_COMMAND
$MsgHwnd = $lParam
$MsgCode = BitShift($wParam, 16)
EndSelect
$iMsgCode = $MsgCode
if StringInStr($MsgCode,"-") Then _
$iMsgCode = StringReplace($MsgCode,"-","A")
$count = DllStructGetData($NotifyStruct,String($MsgHwnd & $iMsgCode))
if Not ($count) Then Return $GUI_RUNDEFMSG
DllStructSetData($NotifyStruct,"WPARAM",$wParam)
DllStructSetData($NotifyStruct,"LPARAM",$lParam)
$OnEvHWND = DllStructGetData($NotifyStruct,"HWND" & String($count))
$ControlID = DllStructGetData($NotifyStruct,"ControlID" & String($count))
$OnEvNotificationCode = DllStructGetData($NotifyStruct,"NotificationCode" & String($count))
$OnEvFunction = DllStructGetData($NotifyStruct,"Function" & String($count))
DllStructSetData($NotifyStruct,"Test",1)
if ($MsgHwnd = $OnEvHWND And $MsgCode = $OnEvNotificationCode) Then _
Call($OnEvFunction,$ControlID,$OnEvNotificationCode)
DllStructSetData($NotifyStruct,"Test",0)
Return $GUI_RUNDEFMSG
EndFunc

Func OnEventExGetWParam($ControlID,$NotificationCode)
$Test = DllStructGetData($NotifyStruct,"Test")
if Not ($Test) Then Return False
$hWnd = GUICtrlGetHandle($ControlID)
if Not IsHWnd($hWnd) Then Return False
$iNotificationCode = $NotificationCode
if StringInStr($NotificationCode,"-") Then _
$iNotificationCode = StringReplace($NotificationCode,"-","A")
$count = DllStructGetData($NotifyStruct,String($hWnd & $iNotificationCode))
if Not ($count) Then Return False
Return DllStructGetData($NotifyStruct,"WPARAM")
EndFunc

Func OnEventExGetLParam($ControlID,$NotificationCode)
$Test = DllStructGetData($NotifyStruct,"Test")
if Not ($Test) Then Return False
$hWnd = GUICtrlGetHandle($ControlID)
if Not IsHWnd($hWnd) Then Return False
$iNotificationCode = $NotificationCode
if StringInStr($NotificationCode,"-") Then _
$iNotificationCode = StringReplace($NotificationCode,"-","A")
$count = DllStructGetData($NotifyStruct,String($hWnd & $iNotificationCode))
if Not ($count) Then Return False
Return DllStructGetData($NotifyStruct,"LPARAM")
EndFunc

Func OnEventExGetHWND($ControlID,$NotificationCode)
$Test = DllStructGetData($NotifyStruct,"Test")
if Not ($Test) Then Return False
$hWnd = GUICtrlGetHandle($ControlID)
if Not IsHWnd($hWnd) Then Return False
$iNotificationCode = $NotificationCode
if StringInStr($NotificationCode,"-") Then _
$iNotificationCode = StringReplace($NotificationCode,"-","A")
$count = DllStructGetData($NotifyStruct,String($hWnd & $iNotificationCode))
if Not ($count) Then Return False
Return DllStructGetData($NotifyStruct,"HWND" & String($count))
EndFunc
Edited by wolf9228

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0