Jump to content

ComboBox - find & select a string


sPeziFisH
 Share

Recommended Posts

This is my first post here, so before comin' into detail I want to say hello to the AutoIt-community and want to thank Jon and the AutoIt-Team for their genial work with all my heart :">

While learning more and more of AutoIt I still have to recognize that my brain and my eyes find no solution for the following:

My script starts IrfanView, opens the 'Save as..'-dialog and shall select the JPEG-Format (selection is done by choosing the right entry of a ComboBox).

This is quite easy, but now I want to be language-independent, therefore I changed to classnames and IDs for all the windows and buttons, it's still working fine :ph34r:

With different languages the Name of the ComoBox-Entry changes, for instance 'JPG - JPEG Files' changes to 'JPG - JPEG Dateien'.

I can do a IniRead to get the choosen language and to choose the right string to be selected in the ComboBox (shall the script use the german string or the english one).

Just to get better known to AutoIt and to see what's possible and to find another solution, I want to find a string-appearance in a ComboBox (not an exact string!), so it shall search for 'JPG' and give me the 'occurence' of the string which consist of 'JPG' (not only) (for the start lets assume there's only one string which has JPG inside, anywhere).

$combo_jpeg = ControlCommand("classname=#32770","","ComboBox2","FindString", 'JPG - JPEG Files')
ControlCommand("classname=#32770","","ComboBox2","SetCurrentSelection", $combo_jpeg)

'FindString' only gives the occurence of the string if the string is exact (as it is written in the help-file).

Here are my questions:

1. am I able to get all the ComboBox-entries in an array or sth. like that ?

how to get access to all the entries in a ComboBox - I want to know, what entries can be choosen (GUIread only gives to current selected entry)

2. or is there a find-stringappearance(not exact)-option ?

3. Another problem, see picture below: all IDs are working but not the ComboBox-ID - here I have to use "ComboBox2", which is still okay, but still makes me wonder

ControlCommand("classname=#32770","","ComboBox2","SetCurrentSelection", $combo_jpeg)

;ControlCommand("classname=#32770","","ComboBox2","SelectString", 'JPG - JPEG Files')

works fine

ControlCommand("classname=#32770","",1136,"SetCurrentSelection", $combo_jpeg)

;ControlCommand("classname=#32770","",1136,"SelectString", 'JPG - JPEG Files')

does not :(

Posted Image

BTW sure, Opt("WinTitleMatchMode", 4) is set, AutoIt 3.0.1.03 is used

Link to comment
Share on other sites

sorry, breaking the rules..

@ 3 : seems (I guess) to be some kind of bug, at least it is still a misbehaviour.

@ 1 & 2: I just want to know if you can have a look at all ComboBox-entries, what can be choosen, which entries are still there.

I am incurable sute that one of you knows if this is possible or not :ph34r:

Link to comment
Share on other sites

  • 2 weeks later...

One simple workaround:

$k = 0
While -1
    ControlCommand ("classname=#32770","", "ComboBox2","SetCurrentSelection",$k)
    $index = ControlCommand ("classname=#32770","","ComboBox2","GetCurrentSelection","")
    If ( StringInStr($index,'jpg')) Then ExitLoop
    $k = $k + 1
WEnd

as alternative: use For-loop instead of While-loop

After another search I found this thread (Gui - Combo, Item index...).

I followed CyberSlug's advice and used

Global $CB_GETCOUNT = ....; AFAIK it is 0x0146
$index = GuiSendMsg($comboRef, $CB_GETCOUNT, 0, 0)
MsgBox(4096,"Value", $index)

to get the number of items of the ComboBox (if this test makes me happy I will use CB_FINDSTRING to find a string apperance in my ComboBox-items).

I looked into the winuser.h to get the right hexadecimal-value, as my code is at home I cannot tell you the right one ATM.

I guess it might work if I would have a handle of the ComboBox; in the given thread it is talked about a created GUI, so the user has a control-handle given by GUICtrlCreate...

In my program I am using an existing control, so I don't have any handle.

Using the ControlID does not work - is there a possibility to get a handle of a given control?

In another thread Jon mentioned a control is only a window, haven't tried it out but I guess WinGetHandle(ControlID/-name) might not work.

Any suggestions?

Link to comment
Share on other sites

I know/guessed that the current state has this limitation, but if there would be a function which give me the control identifier to a control not created by AutoIt's GUICtrlCreate... we would have a very powerful tool. This will also save a lot of workarounds (look at my case).

Has to be sth. like ControlGetID("title", "text", "classnameNN")...

Link to comment
Share on other sites

:) I didn't know the undocumented ControlGetHandle(), but thank you Valik.

I tried $index = GuiSendMsg("ComboBox2", $CB_GETCOUNT, 0, 0) and $index = GuiSendMsg(1136, $CB_GETCOUNT, 0, 0) (see picture) ($CB_GETCOUNT was set before) but there wasn't any number to show, the dialog box was still empty.

Therefore I thought maybe AutiIt doesn't know which control it shall 'ping' or send a message to as it doesn't know the target-window (ControlCommand also needs a target-window) - this all made me thinking I need sth. 'more' than a ControlID/name etc. - yes, I told a MsgBox in one of my own GUIs to show me the ControlID the GUICtrlCreate... gave me and it was exactly the same the AutoIt-Spy showed me (so there not seems to be sth. 'more').

Whatever, as the tried stuff didn't work I came here to spend a word on it.

..I will give it a new try, Thx again.

Link to comment
Share on other sites

You can not use GuiSendMsg() unless you wrote the GUI using AutoIt. It is an internal command, not for use with external windows. It doesn't matter how you try to reference it, it's not going to work. There is no general SendMessage function for use with other windows.

Link to comment
Share on other sites

I did everything possible with external controls and it didn't work, it only works with own created GUIControls (here I saw what I wanted to).

I guessed that AutoIt at the current state (which is damn fine without doubt) has this limitation - so, do we have this limitation because a extansion to external controls is not implemented (yet) or because the window-API still has this limitation, whatever we want to do it won't work.

I guess the first one. If it's so does an implementation may be 'easy' to do or will this need a lot of coding time.

May it be useful to drop an idea to the 'Idea Lab' ?

edit: language

Edited by sPeziFisH
Link to comment
Share on other sites

..vom feinsten

solution is here

let's do cool stuff :)

To find a string-occurrence and to select the right comcobox-entry use sth. like the following:

$hwnd = ControlGethandle("Bild speichern als ...","","ComboBox2")
;ControlGethandle("title", "text", "classnameNN")

Global $CB_FINDSTRING = 0x014C

$i = dllcall("user32.dll","int","SendMessage","hWnd",$hwnd,"int",$CB_FINDSTRING,"int", -1,"str", "jpg")
; search for the string "jpg"

ControlCommand ("Bild speichern als ...","", "ComboBox2","SetCurrentSelection",$i[0])

msdn.microsoft.com - CB_FINDSTRING

For the hex-codes of different commands look into the winuser.h (if you got it) or use google

example: a webpage whith hex-codes of different commands

edit: added code for this specific topic

Edited by sPeziFisH
Link to comment
Share on other sites

  • 4 years later...

Guys good time of day. Help please with function thas controls drop-down combo-box.

Posted Image

I'm trying to do it in that way:

ControlCommand ("Save As", "Save in", "ComboBox1", "SelectString", "New Folder")

but have no success. It's not chahged for New Folder instead of PQI.

The full text of script is next:

Run ("notepad.exe")
WinWaitActive ("Untitled - Notepad")
Send ("This is some test.")
WinClose ("Untitled - Notepad")
WinWaitActive ("Notepad", "The text in the Untitled file has changed.")
Send ("!y")
WinWaitActive ("Save As")
ControlCommand ("Save As", "Save in", "ComboBox1", "SelectString", "New Folder")
Link to comment
Share on other sites

  • 4 years later...

Creating a new function (ControlComboBox)

Text translated from Portuguese by google - please apologize for any errors

Is not it time to create a new function in the manner of function ControlListView for ComboBox

Even with sub because in many programs made ​​in MSAccess I use 2 columns of data to the first index (0-width) and the second satisfaction text selection.

EX:

ControlConboBox("", "", "ComboBox1", "GetItemCount")

ControlConboBox ("", "", "ComboBox1", "GetText", $j, 0)

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...