Solved

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

Posted on 2009-05-10
3
852 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

Title # Comments Views Activity
GUI: DIalog Stacking and Popping in MS C++ 4 96
How to split this in C++ 4 127
Arduino EDI - Programming language 3 125
sorting efficency of sorting algorithm 30 149
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…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

737 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