Solved

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

Posted on 2009-05-10
3
827 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
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

840 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