Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Obtaining an HWND from a process id or thread id

1,830 views
Skip to first unread message

Ora J. Williamson

unread,
Jul 25, 1997, 3:00:00 AM7/25/97
to

What API calls will give me a window handle (HWND) from a process id or
thread id?

Chris Marriott

unread,
Jul 25, 1997, 3:00:00 AM7/25/97
to

In article <33D8E0...@ibm.net>, "Ora J. Williamson"
<ora...@ibm.net> writes

>What API calls will give me a window handle (HWND) from a process id or
>thread id?

Whenever you want to "list" something, look for an API starting with
"Enum"; looking at the help system would have immediately enabled you to
find "EnumTaskWindows" and "EnumThreadWindows".

Chris

----------------------------------------------------------------
Chris Marriott, Microsoft Certified Solution Developer.
SkyMap Software, U.K. e-mail: ch...@skymap.com
Visit our web site at http://www.skymap.com

Ora J. Williamson

unread,
Jul 25, 1997, 3:00:00 AM7/25/97
to

Thanks for your advice, Chris. The problem with EnumThreadWindows and
EnumThreadWndProc is that my app never goes into the callback proc. Why
would that be?

Ora J. Williamson

unread,
Jul 29, 1997, 3:00:00 AM7/29/97
to

GetWindowThreadProcessId

Vivek Kr. Pai wrote:
>
> > Thanks for your advice, Chris. The problem with EnumThreadWindows and
> > EnumThreadWndProc is that my app never goes into the callback proc. Why
> > would that be?
>

> How do you get the thread id that you pass to the EnumThreadWindows()?
> Please give more information/code snippet.
>
> Vivek

Dave Wilson

unread,
Aug 4, 1997, 3:00:00 AM8/4/97
to

Ora J. Williamson wrote:
>
> What API calls will give me a window handle (HWND) from a process id or
> thread id?

Since there is no 1 to 1 correspondance between processes/
threads and HWNDs, I would strongly suspect that this is
not possible. A given process can own no windows or multiple
windows. There may, I suppose, be some way of enumerating
HWNDs owned by a given process but I have not come across
it.

/---------------------------------------------------------\
| Dave Wilson, Rockwell Semiconductor Systems, Austin, TX |
| |
| Owner of "The Almost Definitive FOURCC Definition List" |
| at http://www.flash.net/~dawilson/fourcc |
\---------------------------------------------------------/

Jim O'Brien

unread,
Aug 5, 1997, 3:00:00 AM8/5/97
to

In article <33E5E4...@brooktree.com>, Dave Wilson wrote:
> There may, I suppose, be some way of enumerating
> HWNDs owned by a given process but I have not come across
> it.
>
You can go about it the other way around...use /EnumWindows/ and then
do a /GetWindowLong/ on each handle to get the owner application's
instance handle (/GWL_HINSTANCE/)

Tue, 05 Aug 1997 13:56 EDT
Jim O'Brien, R&D, PTT, Inc.
wiz...@ptti.com +1 (212) 972-1702


Eddie McCreary

unread,
Aug 6, 1997, 3:00:00 AM8/6/97
to

>>>>> "JO" == Jim O'Brien <james....@pobox.com> writes:

JO> In article <33E5E4...@brooktree.com>, Dave Wilson wrote:
>> There may, I suppose, be some way of enumerating HWNDs owned by a
>> given process but I have not come across it.
>>

JO> You can go about it the other way around...use /EnumWindows/ and
JO> then do a /GetWindowLong/ on each handle to get the owner
JO> application's instance handle (/GWL_HINSTANCE/)

Instance handles are no longer unique under Win32. They simly are
the address the exe and/or dll is mapped to in the local address
space.

You can use GetWindowThreadProcessId.

--
"Well, art is art, isn't it? Still, on the other hand, water is water! And
east is east and west is west and if you take cranberries and stew them
like applesauce they taste much more like prunes than rhubarb does."
Captain Jeffrey Spaulding
Eddie McCreary mailto:fo...@neosoft.com http://www.neosoft.com/~forge

Mirko Holzer

unread,
Aug 13, 1997, 3:00:00 AM8/13/97
to

On Mon, 04 Aug 1997 09:17:05 -0500, Dave Wilson
<--dawi...@brooktree.com> wrote:

>Ora J. Williamson wrote:
>>
>> What API calls will give me a window handle (HWND) from a process id or
>> thread id?
>
>Since there is no 1 to 1 correspondance between processes/
>threads and HWNDs, I would strongly suspect that this is
>not possible.

It is possible, but you have to go the other way round: Use
"EnumDesktopWindows" to get all windows and then call
"GetWindowThreadProcessID" for each handle you retrieve and compare
those values to the process id AND thread id you have.

This approach is working fine for 32bit apps, but not for 16bit apps.

Greets
Mirko Holzer

David Ching

unread,
Aug 13, 1997, 3:00:00 AM8/13/97
to

Jim O'Brien wrote:
>
> In article <33E5E4...@brooktree.com>, Dave Wilson wrote:
> > There may, I suppose, be some way of enumerating
> > HWNDs owned by a given process but I have not come across
> > it.
> >
>
Use EnumThreadWindows() to find all windows owned by specified thread.
If you don't know which thread, or you want to do it for all threads in
a process, use TOOLHELP32 functions Process32First, Process32Next,
Thread32First, Thread32Next to iterate through. This is under Win95.

Under WinNT, use performance data stored in registry to get threads and
processes. For more info, e-mail me.

-- David

--
David Ching, Windows Consultant
DC Software Design
http://www.dcsoft.com

0 new messages