Header:
; #FUNCTION# ==================================================================================================== ; Name...........: _WinControlSetEvent ; Description ...: Sets an event for Window control. ; Syntax.........: Func(hWindow, nCtrlID, $sCallOnHoldFunc [, $sOnHoldParams [, $sCallOnReleaseFunc [, $sOnReleaseParams]]]) ; ; Parameters ....: $hWindow - Parent window handle (or class name) that have the control to set event for. ; $nCtrlID - CtrlID (or control text) of the control to set the event for. ; $sCallOnHoldFunc - Function name to call when event is fired (control is pressed *down*). ; $sOnHoldParams - [Optional] Extra parameters to pass to the called function ($sCallOnHoldFunc). ; $sCallOnReleaseFunc - [Optional] Function to call when event is fired (control is released after pressing down). ; $sOnReleaseParams - [Optional] Extra parameters to pass to the called function ($sCallOnReleaseFunc). ; ; Return values .: Always return 1. ; ; Author ........: G.Sandler (a.k.a MrCreatoR). ; Modified.......: 22.01.2009, 20:00 ; ; Remarks .......: 1) This UDF includes OnAutoItExit function to release the callback/hooks resources. ; 2) Blocking of $sCallOnHoldFunc/$sCallOnReleaseFunc function by window messages with commands ; such as "Msgbox()" can lead to unexpected behavior, the return to the system should be as fast as possible! ; ; Related .......: _WinCtrlEvents_Handler, _ControlGetHoveredID, _WinGetHoveredHandle, _OnAutoItExit ; Link ..........; ; Example .......; Yes ; ====================================================================================================
Example:
#include <WinControlSetEvent.au3> ;============== Calc Demo ============== ;In this example we use the main loop to avoid blocking of mouse processing from inside CalcGetResult_Proc() function. HotKeySet("^q", "_Quit") $iGetCalcResults = False Run("Calc.exe") For $i = 1 To 9 _WinControlSetEvent("[CLASS:SciCalc]", $i, "", "", "CalcGetResult_Proc", "'" & $i & "' Button has been pressed") Next _WinControlSetEvent("[CLASS:SciCalc]", "=", "", "", "CalcGetResult_Proc", "'=' Button has been pressed") _WinControlSetEvent("[CLASS:SciCalc]", "/", "", "", "CalcGetResult_Proc", "'/' Button has been pressed") _WinControlSetEvent("[CLASS:SciCalc]", "*", "", "", "CalcGetResult_Proc", "'*' Button has been pressed") _WinControlSetEvent("[CLASS:SciCalc]", "-", "", "", "CalcGetResult_Proc", "'-' Button has been pressed") _WinControlSetEvent("[CLASS:SciCalc]", "+", "", "", "CalcGetResult_Proc", "'+' Button has been pressed") _WinControlSetEvent("[CLASS:SciCalc]", "Button28", "", "", "CalcGetResult_Proc", "'X' Button has been pressed") While 1 Sleep(10) If $iGetCalcResults <> False Then $iParam = $iGetCalcResults $iGetCalcResults = False If $iParam = 168 Then Exit ;Calc closed $sCtrl_Data = ControlGetText("[CLASS:SciCalc]", "", $iParam) If $sCtrl_Data = "=" Then Local $sResult = StringStripWS(ControlGetText("[CLASS:SciCalc]", "", "Edit1"), 3) If StringRight($sResult, 1) = "," Then $sResult = StringTrimRight($sResult, 1) ToolTip("The result has been calculated: " & $sResult, Default, Default, "Calc Info", 1, 5) ElseIf $sCtrl_Data <> "" Then ToolTip("Calc Button Pressed: " & $sCtrl_Data, Default, Default, "Calc Info", 1, 5) EndIf EndIf WEnd ;Warning: blocking of this function by window messages with commands such as "Msgbox()" can lead to unexpected behavior, ;the return to the system should be as fast as possible !!! Func CalcGetResult_Proc($sParams, $hWnd, $nCtrlID) ConsoleWrite("Passed params: " & $sParams & @CRLF) $iGetCalcResults = $nCtrlID EndFunc Func _Quit() Exit EndFunc
WinControlSetEvent.zip 2.78K
391 downloads
Edited by MrCreatoR, 01 June 2009 - 05:27 PM.








