ravi_npatty

Unable to get text or count from listbox

8 posts in this topic

Hello All,

  I am new to Autoit. I am using Windows 10 (64 bit). I tried tutorials and all went smooth till I started my own project. I want to capture some data from a stand alone application and store it in database.

  Data which I am interested are in Static, Edit and Listbox. I have no problem in getting the data from Static or Edit controls. I am unable to get anything from listbox except its handle. I tried _GUICtrlListbox_GetCount, _GUICtrlListbox_GetText, _GUICtrlListbox_GetItemData and nothing gives any information.

I tried on Windows 7 platform (32 bit) also with same application and the results are same.

 

Code:

#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListBox.au3>
#Include <Array.au3>
 

dim $obwin,$ttt,$tt
$obwin=WinWait("Snap Quote of","",1)
if $obwin="" Then
   MsgBox(0,"","No snap quote window open")
Else
  $ttt=ControlGetHandle($obwin,"","[CLASS:ListBox; INSTANCE:2]")
   MsgBox(0,"",$ttt)

   $tt=_GUICtrlListBox_GetCount($ttt)

   MsgBox(0,"",$tt)
EndIf

 

Please somebody help me what I am missing.

 

 

Share this post


Link to post
Share on other sites



I am able to manually click, Ctrl+C to copy the information from that listbox. But when I try to do that using mouseclick(177,445) & Send("{CTRLDOWN}c{CTRLUP}") nothing comes to clipboard. It seems mouseclick itself not really working since that control focus is not set.

I successful in using mouseclick Ctrl+A Ctrl+C to copy content from notepad. but similar thing is not working with this application.

I wonder is the application resisting automation? I think atleast mouseclick copy to clipboard should work since that is working manually. Please somebody suggest what I can do.

Thanks.

Share this post


Link to post
Share on other sites

Some observations and suggestions:

  1. The WinWait() function returns a window handle, not a string, so check for zero (failure) or non-zero (a handle - success)
  2. The application window should probably be active before accessing its controls; a call to WinActivate() after a successful return from WinWait() will do that (it also returns zero on failure and the window handle on success)
  3. Your example code is telling WinWait() to wait at most 1 second for the application window to exist:
    • If the application is already up and running before your script is run, that timeout should be fine
    • If the app is run after your script is running, I would suggest increasing the timeout or else eliminating it altogether by removing the 3rd argument to WinWait()
  4. For retrieving text from the ListBox, take a look at _GUICtrlListBox_GetText(); it needs the zero-based index of the item whose text you want, so you may need to use other GUIListBox functions to find your text and get the index if you don't already know its value.

When the going gets tough, the tough start coding.

Share this post


Link to post
Share on other sites

Thanks tremolux66 for your reply.

 

  1. The WinWait() function returns a window handle, not a string, so check for zero (failure) or non-zero (a handle - success) : I checked this using msgbox and returns a valid handle.
  2. The application window should probably be active before accessing its controls; a call to WinActivate() after a successful return from WinWait() will do that (it also returns zero on failure and the window handle on success). I did this step also. Just omitted this in code mentioned here to keep it small.
  3. Your example code is telling WinWait() to wait at most 1 second for the application window to exist:
    • If the application is already up and running before your script is run, that timeout should be fine
    • If the app is run after your script is running, I would suggest increasing the timeout or else eliminating it altogether by removing the 3rd argument to WinWait() The application is already running. So I think timeout is fine.
  4. For retrieving text from the ListBox, take a look at _GUICtrlListBox_GetText(); it needs the zero-based index of the item whose text you want, so you may need to use other GUIListBox functions to find your text and get the index if you don't already know its value. I tried almost all GUIListBox functions like _GUICtrlListBox_GetText, _GUICtrlListBox_GetItemData, _GUICtrlListBox_GetCount. I  could not get even list count. But I get a valid handle. I can get its size and position. But nothing more than this.

Manually I can click on an item in the list (any position) and Ctrl+C to copy to clipboard. But with autoit, even mouseclick command not clicking on the item (as it is not getting focus). Atleast if mouse click on that x,y coordinate works, I can make progress.

Please help me.

 

Thanks.

Share this post


Link to post
Share on other sites

You might've mentioned those additional details in your post.

If none of the GUIListBox UDFs were helpful, look at the built-in ControlXXX functions. For example, try making a selection in the ListBox and have your script then call ControlCommand() with "GetCurrentSelection" as the command argument. I generally stick to using the ControlXXX functions as much as possible when manipulating another application from an AutoIt script. If you need to click on a control, I'd recommend using ControlClick() instead of MouseClick(), and for sending characters I'd use ControlSend() rather than Send() because the ControlXXX functions communicate directly with the control.


When the going gets tough, the tough start coding.

Share this post


Link to post
Share on other sites

Sorry for not completely giving the details. I tried many things. I think I did not try controlClick(). WIll try and get back. Actually that listbox is for just displaying items and no selection can be made (atleast not visible). If I click manually, that item gets focus and within a second the focus automatically shifts to first item in the listbox. If I press control+C immediately value in that item gets copied, if there is delay, only value in first item gets copied since the focus shifts.

I will try controlClick, ControlSend commands and get back. I am not at home. I think it may take few days for me to try this. Will post update after trying. Thanks.

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

Thanks tremolux66 and LarsJ for your interest and Sorry for delayed reply.

  I tried controlclik also. Even though it return 1 as feedback, I could not see any change in focus and Unable to get the contents copied to clipboard.

Since I dont have inspect.exe, I tried winspy1.7. This is also showing the listbox, but number of items in listbox could not be obtained.

I am afraid this may be a custom listbox.

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