Solved

Finding window with partial name

Posted on 2011-02-25
6
1,481 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Suggested Solutions

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

832 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