Solved

Finding window with partial name

Posted on 2011-02-25
6
1,460 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 3

Expert Comment

by:sergiobg57
Comment Utility
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
Comment Utility
0
 

Author Closing Comment

by:ak5745
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

771 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now