Solved

Finding window with partial name

Posted on 2011-02-25
6
1,495 Views
Last Modified: 2013-12-17
EE,

I'm currently using FindWindow() and FindWindowEx() to find child windows with static names. However, one of the child window's name is dynamic. Actually, the last 3 characters of the string are dynamic - the first 10 or so are static.

I've done my searching and have seen examples of EnumWindows() of EnumChildWindows() doing the trick, but all were in C++. Anyone have a C# version?

Also, is there a way to use FindWindowEx() to do this instead?

Thanks!
0
Comment
Question by:ak5745
  • 3
  • 2
6 Comments
 
LVL 3

Expert Comment

by:sergiobg57
ID: 34982855
FindWindows + EnumChildWindows would do the trick.

In fact, even findWindows should do the trick.
Are you looking for windows using Title String or Class Name?
If the windows is yours, you should be able to get the class name, and use recursively GetWindowText in order to find your window.

Anyway, i don't develop using C#, i do using C++ but if you post the part of your source where you use the FindWindow, i might be able to code the EnumChildWindows callback after seeing some junk of code which uses WINAPIs from this language.
0
 

Author Comment

by:ak5745
ID: 34982947
The window belongs to another application. And yes, I am searching using the title string - all the child windows at the level I'm interested in have the same class name (I'm using Spy++ for that info).

All I'm doing with FindWindow is search for the main window, then use those results as an argument (parent) to FindWindowEX. I'll do that all the way down to the level where the child window I need resides. At that point, I'm stuck. I have the child windows parent, and its class name, but am unable to grab that specific window due to the partially dynamic title.

You're thinking GetWindowText might work for me?
0
 
LVL 3

Accepted Solution

by:
sergiobg57 earned 300 total points
ID: 34982976
GetWindowText is almost a simplification of EnumChildWindows.

You can get all the childs by classname, and the use GetWindowText on their names until you find the window title you need by comparing their names using the String class after erasing the random characters at the end of the title.
It's basically the same of using EnumChildWindows without the need to use a callback function.
0
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
LVL 3

Expert Comment

by:sergiobg57
ID: 34982992
Correcting:
and use GetWindowText on their handles

It's basically the same as using EnumChildWindows


Dear god, my english is just getting worse from time to time!
0
 
LVL 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 200 total points
ID: 34983921
0
 

Author Closing Comment

by:ak5745
ID: 34987650
sergiobg57:
GetWindowText works great. As you said, I chopped off the dynamic part of the handle and just searched for it.

Idle_Mind:
Never thought of using SendMessage and sending the GetText message. Thanks for the class!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

828 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