AndyS01 Posted April 21, 2014 Posted April 21, 2014 I created a ComboBox control and saved it's ID and window handle, but when I put in code to trap ENTER keys for that control, I get ID 1001 in the interrupt handler instead of the correct (4) ID. I found that even if I stripped down my test to remove the handlers, and I run the AU2Recorder, it shows an ID = 1001 when I hover over my ComboBox control. here is my test code: expandcollapse popup#NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <WinAPI.au3> #include <GUIConstantsEx.au3> #include <StructureConstants.au3> OnAutoItExitRegister("ExitStageLeft") Opt("GUICloseOnESC", 1) Opt("GUIEventOptions", 1) Opt("GUIOnEventMode", 1) ;; <===== Opt("WinTitleMatchMode", 1) Opt('MustDeclareVars', 1) Global $hWnd_ComboBox1, $hWnd_input1, $hGUI, $sWinTitle Global $iID_ComboBox1, $iID_Input1, $iID_Enter Global $aAccelKeys[1][2] _Main() Exit (1) Func _Main() $sWinTitle = "ENTER key trap test" $hGUI = GUICreate($sWinTitle, 500, 230) GUICtrlCreateButton("Test", 5, 5, 50, 25) $iID_Input1 = GUICtrlCreateInput("input1", 70, 5, 100, 25) $hWnd_input1 = GUICtrlGetHandle($iID_Input1) $iID_ComboBox1 = GUICtrlCreateCombo("ComboBox1", 10, 40, 475, 190) $hWnd_ComboBox1 = GUICtrlGetHandle($iID_ComboBox1) GUICtrlSetData($iID_ComboBox1, "abcdefghijklmnopqrstuvwxyz" & @CRLF, 1) ConsoleWrite("+++: $hGUI = " & $hGUI & @CRLF) ConsoleWrite("+++: $iID_Input1 = " & $iID_ComboBox1 & @CRLF) ConsoleWrite("+++: $hWnd_input1 = " & $hWnd_input1 & @CRLF) ConsoleWrite("+++: $iID_ComboBox1 = " & $iID_Input1 & @CRLF) ConsoleWrite("+++: $hWnd_list = " & $iID_Input1 & @CRLF) GUISetState() GUISetOnEvent($GUI_EVENT_CLOSE, 'ExitStageLeft') $iID_Enter = GUICtrlCreateDummy() GUICtrlSetOnEvent($iID_Enter, "handle_ENTERKey") $aAccelKeys[0][0] = "{ENTER}" $aAccelKeys[0][1] = $iID_Enter GUISetAccelerators($aAccelKeys) While (1) Sleep(250) WEnd EndFunc ;==>_Main Func ExitStageLeft() Exit (0) EndFunc ;==>ExitStageLeft Func handle_ENTERKey() ConsoleWrite("+++: handle_ENTERKey() entered" & @CRLF) Local $handled = False Local $id = ControlGetFocus($hGUI); Local $hCtrl = ControlGetHandle($hGUI, "", $id) Local $iCtrl = _WinAPI_GetDlgCtrlID($hCtrl) ConsoleWrite("+++: $id = " & $id & @CRLF) ConsoleWrite("+++: $hCtrl = " & $hCtrl & @CRLF) ConsoleWrite("+++: $iCtrl = " & $iCtrl & @CRLF) Switch $iCtrl Case $iID_ComboBox1 ConsoleWrite("+++: do something for the ComboBox" & @CRLF) ; <do something ...> $handled = True Case $iID_Input1 ConsoleWrite("+++: do something for the InputBox" & @CRLF) ; <do something ...> $handled = True EndSwitch If (Not $handled) Then GUISetAccelerators(0) ConsoleWrite("+++: passing {ENTER} to control ID " & $iCtrl & @CRLF) Send("{ENTER}") GUISetAccelerators($aAccelKeys) ; EndIf EndFunc ;==>handle_ENTERKey Here is the console output when I ran my test and clicked on the Input control, pressed the Enter key, then clicked on the ComboBox control and pressed the Enter key: +++: $hGUI = 0x00170D38 +++: $iID_Input1 = 5 +++: $hWnd_input1 = 0x00240AC0 +++: $iID_ComboBox1 = 4 +++: $hWnd_list = 4 +++: handle_ENTERKey() entered +++: $id = Edit1 +++: $hCtrl = 0x00240AC0 +++: $iCtrl = 4 +++: do something for the InputBox +++: handle_ENTERKey() entered +++: $id = Edit2 +++: $hCtrl = 0x00530AB2 +++: $iCtrl = 1001 +++: passing {ENTER} to control ID 1001 What's going on with the ComboBox control? I also noticed that at the start of my test, when I got the handle of the ComboBox control, the GUICtrlGetHandle() function returned its ID (4).
BrewManNH Posted April 21, 2014 Posted April 21, 2014 Well, for one thing you are using the variables in the wrong places. ConsoleWrite("+++: $iID_Input1 = " & $iID_ComboBox1 & @CRLF) ConsoleWrite("+++: $iID_ComboBox1 = " & $iID_Input1 & @CRLF) $iID_Input1 is displaying the control ID for the combobox in this spot and vice versa. You're also displaying a line $hWnd_list, but using the input box control ID and there's no variable used called $hWnd_list. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
AndyS01 Posted April 21, 2014 Author Posted April 21, 2014 Sorry, it should look like this: ConsoleWrite("+++: $hGUI = " & $hGUI & @CRLF) ConsoleWrite("+++: $iID_Input1 = " & $iID_input1 & @CRLF) ConsoleWrite("+++: $hWnd_Input1 = " & $hWnd_Input1 & @CRLF) ConsoleWrite("+++: $iID_ComboBox1 = " & $iID_ComboBox1 & @CRLF) ConsoleWrite("+++: $hWnd_ComboBox1 = " & $hWnd_ComboBox1 & @CRLF) So the full test script now looks like this: expandcollapse popup#NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <WinAPI.au3> #include <GUIConstantsEx.au3> #include <StructureConstants.au3> OnAutoItExitRegister("ExitStageLeft") Opt("GUICloseOnESC", 1) Opt("GUIEventOptions", 1) Opt("GUIOnEventMode", 1) ;; <===== Opt("WinTitleMatchMode", 1) Opt('MustDeclareVars', 1) Global $hWnd_ComboBox1, $hWnd_Input1, $hGUI, $sWinTitle Global $iID_ComboBox1, $iID_Input1, $iID_Enter Global $aAccelKeys[1][2] _Main() Exit (1) Func _Main() $sWinTitle = "ENTER key trap test" $hGUI = GUICreate($sWinTitle, 500, 230) GUICtrlCreateButton("Test", 5, 5, 50, 25) $iID_Input1 = GUICtrlCreateInput("Input1", 70, 5, 100, 25) $hWnd_Input1 = GUICtrlGetHandle($iID_Input1) $iID_ComboBox1 = GUICtrlCreateCombo("ComboBox1", 10, 40, 475, 190) $hWnd_ComboBox1 = GUICtrlGetHandle($iID_ComboBox1) GUICtrlSetData($iID_ComboBox1, "abcdefghijklmnopqrstuvwxyz" & @CRLF, 1) ConsoleWrite("+++: $hGUI = " & $hGUI & @CRLF) ConsoleWrite("+++: $iID_Input1 = " & $iID_Input1 & @CRLF) ConsoleWrite("+++: $hWnd_Input1 = " & $hWnd_Input1 & @CRLF) ConsoleWrite("+++: $iID_ComboBox1 = " & $iID_ComboBox1 & @CRLF) ConsoleWrite("+++: $hWnd_ComboBox1 = " & $hWnd_ComboBox1 & @CRLF) GUISetState() GUISetOnEvent($GUI_EVENT_CLOSE, 'ExitStageLeft') $iID_Enter = GUICtrlCreateDummy() GUICtrlSetOnEvent($iID_Enter, "handle_ENTERKey") $aAccelKeys[0][0] = "{ENTER}" $aAccelKeys[0][1] = $iID_Enter GUISetAccelerators($aAccelKeys) While (1) Sleep(250) WEnd EndFunc ;==>_Main Func ExitStageLeft() Exit (0) EndFunc ;==>ExitStageLeft Func handle_ENTERKey() ConsoleWrite("+++: handle_ENTERKey() entered" & @CRLF) Local $handled = False Local $id = ControlGetFocus($hGUI); Local $hCtrl = ControlGetHandle($hGUI, "", $id) Local $iCtrl = _WinAPI_GetDlgCtrlID($hCtrl) ConsoleWrite("+++: $id = " & $id & @CRLF) ConsoleWrite("+++: $hCtrl = " & $hCtrl & @CRLF) ConsoleWrite("+++: $iCtrl = " & $iCtrl & @CRLF) Switch $iCtrl Case $iID_ComboBox1 ConsoleWrite("+++: do something for the ComboBox" & @CRLF) ; <do something ...> $handled = True Case $iID_Input1 ConsoleWrite("+++: do something for the InputBox" & @CRLF) ; <do something ...> $handled = True EndSwitch If (Not $handled) Then GUISetAccelerators(0) ConsoleWrite("+++: sending {ENTER} to control ID " & $iCtrl & @CRLF) Send("{ENTER}") GUISetAccelerators($aAccelKeys) ; EndIf EndFunc ;==>handle_ENTERKey However, I still see the 1001 ID.
BrewManNH Posted April 22, 2014 Posted April 22, 2014 That is the control ID for the edit control in the combobox. If you disable the edit control using the $CBS_DROPDOWNLIST style setting, and then hit enter, you get the control ID of the combobox as expected. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
AndyS01 Posted May 1, 2014 Author Posted May 1, 2014 When I use $CBS_DROPDOWNLIST, I don't get an edit box, just a combo with things listed in it. I want to be able to type something in, then hit ENTER which should be trapped so I can act on the entered data, So, you say 1001 is the ID of the edit control, which is just what I want. The only trouble is, that when I create the combobox, I get the ID of the commbobox,(4). Is there an API I can call to get the ID of the edit control (in this case, 1001)?
BrewManNH Posted May 1, 2014 Posted May 1, 2014 What's wrong with doing it the same way you do it in your handle_ENTERKey function? Just set the focus to the ComboBox first, then get the control ID of the edit control in it. expandcollapse popup#NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <WinAPI.au3> #include <GUIConstantsEx.au3> #include <StructureConstants.au3> OnAutoItExitRegister("ExitStageLeft") Opt("GUICloseOnESC", 1) Opt("GUIEventOptions", 1) Opt("GUIOnEventMode", 1) ;; <===== Opt("WinTitleMatchMode", 1) Opt('MustDeclareVars', 1) Global $hWnd_ComboBox1, $hWnd_Input1, $hGUI, $sWinTitle Global $iID_ComboBox1, $iID_Input1, $iID_Enter Global $aAccelKeys[1][2] _Main() Exit (1) Func _Main() $sWinTitle = "ENTER key trap test" $hGUI = GUICreate($sWinTitle, 500, 230) GUICtrlCreateButton("Test", 5, 5, 50, 25) $iID_Input1 = GUICtrlCreateInput("Input1", 70, 5, 100, 25) $hWnd_Input1 = GUICtrlGetHandle($iID_Input1) $iID_ComboBox1 = GUICtrlCreateCombo("ComboBox1", 10, 40, 475, 190) $hWnd_ComboBox1 = GUICtrlGetHandle($iID_ComboBox1) ; set the combo to be the focused control ControlFocus($hGUI, "", $hWnd_ComboBox1) ; get the control ID of the control that has focus Local $id = ControlGetFocus($hGUI); Local $hCtrl = ControlGetHandle($hGUI, "", $id) Local $iCtrl = _WinAPI_GetDlgCtrlID($hCtrl) GUICtrlSetData($iID_ComboBox1, "abcdefghijklmnopqrstuvwxyz" & @CRLF, 1) ConsoleWrite("!++: $hGUI = " & $hGUI & @CRLF) ConsoleWrite("!++: $iID_Input1 = " & $iID_Input1 & @CRLF) ConsoleWrite("!++: $hWnd_Input1 = " & $hWnd_Input1 & @CRLF) ConsoleWrite("!++: $iID_ComboBox1 = " & $iID_ComboBox1 & @CRLF) ConsoleWrite("!++: $hWnd_ComboBox1 = " & $hWnd_ComboBox1 & @CRLF) ConsoleWrite("!++: $iCtrl = " & $iCtrl & @CRLF) GUISetState() GUISetOnEvent($GUI_EVENT_CLOSE, 'ExitStageLeft') $iID_Enter = GUICtrlCreateDummy() GUICtrlSetOnEvent($iID_Enter, "handle_ENTERKey") $aAccelKeys[0][0] = "{ENTER}" $aAccelKeys[0][1] = $iID_Enter GUISetAccelerators($aAccelKeys) While (1) Sleep(250) WEnd EndFunc ;==>_Main Func ExitStageLeft() Exit (0) EndFunc ;==>ExitStageLeft Func handle_ENTERKey() ConsoleWrite("+++: handle_ENTERKey() entered" & @CRLF) Local $handled = False Local $id = ControlGetFocus($hGUI); Local $hCtrl = ControlGetHandle($hGUI, "", $id) Local $iCtrl = _WinAPI_GetDlgCtrlID($hCtrl) ConsoleWrite("+++: $id = " & $id & @CRLF) ConsoleWrite("+++: $hCtrl = " & $hCtrl & @CRLF) ConsoleWrite("+++: $iCtrl = " & $iCtrl & @CRLF) Switch $iCtrl Case $iID_ComboBox1 ConsoleWrite("+++: do something for the ComboBox" & @CRLF) ; <do something ...> $handled = True Case $iID_Input1 ConsoleWrite("+++: do something for the InputBox" & @CRLF) ; <do something ...> $handled = True EndSwitch If (Not $handled) Then GUISetAccelerators(0) ConsoleWrite("+++: sending {ENTER} to control ID " & $iCtrl & @CRLF) Send("{ENTER}") GUISetAccelerators($aAccelKeys) ; EndIf EndFunc ;==>handle_ENTERKey If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
Solution AndyS01 Posted May 2, 2014 Author Solution Posted May 2, 2014 That did it, thanks. Here's my working code: expandcollapse popup#NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <WinAPI.au3> #include <GUIConstantsEx.au3> OnAutoItExitRegister("ExitStageLeft") Opt("GUICloseOnESC", 1) Opt("GUIEventOptions", 1) Opt("GUIOnEventMode", 1) ;; <===== Opt("WinTitleMatchMode", 1) Opt('MustDeclareVars', 1) Global $sWinTitle, $hGUI, $iID_Enter Global $iID_Test_btn, $hWnd_Test_btn, $iID_Input1, $hWnd_Input1 Global $iID_ComboBox1, $hWnd_ComboBox1 Global $hWnd_ComboBoxEdit1Ctrl, $iID_ComboBoxEdit1Ctrl Global $aAccelKeys[1][2] _Main() Exit (1) Func _Main() Local $id $sWinTitle = "ENTER key trap test" $hGUI = GUICreate($sWinTitle, 500, 230) $iID_Test_btn = GUICtrlCreateButton("Test", 5, 5, 50, 25) $hWnd_Test_btn = GUICtrlGetHandle($iID_Test_btn) $iID_Input1 = GUICtrlCreateInput("input1-data", 70, 5, 100, 25) $hWnd_Input1 = GUICtrlGetHandle($iID_Input1) $iID_ComboBox1 = GUICtrlCreateCombo("ComboBox1xxx", 10, 40, 475, 190) $hWnd_ComboBox1 = GUICtrlGetHandle($iID_ComboBox1) ControlFocus($hGUI, "", $hWnd_ComboBox1) $id = ControlGetFocus($hGUI) $hWnd_ComboBoxEdit1Ctrl = ControlGetHandle($hGUI, "", $id) ; handle of the ComboBox Edit control $iID_ComboBoxEdit1Ctrl = _WinAPI_GetDlgCtrlID($hWnd_ComboBoxEdit1Ctrl) ; ID of the ComboBox Edit control GUICtrlSetData($iID_ComboBox1, "abcdefghijklmnopqrstuvwxyz" & @CRLF, 1) ConsoleWrite("+++: $hGUI = " & $hGUI & @CRLF) ConsoleWrite("+++: $iID_Test_btn = " & $iID_Test_btn & @CRLF) ConsoleWrite("+++: $hWnd_Test_btn = " & $hWnd_Test_btn & @CRLF) ConsoleWrite("+++: $iID_Input1 = " & $iID_ComboBox1 & @CRLF) ConsoleWrite("+++: $hWnd_Input1 = " & $hWnd_Input1 & @CRLF) ConsoleWrite("+++: $iID_ComboBox1 = " & $iID_Input1 & @CRLF) ConsoleWrite("+++: $hWnd_ComboBox1 = " & $iID_Input1 & @CRLF) ConsoleWrite("+++: $hWnd_ComboBoxEdit1Ctrl = " & $hWnd_ComboBoxEdit1Ctrl & @CRLF) ConsoleWrite("+++: $iID_ComboBoxEdit1Ctrl = " & $iID_ComboBoxEdit1Ctrl & @CRLF) GUISetState() GUISetOnEvent($GUI_EVENT_CLOSE, 'ExitStageLeft') $iID_Enter = GUICtrlCreateDummy() GUICtrlSetOnEvent($iID_Enter, "handle_ENTERKey") $aAccelKeys[0][0] = "{ENTER}" $aAccelKeys[0][1] = $iID_Enter GUISetAccelerators($aAccelKeys) While (1) Sleep(250) WEnd EndFunc ;==>_Main Func ExitStageLeft() Exit (0) EndFunc ;==>ExitStageLeft Func handle_ENTERKey() Local $handled = False Local $id = ControlGetFocus($hGUI); "Button1" or "Edit1" or "ComboBox1" Local $hCtrl = ControlGetHandle($hGUI, "", $id) Local $iCtrl = _WinAPI_GetDlgCtrlID($hCtrl) ConsoleWrite("+++: handle_ENTERKey() entered: $id = '" & $id & "', $hCtrl = " & $hCtrl & ", $iCtrl = " & $iCtrl & @CRLF) Switch $iCtrl Case $iID_ComboBoxEdit1Ctrl ConsoleWrite("+++: do something for the ComboBoxEditCtrl" & @CRLF) ; <do something ...> $handled = True Case $iID_Input1 ConsoleWrite("+++: do something for the InputBox" & @CRLF) ; <do something ...> $handled = True EndSwitch If (Not $handled) Then GUISetAccelerators(0) ConsoleWrite("+++: passing {ENTER} to control ID " & $iCtrl & @CRLF) Send("{ENTER}") GUISetAccelerators($aAccelKeys) ; EndIf EndFunc ;==>handle_ENTERKey
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