🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
5 messages
5 total messages Started by Ray Carpenter Mon, 24 Sep 2007 15:38
HWND from HPROCESS
#1250
Author: Ray Carpenter
Date: Mon, 24 Sep 2007 15:38
9 lines
987 bytes
Colleagues

For a process, is there a way of obtaining the main window handle HWND (as
needed by SendMessage()) from the process handle HPROCESS (as provided by
ShellExecuteEx())?

Regards

Ray Carpenter
Re: HWND from HPROCESS
#1253
Author: Darko Miletic
Date: Mon, 24 Sep 2007 12:17
15 lines
1415 bytes
Ray Carpenter wrote:
> Colleagues
> 
> For a process, is there a way of obtaining the main window handle HWND (as
> needed by SendMessage()) from the process handle HPROCESS (as provided by
> ShellExecuteEx())?
> 

Take a look at EnumProcesses API or here for example:

http://www.codeproject.com/threads/enumprocess.asp

or here:

http://delphi.about.com/od/windowsshellapi/l/aa080304a.htm
Re: HWND from HPROCESS
#1257
Author: Remy Lebeau (TeamB)
Date: Mon, 24 Sep 2007 17:53
26 lines
1936 bytes
"Ray Carpenter" <rjcarpenter@bigpond.com> wrote in message
news:46f6e9ca@newsgroups.borland.com...

> For a process, is there a way of obtaining the main window handle
> HWND (as needed by SendMessage()) from the process handle
> HPROCESS (as provided by ShellExecuteEx())?

There is no such thing as a "main window" from the API's perspective.  Any
thread can have any number of HWNDs associated with it.

You can enumerate the running windows using EnumWindows(), using
GetWindiowLong(GWL_HINSTANCE) to get the HINSTANCE of each window and
compare that to the one returned by ShellExecuteEx().

Alternatively, you can use CreateProcess() instead of ShellExecuteEx(), and
then use GetWindowThreadProcessId() instead of GetWindowLong() to find all
of the windows that belong to the Process ID that CreateProcess() returns.

Either way, if you only find 1 matching HWND, then you likely found its
"main" window.  Note that many applications (including VCL apps) have
multiple HWNDs in their main thread, so it is up to you to manually
determine which HWND you need to send your messages to.


Gambit
Re: HWND from HPROCESS
#1255
Author: Ray Carpenter
Date: Tue, 25 Sep 2007 07:27
27 lines
1537 bytes
Darko

Thanks for your suggestion - I will check it out.

Regards

Ray Carpenter

"Darko Miletic" <kiklop@fibertel.com.ar> wrote in message
news:46f7aad4$1@newsgroups.borland.com...
> Ray Carpenter wrote:
> > Colleagues
> >
> > For a process, is there a way of obtaining the main window handle HWND
(as
> > needed by SendMessage()) from the process handle HPROCESS (as provided
by
> > ShellExecuteEx())?
> >
>
> Take a look at EnumProcesses API or here for example:
>
> http://www.codeproject.com/threads/enumprocess.asp
>
> or here:
>
> http://delphi.about.com/od/windowsshellapi/l/aa080304a.htm
Re: HWND from HPROCESS
#1260
Author: Ray Carpenter
Date: Tue, 25 Sep 2007 18:16
45 lines
2541 bytes
Remy

Thanks for your suggestions. You are almost an infinite source of wisdom in
these matters.

I will try out your first suggestion using the instance handle HINSTANCE
provided by ShellExecuteEx() instead of the process handle referred to in my
original posting.

Regards

Ray Carpenter


"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message
news:46f7f9a2$1@newsgroups.borland.com...
>
> "Ray Carpenter" <rjcarpenter@bigpond.com> wrote in message
> news:46f6e9ca@newsgroups.borland.com...
>
> > For a process, is there a way of obtaining the main window handle
> > HWND (as needed by SendMessage()) from the process handle
> > HPROCESS (as provided by ShellExecuteEx())?
>
> There is no such thing as a "main window" from the API's perspective.  Any
> thread can have any number of HWNDs associated with it.
>
> You can enumerate the running windows using EnumWindows(), using
> GetWindiowLong(GWL_HINSTANCE) to get the HINSTANCE of each window and
> compare that to the one returned by ShellExecuteEx().
>
> Alternatively, you can use CreateProcess() instead of ShellExecuteEx(),
and
> then use GetWindowThreadProcessId() instead of GetWindowLong() to find all
> of the windows that belong to the Process ID that CreateProcess() returns.
>
> Either way, if you only find 1 matching HWND, then you likely found its
> "main" window.  Note that many applications (including VCL apps) have
> multiple HWNDs in their main thread, so it is up to you to manually
> determine which HWND you need to send your messages to.
>
>
> Gambit
>
>
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads