Thomymaster Posted July 8, 2015 Share Posted July 8, 2015 HiI have a GUI setup (in OnEvent mode) with a combobox with 3 elements. I want to invoke some function only if the user clicked on a different control in the combobox then before.I use the $CBN_SELCHANGE constant in my WM_COMMAND function to check for the selection but i noticed something strange:- when i click on the arrow top open the combobox, the $CBN_SELCHANGE is triggered- when i select a value from the combobox, the $CBN_SELCHANGE is triggered 2 times Here is my code: GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND") Global Const $idcLastDataType = GUICtrlCreateCombo("",110,161,80,21,67,-1) GUICtrlSetData(-1,"Value1|Value2") Func MY_WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) Local $idControl = _LoWord($iwParam) ; LoWord - this gives the ControlID of the control which sent the message Local $nNotifyCode = _HiWord($iwParam) ; HiWord - this gives the submessage that was sent Local $sWinTitle=WinGetTitle($hWnd) ;Local $hCtrl = $ilParam If $GUI_DEBUG Then ConsoleWrite("Window handle: " & $hWnd & " | Window title: " & $sWinTitle & " | Control ID: " & $idControl & @CRLF) EndIf Switch $idControl Case $idcLastDataType If $CBN_SELCHANGE Then _GUI_LastDataUpdate() EndSwitch ; Proceed the default Autoit3 internal message commands. ; You also can complete let the line out. ; !!! But only 'Return' (without any value) will not proceed ; the default Autoit3-message in the future !!! Return $GUI_RUNDEFMSG EndFunc Func _GUI_LastDataUpdate() MsgBox(0,"Test","Test) Return 1 EndFunc Like i said i want the function to only be invoked if the item is a different one then the last time it was selected. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 8, 2015 Moderators Share Posted July 8, 2015 Thomymaster,The only way I can see to do this would be to store the selection and compare when a new one is made:expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Opt("GUIOnEventMode", 1) $sSel = "" $hGUI = GUICreate("Test", 500, 500) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") $cCombo = GUICtrlCreateCombo("", 10, 10, 200, 20) GUICtrlSetData($cCombo, "One|Two|Three|Four|Five") GUICtrlSetOnEvent($cCombo, "_Combo_Event") GUISetState() While 1 Sleep(10) WEnd Func _Combo_Event() $sNewSel = GUICtrlRead($cCombo) If $sNewSel <> $sSel Then $sSel = $sNewSel MsgBox($MB_SYSTEMMODAL, "Selection", $sSel) EndIf EndFunc Func _Exit() Exit EndFuncAnd why are you using Windows messaging to check for a selection? You can do it easily with standard OnEvent coding as I have shown.M23 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...
Thomymaster Posted July 8, 2015 Author Share Posted July 8, 2015 (edited) Hi Thanks for that. I already know that i can use OnEvent coding, but is there a reason not to select for events like button clicks or combox changes using the MY_WM_COMMAND function? Is there an explanation why the combobox throws the $CB_SELCHANGE one time for opening and then 2 times after selecting a value? Edited July 8, 2015 by Thomymaster Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 8, 2015 Moderators Share Posted July 8, 2015 (edited) Thomymaster,is there a reason not to select for events like button clicks or combox changes using the MY_WM_COMMAND function?I would suggest that the answer is given by your question in the last line: Is there an explanation why the combobox throws the $CB_SELCHANGE one time for opening and then 2 times after selecting a value?Why use message handlers and make life difficult for yourself when you can use native functions and make it easy? if you use a high level language then using its functions must be a better way.As to the answer to that question, I have no idea - try looking on MSDN and see if there is an explanation.M23 Edited July 8, 2015 by Melba23 Typo 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...
Thomymaster Posted July 9, 2015 Author Share Posted July 9, 2015 OK, i got your point XinYoung 1 Link to comment Share on other sites More sharing options...
XinYoung Posted March 2, 2017 Share Posted March 2, 2017 Hello. I implemented this but now it's stuck in the _Combo_Event function. How can I get past this so I can make the UI do other things, like close if Cancel is pressed? Link to comment Share on other sites More sharing options...
XinYoung Posted March 2, 2017 Share Posted March 2, 2017 (edited) OK I realized this "Opt("GUIOnEventMode", 1)" is causing the UI to not recognize that other buttons are being pressed. When I comment it out, my different Cases in While 1 are working, but then the _Combo_Event doesn't get triggered. Any ideas??? Edited March 2, 2017 by XinYoung 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