Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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 clear a vector as well as how to detect empty vectors in C++.

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now