Sign in to follow this  
Followers 0
cag8f

Basic controlcommand problems

10 posts in this topic

I'm slowly learning the control functions in Autoit. I can get this line to work succesfully:

ControlCommand("WINDOW1", "", "WindowsForms10.COMBOBOX.app.X.XXXXXXXX" , "ShowDropDown", "")

The combo box in question drops down and reveals its options. However when I try the same line, only with the GetCurrentSelection command inserted:

ControlCommand("WINDOW1", "", "WindowsForms10.COMBOBOX.app.X.XXXXXXXX" , "GetCurrentSelection", "")

nothing is returned. The combo box definitely has a current selection displayed (i.e. the selection is not blank). What am I doing wrong? Thanks in advance.

Share this post


Link to post
Share on other sites



Try with SetCurrentSelection instead of GetCurrentSelection.


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

This may be a non-standard Windows control. But if so, why does controlcommand work with the "ShowDropDown" command? Or will non-standard controls behave that way: work fine for some commands but not for others?

And SetCurrentSelection is my ultimate goal for this control. However that does not work either. As a diagnostic, I was trying to figure out why a simple control command (GetCurrentSelection) was not working, then move on to SetCurrentSelection.

Edited by cag8f

Share this post


Link to post
Share on other sites

Bumping in case the 9-5 crew can help...

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I'm slowly learning the control functions in Autoit. I can get this line to work succesfully:

ControlCommand("WINDOW1", "", "WindowsForms10.COMBOBOX.app.X.XXXXXXXX" , "ShowDropDown", "")

The combo box in question drops down and reveals its options. However when I try the same line, only with the GetCurrentSelection command inserted:

ControlCommand("WINDOW1", "", "WindowsForms10.COMBOBOX.app.X.XXXXXXXX" , "GetCurrentSelection", "")

nothing is returned. The combo box definitely has a current selection displayed (i.e. the selection is not blank). What am I doing wrong? Thanks in advance.

you need to use combobox and listbox UDFs

example tested with WindowsForms controls

EDIT: typo

#Include <GuiComboBox.au3>
;#Include <GuiComboBoxEx.au3>
#Include <GuiListBox.au3>
#include <WinAPI.au3>
#include <Array.au3>
#include <WindowsConstants.au3>

Opt("MustDeclareVars", 1)

Local $hWin, $sText, $tInfo, $hCombo, $hList
Local $iIndex = 2 ; zero based combobox item to change
Local $sReplacetext = "TEXT"; combobox replacement text
Local $iInstance = 1 ;your combobox instance from AutoIt v3 Window Info tool
Local $sMain = "[TITLE:WINDOW1]" ;app title
Local $sMainTitle = "WINDOW1";app title
;Local $sClassCombo = "[CLASS:WindowsForms10.COMBOBOX.app.0.3ce0bb8; INSTANCE:"&$iInstance&"]"
Local $sClassCombo = "[REGEXPCLASS:WindowsForms10\.COMBOBOX\.app\.0\.?; INSTANCE:"&$iInstance&"]"

$hWin = WinGetHandle($sMain);get win handle for use with all control commands
;verify that handle belongs to target window: check IsHWnd() and Title
If Not IsHWnd($hWin) Or WinGetTitle($hWin) <> $sMainTitle Then ; Or StringInStr(_WinAPI_GetClassName($hWin), "", "WindowsForms10.Window") = 0
    ConsoleWrite("! Error: Failed to retrieve form handle" & @CRLF)
    Exit
EndIf

WinActivate($hWin)

$hCombo = ControlGetHandle($hWin, "", $sClassCombo)
If StringInStr(_WinAPI_GetClassName($hCombo), "COMBOBOX") = 0 Or StringRight(_ControlGetClassnameNN($hCombo), 1) <> $iInstance Then
    ConsoleWrite("! Error: Failed to retrieve combobox handle" & @CRLF)
EndIf

;set control focus
;_WinAPI_SetFocus($hCombo);sets keyboard focus - use for testing only as it visually highlights better than ControlFocus
ControlFocus($hWin, "", $hCombo);set control input focus

;show dropdown if required - can change combobox without this
;_GUICtrlComboBox_ShowDropDown($hCombo, True)
;ControlCommand($hWin, "", $hCombo, "ShowDropDown", "")
_GUICtrlComboBox_SetCurSel($hCombo, $iIndex);select dropdown listbox item index to change

;get selected listbox item text
;$iIndex = _GUICtrlComboBox_GetCurSel($hCombo);if getting currently selected item
;_GUICtrlComboBoxEx_GetItemText($hCombo, $iIndex, $sText)
_GUICtrlComboBox_GetLBText($hCombo, $iIndex, $sText)
ConsoleWrite('-$sText = ' & $sText & @crlf)

;get handle to combobox listbox control
_GUICtrlComboBox_GetComboBoxInfo($hCombo, $tInfo)
$hList = DllStructGetData($tInfo, "hList")
ConsoleWrite("+ Handle to the drop-down list: " & $hList & " : Class: " & _WinAPI_GetClassName($hList) & @crlf)

;replace listbox item text
_GUICtrlListBox_ReplaceString($hList, $iIndex, $sReplacetext)

;set current selected item
_GUICtrlComboBox_SetCurSel($hCombo, $iIndex)

;get changed item text
_GUICtrlComboBox_GetLBText($hCombo, $iIndex, $sText)
ConsoleWrite('!$sText = ' & $sText & @crlf)


Func _ControlGetClassnameNN($hControl)
    ;Author: Valik
    If Not IsHWnd($hControl) Then Return SetError(1, 0, "")
    Local Const $hParent = _WinAPI_GetAncestor($hControl, $GA_ROOT)
    If Not $hParent Then Return SetError(2, 0, "")
    Local Const $sList = WinGetClassList($hParent)
    Local $aList = StringSplit(StringTrimRight($sList, 1), @LF, 2)
    _ArraySort($aList)
    Local $nInstance, $sLastClass, $sComposite
    For $i = 0 To UBound($aList) - 1
        If $sLastClass <> $aList[$i] Then
            $sLastClass = $aList[$i]
            $nInstance = 1
        EndIf
        $sComposite = $sLastClass & $nInstance
        If ControlGetHandle($hParent, "", $sComposite) = $hControl Then Return $sComposite
        $nInstance += 1
    Next
    Return SetError(3, 0, "")
EndFunc   ;==>_ControlGetClassnameNN
Edited by rover

I see fascists...

Share this post


Link to post
Share on other sites

I would also look at @error and do testing with ControlGetHandle.

You need to understand why the control is not being found.


Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites

I agree I need to understand why the control is not being found. I will play with this and return results, thanks.

Share this post


Link to post
Share on other sites

help file remarks for ControlCommand()

"Certain commands that work on normal Combo and ListBoxes do not work on "ComboLBox" controls."

the WindowsForms10.COMBOBOX .NET managed control has a ComboLBox listbox class

the Combobox/listbox udfs work, as shown in my code example above.

the code was tested with Putty Connection Manager, a .NET application.


I see fascists...

Share this post


Link to post
Share on other sites

OK that is very illuminating. I did not know how to find out what type of control mine was. I haven't had a chance to experiment with the UDF(s) you posted. I will do so soon and get back to you. Thanks for your help.

Share this post


Link to post
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
Sign in to follow this  
Followers 0