Solved

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

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

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…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

717 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