🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #1260

Re: HWND from HPROCESS

#1260
From: 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
>
>
Technical Details
Message-ID: <46f86038@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <46f6e9ca@newsgroups.borland.com> <46f7f9a2$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,da404016b88d04f2
X-Google-Attributes: gid10cc67,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Ray Carpenter" <rjcarpenter@bigpond.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <46f6e9ca@newsgroups.borland.com> <46f7f9a2$1@newsgroups.borland.com>
Subject: Re: HWND from HPROCESS
Date: Tue, 25 Sep 2007 11:16:13 -0700
Lines: 47
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 124.176.48.210
Message-ID: <46f86038@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1190682680 124.176.48.210 (24 Sep 2007 18:11:20 -0700)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail