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?
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?
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.
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 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.