Solved

Finding window with partial name

Posted on 2011-02-25
6
1,527 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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 86

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

738 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