supersonic Posted December 7, 2011 Posted December 7, 2011 (edited) Hi everybody, I'm trying to solve an apparently simple issue but I don't get it solved... So, if the ComboBox control has focus and I press ENTER some action should start... With the sample code below it does not work. For the Input control it works fine. Here's the sample code: #include <GUIConstantsEx.au3> #include <Misc.au3> #include <WinAPI.au3> Local $hDLL = DllOpen("USER32.DLL") Local $hGUI = GUICreate("", 200, 100, -1, -1) Local $hButton = GUICtrlCreateButton("Button", 10, 10, 100, 21) Local $hComboBox = GUICtrlCreateCombo("ComboBox", 10, 40, 100, 21) Local $hInput = GUICtrlCreateInput("Input", 10, 62, 100, 21) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $hButton MsgBox(0, "", "Button") EndSwitch ConsoleWrite("___" & _WinAPI_GetFocus() & "___" & GUICtrlGetHandle($hComboBox) & @CRLF) If _IsPressed("0D", $hDll) = True And _WinAPI_GetFocus() = GUICtrlGetHandle($hComboBox) Then ; 0D = ENTER. MsgBox(0, "", "ComboBox") EndIf ConsoleWrite("___" & _WinAPI_GetFocus() & "___" & GUICtrlGetHandle($hInput) & @CRLF) If _IsPressed("0D", $hDll) = True And _WinAPI_GetFocus() = GUICtrlGetHandle($hInput) Then ; 0D = ENTER. MsgBox(0, "", "Input") EndIf WEnd DllClose($hDLL) The function "_WinAPI_GetFocus()" returns an other handle for the ComboBox control as "GUICtrlGetHandle()". Anyone any idea? Greets, -supersonic. Edited December 7, 2011 by supersonic
JohnOne Posted December 7, 2011 Posted December 7, 2011 I'm not sure if this will work, as I'm not entirely sure it does not just give initial focus to the control, but try this after create your comboGUICtrlSetState(-1, $GUI_DEFBUTTON) AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Moderators Melba23 Posted December 7, 2011 Moderators Posted December 7, 2011 supersonic,The combobox actually consists of 3 parts:- 1. The combo you create- 2. The edit box at the top- 3. The list that drops downSo the handle you get with GUICtrlGetHandle($hComboBox) is not what _WinAPI_GetFocus sees - it sees the edit control. The solution is to use _GUICtrlComboBox_GetComboBoxInfo to get this handle:expandcollapse popup#include <GUIConstantsEx.au3> #include <Misc.au3> #include <WinAPI.au3> #include <GUIComboBox.au3> #include <Constants.au3> $tInfo = $tagCOMBOBOXINFO Local $hDLL = DllOpen("USER32.DLL") Local $hGUI = GUICreate("", 200, 100, -1, -1) Local $hButton = GUICtrlCreateButton("Button", 10, 10, 100, 21) Local $hComboBox = GUICtrlCreateCombo("ComboBox", 10, 40, 100, 21) If _GUICtrlComboBox_GetComboBoxInfo($hComboBox, $tInfo) Then ConsoleWrite("Handle to the ComboBox .....: " & DllStructGetData($tInfo, "hCombo") & @CRLF) ConsoleWrite("Handle to the Edit Box .....: " & DllStructGetData($tInfo, "hEdit") & @CRLF) ConsoleWrite("Handle to the drop-down list: " & DllStructGetData($tInfo, "hList") & @CRLF) EndIf $hEditBox = DllStructGetData($tInfo, "hEdit") Local $hInput = GUICtrlCreateInput("Input", 10, 62, 100, 21) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $hButton MsgBox(0, "", "Button") EndSwitch ConsoleWrite("___" & _WinAPI_GetFocus() & "___" & $hEditBox & @CRLF) If _IsPressed("0D", $hDLL) = True And _WinAPI_GetFocus() = $hEditBox Then ; 0D = ENTER. MsgBox(0, "", "ComboBox") EndIf ConsoleWrite("___" & _WinAPI_GetFocus() & "___" & GUICtrlGetHandle($hInput) & @CRLF) If _IsPressed("0D", $hDLL) = True And _WinAPI_GetFocus() = GUICtrlGetHandle($hInput) Then ; 0D = ENTER. MsgBox(0, "", "Input") EndIf WEnd DllClose($hDLL)All clear? 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
kylomas Posted December 7, 2011 Posted December 7, 2011 supersonic, be carefull running M23's example, it loops on the consolewrite's @M23 - can the $es_readonly style be applied to the edit component of the combobox??? kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
Moderators Melba23 Posted December 7, 2011 Moderators Posted December 7, 2011 kylomas,be carefull running M23's example, it loops on the consolewrite'sIt is not my example - it is supersonic's example in the first post with my added code to show the 3 handles! can the $es_readonly style be applied to the edit component of the comboboxNo - but you just need to apply the $CBS_DROPDOWNLIST to the combo when you create it to get the same effect. I know the description in the Help file is not wonderful:"$CBS_DROPDOWNLIST - 0x0003 - Displays a static text field that displays the current selection in the list box"but that is what MSDN gives us to work with! 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
kylomas Posted December 7, 2011 Posted December 7, 2011 M23, Thanks, apologies for the mis-attribution (cool word I just made up)... kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
supersonic Posted December 7, 2011 Author Posted December 7, 2011 Hi Melba, everything clear - thank you very much for this excellent explanation! @ kylomas: I'm aware of the "ConsoleWrite()" loop. The sample code above was just for testing purposes... Greets, -supersonic.
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