Jump to content

Enter a ComboBox control if it has focus


Recommended Posts

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 by supersonic
Link to comment
Share on other sites

  • Moderators

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 down

So the handle you get with GUICtrlGetHandle($hComboBox) is not what _WinAPI_GetFocus sees - it sees the edit control. :oops:

The solution is to use _GUICtrlComboBox_GetComboBoxInfo to get this handle:

#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? :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

kylomas,

be carefull running M23's example, it loops on the consolewrite's

It is not my example - it is supersonic's example in the first post with my added code to show the 3 handles! :D

can the $es_readonly style be applied to the edit component of the combobox

No - but you just need to apply the $CBS_DROPDOWNLIST to the combo when you create it to get the same effect. :oops:

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! :rip:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...