We help IT Professionals succeed at work.

Acquire contents of a ListBox that's in another application

maxcapacity
maxcapacity asked
on
737 Views
Last Modified: 2007-12-19
I have an application (the controling application) that controls another application (the Target application).

The target application is some other Windows-based application that I cannot control directly other than through the UI. My users would like to automate certain tasks and the controlling application's design goal is to carry out tasks for the user.

I have managed to use C# and P/Invoke to find the application's window, enumerate over the controls, click buttons, and set/clear checkboxes. All of this is great but now I'm stuck.

The target application has a ListBox whose contents move around based on certain criteria. I know that a certain item is somewhere in the ListBox control but I cannot find a way to (a) locate the item and (b) select the item.

I have done some research and have found a number of Windows messages that should work to get a ListBox's item count and even listing of items - but I cannot get that to work. I also need a way to extract the position of the item in the list so that I can simulate a click event.

Sounds complicated? Perhaps. I managed to figure most of this stuff out by inspecting Windows messages using Spy++ but now I need some more help.

You can get full points for answering this question by providing sample code that reads through a ListBox that resides in another application (a commerical application that you don't have the source code for), locates a particular item in the list, and selects the item. The sample must be in C# and use P/Invoke. I'm not at all concerned about finding the application's window or ListBox control - I already know how to do that, so if your sample does not include that but I can get it to work, you'll get full points.

Thanks in advance,

max
Comment
Watch Question

Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
mogun -

I tried SendMessage with LB_SELECTSTRING (defined the constant) - does not work. I tried an exact match including case (just in case) but still no luck.

I have been staring at those LB_* message constants (and trying them) and Spy++ for a long time now without success.
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Hey RomanPetrenko,

Thank you very much - that worked. I tried something very similar but did not get it working. I'm splitting the points, 450 to you, and 50 to mogun since mogun also tried.

Thanks again,

max
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.