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

GetActiveWindow, Win16 vs. Win32?

166 views
Skip to first unread message

Ted Johansson

unread,
Sep 8, 1996, 3:00:00 AM9/8/96
to

I Win16, the API function GetActiveWindow gives me the handle of the active
window.
In Win32 however, GetActiveWindow only gives me the "handle of the active
window associated with the thread that calls the function.", and appearently I
can not find the active window on the screen, only the active window of my
thread.

Is this reaaly so, and then, how do I get the active window?

Regards, Ted

Lucian Wischik

unread,
Sep 8, 1996, 3:00:00 AM9/8/96
to

To get the handle of the foreground window, you use the cunningly-hidden
GetForegroundWindow()

--
Lucian

Jim Hoggarth

unread,
Sep 9, 1996, 3:00:00 AM9/9/96
to

Ted.Jo...@pobox.com (Ted Johansson) wrote:

>I Win16, the API function GetActiveWindow gives me the handle of the active
>window.
>In Win32 however, GetActiveWindow only gives me the "handle of the active
>window associated with the thread that calls the function.", and appearently I
>can not find the active window on the screen, only the active window of my
>thread.

>Is this reaaly so, and then, how do I get the active window?

>Regards, Ted

GetActiveWindow returns the HWND of the active window on a TASK basis,
I believe. I cannot comment as to whether threads in a task play any
part, as I have only ever used threads to implement worker functions,
and not fire up complete window procedures. Although I am not A1
totally sure, GetActiveWindow now acts in a similar way to
GetLastActivePopup. The call you want is GetForegroundWindow. This
returns the HWND of the window which actually has the highlighted
caption bar and, usually, the user input focus - although experience
has shown that it is possible for an inactive window of an MDI client
to have focus and not be the window which appears to have it.

This may be overkill, but I have found that the following always gets
the window handle of the really, truely, kosher active window:

hActive = GetLastActivePopup(GetForegroundWindow())

Jim

-------------------------------------------------------------
Jim Hoggarth, Bradford, UK hogg...@nildram.co.uk
Author of the 'Screen Thief' range of screen capture products
for DOS, Win31 and Win95 (ASP). See http://www.nildram.co.uk
-------------------------------------------------------------


Robert Mashlan

unread,
Sep 9, 1996, 3:00:00 AM9/9/96
to

Ted.Jo...@pobox.com (Ted Johansson) wrote:

>I Win16, the API function GetActiveWindow gives me the handle of the active
>window.
>In Win32 however, GetActiveWindow only gives me the "handle of the active
>window associated with the thread that calls the function.", and appearently I
>can not find the active window on the screen, only the active window of my
>thread.
>
>Is this reaaly so, and then, how do I get the active window?

You might want to take a look at
http://www.r2m.com/win-developer-FAQ/windows/7.html

rm

---
Robert Mashlan R2M Software rmas...@r2m.com
Internet Resources for Windows Developers http://www.r2m.com/windev/


Mike Philben

unread,
Sep 9, 1996, 3:00:00 AM9/9/96
to

In article <50u8b1$n...@erinews.ericsson.se>, Ted.Jo...@pobox.com says...

>In Win32 however, GetActiveWindow only gives me the "handle of the active
>window associated with the thread that calls the function.", and appearently I
>can not find the active window on the screen, only the active window of my
>thread.

>Is this realy so, and then, how do I get the active window?

Yes, it's really so. We use a CBT hook to monotor system wide window
activations.

Mike Philben

>Regards, Ted


Ted Johansson

unread,
Sep 10, 1996, 3:00:00 AM9/10/96
to

The answer to my specific question (cited above) is to use
GetForegroundWindow which seems to give me the correct handle.


Regards, Ted

0 new messages