Solved

FindWindow - Finding a name that is 'partial' to the window name C++

Posted on 2009-05-10
3
837 Views
Last Modified: 2012-05-06
I am trying to find a process name that may have a different version number, for example:

HANDLE test = FindWindow(TEXT("Test Window"), NULL);
if(test)
  return true;

Will find a window that is called "Test Window"... However, what if there is a number that changes once and awhile, for example:

"Find Window v1.2"
"Find Window v1.3"
"Find Window Beta"

What I'd want is it to return TRUE for all these of these. Basicly like if a partial name is found it should return TRUE, otherwise false.

Anyone got any suggestions?
0
Comment
Question by:Valleriani
[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 Comments
 
LVL 40

Accepted Solution

by:
evilrix earned 350 total points
ID: 24347893
Use EnumWindow to enumerate all open windows. Use strncmp to look for a Window that starts with the string you are looking for. When found, stop enumerating the Windows. Since this work is done in a callback you'll need to persist the Window handle somewhere to retrieve after.
0
 
LVL 7

Author Comment

by:Valleriani
ID: 24348127
I have some following code attached.

For some reason this gives me a debug error of: i386/chkesp.c

"The value of the ESP was not properly saved across a function call..."

Any suggestions?
BOOL EnumWindowsProc(HWND hWnd, long lParam)
{
	char Buff[255];
 
	GetWindowText(hWnd, Buff, 254);
	if (strncmp (Buff,"Test Window xxx",11) == 0)
	  return TRUE;
}
 
BOOL FindProcess()
{
	EnumWindows((WNDENUMPROC)EnumWindowsProc, 0);
		return TRUE;
}

Open in new window

0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 150 total points
ID: 24348268
You are missing the 'CALLBACK' attribute for your EnumWindowsProc which causes a different calling convention and therefore this error - better use
BOOL CALLBACK EnumWindowsProc(HWND hWnd, long lParam)
{
        char Buff[255];
 
        GetWindowText(hWnd, Buff, 254);
        if (strncmp (Buff,"Test Window xxx",11) == 0)
          return TRUE;
}

Open in new window

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

762 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