Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

GuiControlGet, OutputVar, Focus & ComboBox issue

  • Please log in to reply
1 reply to this topic
just me
  • Members
  • 1496 posts
  • Last active: Nov 03 2015 04:32 PM
  • Joined: 28 May 2011

Using this command for the first time to check for a ComboBox I get a confusing result; the class part of ClassNN contains "Edit". I know that a ComboBox contains an Edit as a child control, but I always thought that GuiControlGet other than ControlGet will retrieve informations about a GuiControl, i.e. a ComboBox in this case. Also, the returned ClassNN won't be accepted as valid for subsequent GuiControlGet or GuiControl commands. Does this make any sense?

SetBatchLines, -1
Gui, Margin, 20, 20
Gui, Add, ComboBox, w500 r5 vCBBVar hwndHCBB Choose1, ComboBox|2|3|4|5
Gui, Add, Edit, w500 vEditVar hwndHEDit, Edit
Gui, Add, ListView, w500 r6 Grid, Command|OutputVar|ErrorLevel
LV_ModifyCol(1, 300)
LV_ModifyCol(2, 100)
LV_ModifyCol(3, "AutoHdr")
Gui, Show, , ComboBox
GuiControlGet, ClassNN, Focus
LV_Add("", "GuiControlGet, ClassNN, Focus", ClassNN ? ClassNN : "!!! Empty !!!", ErrorLevel)
GuiControlGet, CtrlVar, FocusV
LV_Add("", "GuiControlGet, CtrlVar, FocusV", CtrlVar ? CtrlVar : "!!! Empty !!!", ErrorLevel)
GuiControlGet, HCTRL, HWND, %ClassNN%
LV_Add("", "GuiControlGet, HCTRL, HWND, %ClassNN%", HCTRL ? HCTRL : "!!! Empty !!!", ErrorLevel)
GuiControlGet, HCTRL, HWND, %CtrlVar%
LV_Add("", "GuiControlGet, HCTRL, HWND, %CtrlVar%", HCTRL ? HCTRL : "!!! Empty !!!", ErrorLevel)
GuiControlGet, VarName, Name, %ClassNN%
LV_Add("", "GuiControlGet, VarName, Name, %ClassNN%", VarName ? VarName : "!!! Empty !!!", ErrorLevel)
GuiControl, , %ClassNN%, Hello world!
LV_Add("", "GuiControl, , %ClassNN%, Hello world!", "N/A", ErrorLevel)

Sorry, if this has been already asked and answered!

Prefer ahkscript.org for the time being.

  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
✓  Best Answer

The ClassNN will work with any of the Control commands. GuiControlGet Focus can be used when the script needs to know the actual control that has focus, or if it needs to interact directly with the Edit control rather than its parent ComboBox.


The inability to specify the ClassNN of the Edit control to refer to the ComboBox could be considered a bug, since passing the HWND of the Edit control works the same as passing the HWND of the ComboBox which contains it.  This will be fixed - so in the example below, Edit1 will contain "Set by ClassNN".

Gui, Add, ComboBox, w150
Gui, Add, Edit, w150
Gui, Show,, Test
Gui +LastFound
ControlGet, hEdit, Hwnd,, Edit1
GuiControl, Text, %hEdit%, Set by HWND   ; Works
GuiControl, Text, Edit1, Set by ClassNN  ; Fails
GuiControl, Text, Edit2, Set by ClassNN

Note that I used the Text sub-command.  The blank sub-command would append list items, since it's operating on the ComboBox Gui control, not (directly) the Edit.