I need help finding the Window Handle of a program that is
called by my VC++ 6.0 application. It calls ShellExecute,
but ShellExecute returns a HINSTANCE.
How do I get the window handle (HWND) of the program I
just called. I need to resize it and I cannot use
MoveWindow with the program's title, because I have no
sure way of knowing what the application's title will be.
I tried using EnumWindows, but the instances for the
running programs I find this way are not the same than the
one returned by ShellExecute.
Anyone knows a quick and sure way to get the window handle
of an application started by ShellExecute?
Any help will be appreciated.
Thanks,
Jerome
"Jerome" <jerome_...@hotmail.com> wrote in message
news:01cc01c2a52f$7400f160$d2f82ecf@TK2MSFTNGXA09...
The easiest way to find the window of an application is with the
application's process id. Unfortunately, ShellExecute doesn't give you any
information at all about the process, and ShellExecuteEx only gives you an
HPROCESS (not the process id). If you can, use CreateProcess instead. It
gives you back the process handle *and* id. You then call WaitForInputIdle
on the process handle to wait for the app to finish starting up, then
enumerate the windows and call GetWindowProcessId to locate the window with
the process id you just started. You might need to look for top-level
windows if the called app creates other, perhaps hidden, windows for
communication (e.g. COM).
HTH
Jay
See if this article helps :-
http://www.codeproject.com/system/newbiespawn.asp
Regards,
Nish [VC++ MVP]
"Jerome" <jerome_...@hotmail.com> wrote in message
news:01cc01c2a52f$7400f160$d2f82ecf@TK2MSFTNGXA09...
I just implemented the CreateProcess -> FindWindow ->
GetWindowProcessID and it almost works.
If I test it with something like notepad.exe, it works
great. However, the program I am calling
is "explorer.exe", because I am opening a URL. However,
when calling "explorer.exe", the FindWindow callback
function does not find the processid of the window just
created.
Anyone know why?
Also, of less importance, is there a way to detect if
Internet Explorer is already opened and get that process's
window instead?
It turns out this is not easy; I asked this same question a few weeks ago and got several
rather complex answers, all of which my client rejected as being "too complex to put into
a service updated" (which is sort of what I recommended, as in "I could do what you ask,
but do you really want to release relatively complex and not-very-thoroughly-tested code
in a service updated?"). Check the back postings for the answers.
joe
Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm
Joseph M. Newcomer [MVP]