Slavak
asked on
ShellExecute window...
I open files using ShellExecute command. The command opens application, according to file type. Can I get window handle of starting application?
For example,
I open txt file.
Notepad started.
Now I want get window handle of notepad (to change size, location etc. of the window)
For example,
I open txt file.
Notepad started.
Now I want get window handle of notepad (to change size, location etc. of the window)
Listening :-)
If you use ShellExecuteEx to execute it, you will need to pass in a PShellExecuteInfo. The function will return back the ShellExecuteInfo structure, which contains hProcess, a handle to the newly started application (of course, you need to set PShellExecuteInfo^.fMask to include SEE_MASK_NOCLOSEPROCESS). Using that handle, you can call stuff like what Madshi said.
(Hi, Madshi!)
DragonSlayer
(Hi, Madshi!)
DragonSlayer
Hi DragonSlayer! :-)
Unfortunately it's not fully correct, what you said. You can get a process *HANDLE* from ShellExecuteEx. But what we need for comparing enumerated windows is a process *ID*. That are two different beasts. And there is no official way to get the ID from the handle (though I'm having hacked functions that do that... :-).
Regards, Madshi.
Unfortunately it's not fully correct, what you said. You can get a process *HANDLE* from ShellExecuteEx. But what we need for comparing enumerated windows is a process *ID*. That are two different beasts. And there is no official way to get the ID from the handle (though I'm having hacked functions that do that... :-).
Regards, Madshi.
ASKER
Thanks, Madshi.
I thinked about the way, but hoped for better way to do it.
This way has 2 major problems:
-- how much is "a bit" (time between calls to CreateProcess and EnumWindows)
-- it can be too slow
still hope for better solution :)
I thinked about the way, but hoped for better way to do it.
This way has 2 major problems:
-- how much is "a bit" (time between calls to CreateProcess and EnumWindows)
-- it can be too slow
still hope for better solution :)
ASKER
I can compromise with the solution if I can GET EVENT that started application ready
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
There is more elegant (but more difficult too) way:
(1) Create process
(2) Set hook on CreateWindow(ex) function in the process.
Demerit of this way is that hook function should be in dll.
I should minimize executable file(s) size.
May be you can suggest another way.
Thanks
(1) Create process
(2) Set hook on CreateWindow(ex) function in the process.
Demerit of this way is that hook function should be in dll.
I should minimize executable file(s) size.
May be you can suggest another way.
Thanks
Well, but in your exe file you need the window handle, don't you? So you would in your exe file still need to wait for your dll to send the window handle to you, or am I wrong? So basically I see no advantage, the only advantage is that you don't need to poll, but get notified about the window creation. But polling in a loop with a sleep(100) in the loop is really no problem at all.
For what purpose do you need the window handle? What do you want to do with it? Maybe we can find a better way, if I know what you really want to do.
For what purpose do you need the window handle? What do you want to do with it? Maybe we can find a better way, if I know what you really want to do.
ASKER
I want set position and size of the window.
For this, no need return event from hook to application. I can pass required values when I set the hook, and after first top window, remove the hook.
I think about way to open file in my window, like com objects in TOLEContainer.
For this, no need return event from hook to application. I can pass required values when I set the hook, and after first top window, remove the hook.
I think about way to open file in my window, like com objects in TOLEContainer.
Hmmm... Okay, in such a situation a hook could be solution, a bit work, but possible. However, if you look at how e.g. Delphi's windows look like (multiple top-level windows, main window, edit window, object inspector, project manager, etc) you'll run into problems with what you want to do... :-(
Regards, Madshi.
Regards, Madshi.
Regards, Madshi.