Mat Posted November 17, 2009 Share Posted November 17, 2009 (edited) It's on old trick using WM_COMMAND, but it's now nice and easy to use. Its syntax is very similar to GUICtrlSetOnEvent, however it does have an extra parameter for parameters for the function. example: #Include "GUIonchangeRegister.au3" GUICreate ("test") $EditID = GUICtrlCreateEdit ("", 2, 2, 300, 300) GUICtrlonchangeRegister (-1, "MyFunc", "42|53") GUISetState () While GUIGetMsg () <> -3 Sleep (10) WEnd Func MyFunc ($i, $n) Tooltip ("You sent data!! params: " & $i & ", " & $n) EndFunc ; ==> MyFunc expandcollapse popup#Include-once #Include<Array.au3> Global $INTERNAL_CHANGE_REGISTER[1][3] = [[0, 0, 0]] GUIRegisterMsg (0x0111, "__GUI_CHANGE_REGISTER_WM_COMMAND") ; #FUNCTION# ;==================================================================================================================== ; ; Name...........: GUICtrlonchangeRegister ; Description ...: Registers an edit or input control to trigger a function when edited. ; Syntax.........: GUICtrlonchangeRegister($hEdit, $sFunc [, $sParams] ) ; Parameters ....: $hEdit - The handle to the edit control (can be a control ID) ; $sFunc - The string function, as used in functions like HotKeySet + GUISetOnEvent. ; $sParams - a "|" seperated list of parameters for the function (Optional, default = "") ; Return values .: Success - 1 ; Failure - 0 And Sets @Error to 1 ; Author ........: Mat ; Modified.......: ; Remarks .......: When using the pipe, use "\|" to stop it from being a seperator. ; Related .......: GUICtrlonchangeUnRegister ; Link ..........: ; Example .......: Yes ; ; ;=============================================================================================================================== Func GUICtrlonchangeRegister ($hEdit, $sFunc, $sParams = "") If $hEdit = -1 Then $hEdit = GUICtrlGetHandle (-1) If Not IsHwnd ($hEdit) Then $hEdit = GUICtrlGetHandle ($hEdit) If $hEdit = 0 Then Return SetError (1, 0, 0) ; $hEdit does not exist If $sFunc = "" Then Return GUICtrlonchangeUnRegister ($hEdit) ReDim $INTERNAL_CHANGE_REGISTER[UBound ($INTERNAL_CHANGE_REGISTER) + 1][3] $INTERNAL_CHANGE_REGISTER[0][0] += 1 $INTERNAL_CHANGE_REGISTER[$INTERNAL_CHANGE_REGISTER[0][0]][0] = $hEdit $INTERNAL_CHANGE_REGISTER[$INTERNAL_CHANGE_REGISTER[0][0]][1] = $sFunc $INTERNAL_CHANGE_REGISTER[$INTERNAL_CHANGE_REGISTER[0][0]][2] = $sParams Return 1 Endfunc ; ==> GUICtrlonchangeRegister ; #FUNCTION# ;==================================================================================================================== ; ; Name...........: GUICtrlonchangeUnRegister ; Description ...: UnRegisters an edit or input control so it no longer triggers a function ; Syntax.........: GUICtrlonchangeUnRegister($hEdit) ; Parameters ....: $hEdit - The handle to the edit control (can be a control ID) ; Return values .: Success - 1 ; Failure - 0 And Sets @Error to 1 ; Author ........: Mat ; Modified.......: ; Remarks .......: ; Related .......: GUICtrlonchangeRegister ; Link ..........: ; Example .......: Yes ; ; ;=============================================================================================================================== Func GUICtrlonchangeUnRegister ($hEdit) If $hEdit = -1 Then $hEdit = GUICtrlGetHandle (-1) If Not IsHwnd ($hEdit) Then $hEdit = GUICtrlGetHandle ($hEdit) If $hEdit = 0 Then Return SetError (1, 0, 0) ; $hEdit does not exist Local $i = __GUI_CHANGE_REGISTER_GETINDEX ($hEdit) If $i < 0 Then Return SetError (1, 0, 0) _ArrayDelete ($INTERNAL_CHANGE_REGISTER, $i) $INTERNAL_CHANGE_REGISTER[0][0] -= 1 Return 1 Endfunc ; ==> GUICtrlonchangeUnRegister ; #INTERNAL# ;==================================================================================================================== ; ; Name...........: __GUI_CHANGE_REGISTER_WM_COMMAND ; Description ...: Handles the WM_COMMAND message and triggers events. ; Syntax.........: __GUI_CHANGE_REGISTER_WM_COMMAND ($hWnd, $msgID, $wParam, $lParam) ; Parameters ....: $hEdit - The handle to the edit control (can be a control ID) ; Return values .: "GUI_RUNDEFMSG" ; Author ........: Mat ; Modified.......: ; Remarks .......: ; Related .......: GUICtrlonchangeRegister ; Link ..........: ; Example .......: Yes ; ; ;=============================================================================================================================== Func __GUI_CHANGE_REGISTER_WM_COMMAND ($hWnd, $msgID, $wParam, $lParam) If (BitShift($wParam, 16) <> 768) Then Return "GUI_RUNDEFMSG" Local $i = __GUI_CHANGE_REGISTER_GETINDEX ($lParam) If $i < 0 Then Return "GUI_RUNDEFMSG" If $INTERNAL_CHANGE_REGISTER[$i][1] = "" Then Call ($INTERNAL_CHANGE_REGISTER[$i][1]) Else Local $avParams = StringRegExp ($INTERNAL_CHANGE_REGISTER[$i][2], "(.*?[^\\])?(?:\||$)", 3) For $x = Ubound ($avParams) - 2 to 0 Step -1 $avParams[$x + 1] = $avParams[$x] Next $avParams[0] = "CallArgArray" Call ($INTERNAL_CHANGE_REGISTER[$i][1], $avParams) EndIf Return "GUI_RUNDEFMSG" EndFunc ; ==> __GUI_CHANGE_REGISTER_WM_COMMAND ; #INTERNAL# ;==================================================================================================================== ; ; Name...........: __GUI_CHANGE_REGISTER_GETINDEX ; Description ...: Returns the array index for an Edit HWnd, or -1. ; Syntax.........: __GUI_CHANGE_REGISTER_GETINDEX($hWnd) ; Parameters ....: $hWnd - The handle to the edit control (can NOT be a control ID) ; Return values .: The index or -1 ; Author ........: Mat ; Modified.......: ; Remarks .......: ; Related .......: __GUI_CHANGE_REGISTER_WM_COMMAND ; Link ..........: ; Example .......: Yes ; ; ;=============================================================================================================================== Func __GUI_CHANGE_REGISTER_GETINDEX ($hWnd) For $i = 1 to $INTERNAL_CHANGE_REGISTER[0][0] If $hWnd = $INTERNAL_CHANGE_REGISTER[$i][0] Then Return $i Next Return SetError (1, 0, -1) Endfunc ; ==> __GUI_CHANGE_REGISTER_GETINDEX and for those who don't like copying + pasting: http://m-a-t.googlecode.com/files/GUIonchangeRegister.au3 Mat Edited November 17, 2009 by Mat wyl0205 1 AutoIt Project Listing Link to comment Share on other sites More sharing options...
nikink Posted November 18, 2009 Share Posted November 18, 2009 This looks awesome for my pet project which has two combo boxes, where one is dependent upon the other. I will try this out in the next couple of days as I've been somewhat stumped as to how to link the two. Link to comment Share on other sites More sharing options...
Mat Posted November 18, 2009 Author Share Posted November 18, 2009 This looks awesome for my pet project which has two combo boxes, where one is dependent upon the other. I will try this out in the next couple of days as I've been somewhat stumped as to how to link the two.I haven't tried it with combo boxes so I'm unsure if it will trigger the same message, It might need a bit of tweaking.I have been looking for a way to tell what type of control a handle is pointing to, but without much success. If I can get that sorted then this could become a lot bigger and a lot more useful.Mat AutoIt Project Listing Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 18, 2009 Moderators Share Posted November 18, 2009 Mat,Try _WinAPI_GetClassName to find out the class of a handle.nikink,If you want some interim code for dependent combos while Mat is working on his UDF, please take a look here:expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIComboBox.au3> $sFirst_Combo_Data = "" $sSecond_Combo_List_1 = "|1|2|3|4|5" $sSecond_Combo_List_2 = "|A|B|C|D|E" ; Create GUI Global $hMain_Win = GUICreate("Dependent Combos", 500, 500) ; Create combo lists Global $hFirst_Combo= GUICtrlCreateCombo("", 10, 40, 230, 20, $CBS_DROPDOWNLIST) GUICtrlSetData(-1, "List 1|List 2") Global $hSecond_Combo = GUICtrlCreateCombo("First Select From First Combo", 250, 40, 230, 20, $CBS_DROPDOWNLIST) GUICtrlSetState(-1, $GUI_DISABLE) ; Create labels GUICtrlCreateLabel("First Combo", 10, 10, 80, 20) $hSecond_Label = GUICtrlCreateLabel("Second Combo", 250, 10, 80, 20) GUICtrlSetState(-1, $GUI_DISABLE) GUISetState(@SW_SHOW, $hMain_Win) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch ; Fill Second Combo if UDF folder chosen/changed If GUICtrlRead($hFirst_Combo) <> "" And GUICtrlRead($hFirst_Combo) <> $sFirst_Combo_Data And _GUICtrlComboBox_GetDroppedState($hFirst_Combo) = False Then GUICtrlSetState($hSecond_Combo, $GUI_ENABLE) GUICtrlSetState($hSecond_Label, $GUI_ENABLE) Switch GUICtrlRead($hFirst_Combo) Case "List 1" GUICtrlSetData($hSecond_Combo, $sSecond_Combo_List_1) Case "List 2" GUICtrlSetData($hSecond_Combo, $sSecond_Combo_List_2) EndSwitch $sFirst_Combo_Data = GUICtrlRead($hFirst_Combo) EndIf WEndM23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Mat Posted November 18, 2009 Author Share Posted November 18, 2009 Try _WinAPI_GetClassName to find out the class of a handle.M23What doesn't winapi.au3 have I never even looked. Thanks a lot Melba!Mat AutoIt Project Listing Link to comment Share on other sites More sharing options...
amphoric Posted June 8, 2017 Share Posted June 8, 2017 Does this work with Radio Buttons and Check Boxes? As I cannot get this to work Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now