-
October 23rd, 2009, 05:16 PM
#1
FindWindow() issue
hello,
I'm using FindWindow() function to find a specific window/dialog.
as all the windows have the same name I can not use the Windowname in the function.
(if I use it, the function finds the first, while I need the third)
using a counter is not an option think of the possibility of next en back buttons
so I have to use the Classname arg., I think...
I know all the windows have static text items.
window 3 has 5 edit control boxes, I also know the ID numbers (Spy++ and Orca)
they are 1304 to 1308. So window 3 is Unique
how do I define the function, so it catches the 3 window?
regards,
ger
-
October 25th, 2009, 05:22 AM
#2
-
October 25th, 2009, 09:44 AM
#3
Re: FindWindow() issue
I guess if the windows have the same titles their classnames in most cases are also identical. So you can't use it to differentiate them.
It's hard to answer something without having enough information.
What's your "initial" problem? Why should you find this window?
-
October 25th, 2009, 01:21 PM
#4
Re: FindWindow() issue
The general strategy is to use all the criteria you can to get the window you need.
Here's what you have to work with:
1) The pid of the application. If you have launched the application, then you have its pid. The pid can be used to eliminate windows that aren't in the target application. Use GetWindowThreadProcessId to determine if a window is part of the target app.
2) Use the window title. If the title is constant you should always use it. If it changes then try to use a portion of the title that may not change. For example, the top level window title in the IE window I'm typing in is "CodeGuru Forums - Repy to Topic - Windows Internet Explorer". If I'm searching for this window, I know that the "Windows Internet Explorer" portion is constant so I can do a partial match for that.
3) Use the class name. The strategy here is similar to the title. Use the class name whenever possible and a partial match is better than nothing.
4) Search with the parent window. A good strategy is always supply a parent window handle with searching for a child window. This eliminates finding windows with the same title and class name, but have a different parent window.
5) Use all in combination. I usually launch the target application, store its pid, and then immediately find its top level window. I then use the top level window to build a hierarchy of windows as needed. That way all my child windows searches are performed using the hierarchy that I've built up. And because I've restricted the first top level window by the pid, I am ensured that I will only find windows in my application.
-
October 26th, 2009, 11:18 AM
#5
Re: FindWindow() issue
If the window you need cannot be identified solely by title/classname:
use EnumWindows(), and provide a callback to do whatever additional testing you need to identify the proper window.
-
October 26th, 2009, 01:27 PM
#6
Re: FindWindow() issue
EnumWindows() is what I would use in this case too.
-
October 26th, 2009, 03:05 PM
#7
Re: FindWindow() issue
While EnumWindows is a great choice for determining the top level window for an application, it's not very performant (because it enumerates all the windows on the system).
If you are trying to capture child windows of a specific window or dialog, FindWindowEx or EnumChildWindows will yield better performance.
-
October 27th, 2009, 02:58 PM
#8
Re: FindWindow() issue
Thank you guys for all the replies !!
to be more specific.
I made a program which calls at certain time an installer (Call of Duty -2-).
I use the call _spawnlp with the _P_NOWAIT option.
when dialog three shows up a serial has to be inserted.
using the Sleep(number) in combination with keybd_event('X', 0, 0, 0 )
I managed to insert the text.
but the Sleep() option is not waterproof!! (read poor programming)
so I need to capture the third window iso using a timer.
using PID is also difficult as the installer also creates new processses.
As all windows are using the same title "Call odf Duty 2" I can not differentiate on that,
however dialog three has 5 edit boxes. This an unique point as the installer will not
move on as long as the correct serail is not inserted.
is there a way to test on the existence of the edit boxes or on a part of static text?
I have also been testing with a program called AutoIt v3
it uses a call like
WinWaitActive("Call of Duty(R) 2","The Key Code is loca")
to find the requested window/dialog.
I will have a go with the posted suggestions
regards,
gerwin
-
October 27th, 2009, 05:17 PM
#9
Re: FindWindow() issue
You can use EnumChildWindows to enumerate all the child windows of a given top level window.
Then you can use GetDlgItem to find a specified control in a window. That function requires the identifier of the control. You can find that identifier using the Spy++ application.
Note that the identifier is a constant and will have the same value every time you run the application. So you need to find it only once, then you can hard code the identifier in your application.
-
October 28th, 2009, 12:26 AM
#10
Re: FindWindow() issue
Originally Posted by srelu
Note that the identifier is a constant and will have the same value every time you run the application. So you need to find it only once, then you can hard code the identifier in your application.
Not necessarily. It is not a constant. It may be defined as constant in a code but ID of any window can be changed on the fly by the application’s code.
There are only 10 types of people in the world:
Those who understand binary and those who do not.
-
October 28th, 2009, 05:22 PM
#11
Re: FindWindow() issue
this should to the trick
PID = _spawnlp(_P_NOWAIT,"C:\\COD2\\COD2DVD\\setup.exe"," ",NULL);
lhwnd = NULL;
lhwnd_test = NULL;
while (lhwnd == NULL)
{
lhwnd = FindWindow(NULL, L"Call of Duty(R) 2");
if (lhwnd != NULL)
lhwnd_test = GetDlgItem(lhwnd, 1304);
if (lhwnd_test == NULL)
lhwnd = NULL;
Sleep(100);
}
any finetuning comments
regards.
ger
-
October 28th, 2009, 06:03 PM
#12
Re: FindWindow() issue
Are you trying to break this game's registration by brute force?
First, this is illegal.
And second, this is stupid.
P.S. Your original post smelled like a cheat; didn't want to say anything until I was sure.
P.P.S. This forum used to be full of interesting questions / answers. Now it mostly has requests from kiddie hackers (who haven't mastered "Hello World" yet) or homework assignment... That's a shame.
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
October 29th, 2009, 03:17 AM
#13
Re: FindWindow() issue
Virus and anti-virus technology, we need to study them. Just not do bad things on the list.
-
October 29th, 2009, 03:38 AM
#14
Re: FindWindow() issue
Understand that on this forum, we are if violation of the AUP if we answer any virus related questions.
-
October 29th, 2009, 07:51 AM
#15
Re: FindWindow() issue
A lot of legitimate stuff can be virus related.
I find myself spending more and more time into projects that need me to interface to other programs, often programs that weren never intended to be interfaced to. So I tend to need a lot of low level stuff that could just as easily be used maliciously.
Even stuff like this very question. Automating/scripting an installation that hasn't got provesions for it is part of the common problems I'm needing to solve. There's a thin line between filling in a known registration key and filling in a registration key at random trying to break a code. All of the code would be the same except for 3 or 4 lines of code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|