Article View: borland.public.cppbuilder.nativeapi
Article #1257Re: HWND from HPROCESS
From: Remy Lebeau (TeamB)
Date: Mon, 24 Sep 2007 17:53
Date: Mon, 24 Sep 2007 17:53
26 lines
1936 bytes
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
Technical Details
Message-ID:
<46f7f9a2$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<46f6e9ca@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: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <46f6e9ca@newsgroups.borland.com> Subject: Re: HWND from HPROCESS Date: Mon, 24 Sep 2007 10:53:02 -0700 Lines: 28 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 75.83.29.61 Message-ID: <46f7f9a2$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1190656418 75.83.29.61 (24 Sep 2007 10:53:38 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail