ControlGetChoice

Returns the name of the currently selected entry in a ListBox or ComboBox.

Choice := ControlGetChoice(Control , WinTitle, WinText, ExcludeTitle, ExcludeText)

Parameters

Control

Type: String, Integer or Object

The control's ClassNN, text or HWND, or an object with a Hwnd property. For details, see The Control Parameter.

WinTitle

Type: String, Integer or Object

A window title or other criteria identifying the target window. See WinTitle.

WinText

Type: String

If present, this parameter must be a substring from a single text element of the target window (as revealed by the included Window Spy utility). Hidden text elements are detected if DetectHiddenText is ON.

ExcludeTitle

Type: String

Windows whose titles include this value will not be considered.

ExcludeText

Type: String

Windows whose text include this value will not be considered.

Return Value

Type: String

This function returns the name of the currently selected entry in a ListBox or ComboBox.

Error Handling

An exception is thrown on failure, or if the window or control could not be found.

Remarks

To instead retrieve the position of the selected item, follow this example (use only one of the first two lines):

ChoicePos := SendMessage(0x188, 0, 0, "ListBox1", WinTitle)  ; 0x188 is LB_GETCURSEL (for a ListBox).
ChoicePos := SendMessage(0x147, 0, 0, "ComboBox1", WinTitle)  ; 0x147 is CB_GETCURSEL (for a DropDownList or ComboBox).
ChoicePos += 1  ; Convert from 0-based to 1-based, i.e. so that the first item is known as 1, not 0.
; ChoicePos is now 0 if there is no item selected.

Window titles and text are case sensitive. Hidden windows are not detected unless DetectHiddenWindows has been turned on.

Related

ControlChooseIndex, ControlChooseString, Value property (GuiControl object), Choose method (GuiControl object), Control functions