jftuga Posted May 19, 2005 Share Posted May 19, 2005 (edited) I searched the forums but did not see an answer for this. I have a combo box, created with GUICtrlCreateCombo(), that has a list of 5 items. If the user selects on an item, my event will fire off as expected. In the main section of the program, I use GUICtrlSetOnEvent() and in the handler use GUICtrlRead(). If the user types something in and hits enter nothing happens. How do I make this action activate the same event handler? FWIW, I am using the beta version, 3.1.1.25. Thanks, -John Edited May 19, 2005 by jftuga Admin_Popup, show computer info or launch shellRemote Manager, facilitates connecting to RDP / VNCProc_Watch, reprioritize cpu intensive processesUDF: _ini_to_dict, transforms ini file entries into variablesUDF: monitor_resolutions, returns resolutions of multiple monitorsReport Computer Problem, for your IT help deskProfile Fixer, fixes a 'missing' AD user profile Link to comment Share on other sites More sharing options...
GaryFrost Posted May 19, 2005 Share Posted May 19, 2005 The only way i've been able to do it is by brute force, set oldstring in the loop, check oldstring against what's in the box, if differ than update oldstring and do what you need to do. SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
jftuga Posted May 19, 2005 Author Share Posted May 19, 2005 (edited) The only way i've been able to do it is by brute force, set oldstring in the loop, check oldstring against what's in the box, if differ than update oldstringand do what you need to do.<{POST_SNAPBACK}>How can you check what's in the box and when enter is pressed? Edited May 19, 2005 by jftuga Admin_Popup, show computer info or launch shellRemote Manager, facilitates connecting to RDP / VNCProc_Watch, reprioritize cpu intensive processesUDF: _ini_to_dict, transforms ini file entries into variablesUDF: monitor_resolutions, returns resolutions of multiple monitorsReport Computer Problem, for your IT help deskProfile Fixer, fixes a 'missing' AD user profile Link to comment Share on other sites More sharing options...
Sosostris Posted July 3, 2006 Share Posted July 3, 2006 How can you check what's in the box and when enter is pressed? You can always interrupt the <Enter> key, check if your box is active, then grab the contents. HotKeySet("{ENTER}", "handleEnter") Func handleEnter() ; Check if the window is active Local $tstate = WinGetState("Window Title here", "") If $tstate = 15 Then Local $tImputTx = GUICtrlRead($searchBox); EndIf ; Now we free the hotkey, send enter again in the original context HotKeySet("{Enter}") ; ... send enter again in the original context Send("{Enter}") ; and reestablish the hotkey binding HotKeySet("{Enter}", "handleEnter") EndIf EndFunc ;==>handleEnter Hope this helps Link to comment Share on other sites More sharing options...
GaryFrost Posted July 3, 2006 Share Posted July 3, 2006 Modified for combobox, can tell with the edit box of the combo has changed, this can be easily modified for GuiOnEvent, no need to worry about when the user presses enter @Sosostris, if your going to revive a thread more than a year old, i would suggest some research on what is now capable in autoit (including latest betas) expandcollapse popup#include <GuiConstants.au3> Global Const $WM_COMMAND = 0x0111 Global Const $CBN_EDITCHANGE = 5; Global Const $CBN_SELCHANGE = 1; Global Const $CBN_EDITUPDATE = 6; Global Const $DebugIt = 1 GUICreate("My GUI combo") ; will create a dialog box that when displayed is centered $combo = GUICtrlCreateCombo ("item1", 10,10) ; create first item GUICtrlSetData(-1,"item2|item3","item3") ; add other item snd set a new default $btn = GUICtrlCreateButton("Ok", 40, 75, 60, 20) GUISetState() GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND") $msg = 0 While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() Select Case $msg = $btn ExitLoop EndSelect WEnd Func _Combo_Changed() ;---------------------------------------------------------------------------------------------- If $DebugIt Then ConsoleWrite (_DebugHeader("Combo Changed:" & GUICtrlRead($combo))) ;---------------------------------------------------------------------------------------------- EndFunc ;==>_File_Changed Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam) Local $nNotifyCode = _HiWord($wParam) Local $nID = _LoWord($wParam) Local $hCtrl = $lParam Switch $nID Case $combo Switch $nNotifyCode Case $CBN_EDITUPDATE, $CBN_EDITCHANGE ; when user types in new data _Combo_Changed() Case $CBN_SELCHANGE ; item from drop down selected _Combo_Changed() EndSwitch 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 ;==>MY_WM_COMMAND Func _DebugHeader($s_text) Return _ "!===========================================================" & @LF & _ "+===========================================================" & @LF & _ "-->" & $s_text & @LF & _ "+===========================================================" & @LF EndFunc ;==>_DebugHeader Func _HiWord($x) Return BitShift($x, 16) EndFunc ;==>_HiWord Func _LoWord($x) Return BitAND($x, 0xFFFF) EndFunc ;==>_LoWord SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
marfdaman Posted July 4, 2006 Share Posted July 4, 2006 But why not just create a button out of the screen, set the style to $BS_DEFPUShBUTTON, and associate the function with that button? Alzo Don't take my pic to serious...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~You Looked, but you did not see!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Link to comment Share on other sites More sharing options...
kbosward Posted July 15, 2006 Share Posted July 15, 2006 (edited) gafrost, I tried your code to detect edit changes in a Combo and it works as expected, except for the following strange case: if the current selection on the Combo is deleted (using the Delete or Backspace key), the CBN_EDITCHANGE notification is received, however GuiCtrlRead still reads the current selection, even though the Combo is now showing blank! For example, with the following script: #include <GUIConstants.au3> Global Const $WM_COMMAND = 0x0111 Global Const $CBN_SELCHANGE = 1 Global Const $CBN_EDITCHANGE = 5 Global $hCombo GuiCreate("Test", 200, 200) $hCombo = GuiCtrlCreateCombo("", 20, 20, 120, 80) GuiCtrlSetData($hCombo, "Item1|Item2|Item3", "Item2") GuiRegisterMsg($WM_COMMAND, "My_WM_COMMAND") GuiSetState() While GuiGetMsg() <> $GUI_EVENT_CLOSE WEnd Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam) Local $nNotifyCode = BitShift($wParam, 16) Local $nControlId = BitAND($wParam, 0xFFFF) If $nControlId = $hCombo Then Switch $nNotifyCode Case $CBN_EDITCHANGE, $CBN_SELCHANGE FileWriteLine("debug.txt", '"' & GuiCtrlRead($hCombo) & '"') EndSwitch EndIf Return $GUI_RUNDEFMSG EndFunc When you run this, "Item1" is shown, if you select "Item2" that it logged, but when you delete the selection (using Backspace or Delete), "Item2" is still logged. It is only after you enter a character and then delete it that an empty string is logged. So how can I check if the current selection has been deleted? Ken. Edited July 15, 2006 by kbosward Link to comment Share on other sites More sharing options...
GaryFrost Posted July 15, 2006 Share Posted July 15, 2006 (edited) expandcollapse popup#include <GuiConstants.au3> Global Const $WM_COMMAND = 0x0111 Global Const $CBN_EDITCHANGE = 5; Global Const $CBN_SELCHANGE = 1; Global Const $CBN_EDITUPDATE = 6; Global Const $DebugIt = 1 Global $changed = 0 GUICreate("My GUI combo") ; will create a dialog box that when displayed is centered $combo = GUICtrlCreateCombo("item1", 10, 10); create first item GUICtrlSetData(-1, "item2|item3", "item3"); add other item snd set a new default $btn = GUICtrlCreateButton("Ok", 40, 75, 60, 20) GUISetState() GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND") $msg = 0 While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() Select Case $msg = $btn ExitLoop Case $changed = 1 ;---------------------------------------------------------------------------------------------- If $DebugIt Then ConsoleWrite(_DebugHeader("Combo Changed:" & GUICtrlRead($combo))) ;---------------------------------------------------------------------------------------------- $changed = 0 EndSelect WEnd Func _Combo_Changed() $changed = 1 EndFunc ;==>_Combo_Changed Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam) Local $nNotifyCode = _HiWord($wParam) Local $nID = _LoWord($wParam) Local $hCtrl = $lParam Switch $nID Case $combo Switch $nNotifyCode Case $CBN_EDITUPDATE, $CBN_EDITCHANGE; when user types in new data _Combo_Changed() Case $CBN_EDITUPDATE; sent when the edit control portion of a combo box is about to display altered text. ; This notification message is sent after the control has formatted the text, ; but before it displays the text. Case $CBN_SELCHANGE; item from drop down selected _Combo_Changed() EndSwitch 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 ;==>MY_WM_COMMAND Func _DebugHeader($s_text) Return _ "!===========================================================" & @LF & _ "+===========================================================" & @LF & _ "-->" & $s_text & @LF & _ "+===========================================================" & @LF EndFunc ;==>_DebugHeader Func _HiWord($x) Return BitShift($x, 16) EndFunc ;==>_HiWord Func _LoWord($x) Return BitAND($x, 0xFFFF) EndFunc ;==>_LoWord Edited July 15, 2006 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 15, 2006 Moderators Share Posted July 15, 2006 Nice Gary... They should make the _HiWord()/_Loword() standards, I get confused which is which sometimes . Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
kbosward Posted July 16, 2006 Share Posted July 16, 2006 Thanks Gary. I don't know why it works, but it works! Ken. Link to comment Share on other sites More sharing options...
GaryFrost Posted July 16, 2006 Share Posted July 16, 2006 Thanks Gary. I don't know why it works, but it works!Ken.The WM_COMMAND is fired on the event, which in turns fires the func, at the point of the function the WM_COMMAND isn't finished, even tho the screen is updated, you can't use GuiCtrlRead at this point.Therefore setting a flag in the function to let WM_COMMAND finish and check for the flag in the While loop. SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
rakudave Posted July 16, 2006 Share Posted July 16, 2006 you might also look at a script i did a while back:http://www.gymmuenchenstein.ch/rakudave/bl...s/quickgold.php Pangaea Ruler new, UDF: _GUICtrlCreateContainer(), Pangaea Desktops, Pangaea Notepad, SuDoku, UDF: Table 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