Solved

Finding window with partial name

Posted on 2011-02-25
6
1,563 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
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

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:…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

632 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