Spy++ or Windows Api Functions not locating controls on child window

Posted on 2010-04-02
Medium Priority
Last Modified: 2012-05-09
I'm trying to write a console application in C# to manipulate another 3rd party Windows application our company uses (written in FoxPro). I'm not seeing all controls on a child page with spy++ or through C# code calling Windows API functions such as FindWindowByIndex() method. Are their some Windows programs that hide controls or that are just written in such a way that they're not accessible, or are their other ways to find them programmatically? My code (using the above and other methods like FindWindow(), FindWindowEx(), etc.) is locating ONLY the same windows/controls that spy++ can see. The window I need to manipulate contains some 50 check boxes, buttons, panels, etc., though Spy++ shows only a few 'next' windows that contain a few dead-end child windows. If I place the finder tool over that windows controls - nothing changes!

Please clue me in on anything (tools, code, shrink, ...) you can think of to find these controls or any info on what may cause these not to show up. I need to know when it's time to stop trying if this is really not possible. Thanks!
Question by:bfay65
  • 4
  • 3
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 29496227
"Are their some Windows programs that hide controls or that are just written in such a way that they're not accessible..."

Absolutely!  There is the notion of a "light" or "heavy" control.  A light control does NOT have it's own window handle and won't be seen by Spy++ (or other similar utilities).  The manipulation of a light control is much more difficult as you usually have to start poking around in the apps memory space to find them.  A heavy control has its own window handle and can receive messages directly.  Some applications use all light controls, others all heavy controls, and some use a combination of both.  (I believe both MS Access and FoxPro use all lightweight controls.)

User interfaces that are browser based in nature (Internet Explorer for example) would be considered completely "light" but are technically something completely different.

On the new technology front, WPF (Windows Presentation Foundation in .Net 3.0 and above) apps draw their interfaces not unlike a game drawing to the screen with OpenGL/DirectX.  So you'll find that apps using WPF don't present you with any handles either...

Author Comment

ID: 29498677
Idle, Thanks for the fast reply!  Looks like you might have been cut off, or were you finished? Your last line looks like this:

So you'll find that apps using WPF don't present you with any handles  either...

I need to know more about how to handle this if it is in fact 'lightweight'.  There was a window blocking, but when I opened the app more and moved the child window out of its scope, spy++ gave it only 1 handle for the whole window.  So how do I 'start poking around in the apps memory space to find them'?  How could I deal with the controls if they're in a group box or 'inside' of some other control - like a grid?  Could that also be the case? How would I know that was the case?  so many questions!  Thanks!
LVL 86

Accepted Solution

Mike Tomlinson earned 1000 total points
ID: 29524158
It's possible to do but way beyond my level of programming...it would require un-managed code to say the least.  =\

Another option is to attempt to automate the process by blindly sending keystrokes with SendKeys.Send() but this is an un-reliable approach at best.

A third approach would be to try a third-party tool such as AutoIt:

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.


Author Comment

ID: 29568449
Idle, Thanks for the suggestions.  I'll may have to try a 3rd party tool, but would like to first prove I can't get to these controls any other way.  I started out using the keystrokes, but found that some fields on this window became inaccessible if 0 orders were shown in a label there, which throws off the number of tabbing needed to access other check boxes.  Therefore; to do what I need, I must access and read that zero in order to proceed (since the process needs to loop hundreds of times and hit the right controls each time.  

Anyone have suggestions on how to prove if either these are in fact 'Lightweight Controls' or if they are wrapped in some other type of proprietary or otherwise-limiting control?

Author Comment

ID: 30020423
So to rephrase...What steps does one take to automate an application when spy++ does not see the controls you need?  Since the tabbing routine changes depending on the data in the controls, simple SendKeys patterns won't work.  I will need to see the data in the labels and checkboxes to control the steps.

Possible issues:
1. The controls are 'lightweigt' and therefore virtually inaccessible (but how can I tell?)
2. The controld are 'wrapped' or 'nested' in another control like a panel (What then?  Win API functions i.e. FindWindowsEx() aren't finding child windows)
3. Please suggest other reasons these won't show up and/or what to try next

LVL 86

Expert Comment

by:Mike Tomlinson
ID: 30020644
Basically if Spy++ doesn't show a handle then it is lightweight and I don't know how to access it.  Sorry...  =\

Author Closing Comment

ID: 31712511
Auto-IT worked well enough to automate the program, though I was really hoping someone could help me figure out how to identify and read the controls on the page, Idle's suggestion was the only suggestion and he helped me get this solution going.  Thanks Idle!

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

This is a little timesaver I have been using for setting up Microsoft Small Business Server (SBS) in the simplest possible way. It may not be appropriate for every customer. However, when you get a situation where the person who owns the server is i…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question