[comp.windows.ms.programmer] Keeping a window "almost" in front

jls@hsv3.UUCP (James Seidman) (12/14/90)

I'm writing a utility program which I'd like to have (optionally) keep
itself in front of all other programs.  I could, of course, just do a
SetWindowPos() with hWndInsertAfter set to NULL.  The only problem with
this idea, though, is that it gets ugly with screen savers such as Magic,
Screen Peace, and IdleWild.

So, I decided to be real clever:  I set hWndInsertAfter equal to
GetFocus(), figuring that at least most of the time the window with
the focus would be in front.  But doing this makes Windows hang as soon
as it tries it!

I'm sure I'm doing something obvious and stupid here, but I can't for
the life of me figure out what it is.  Any pointers would be appreciated!

-- 
Jim Seidman (Drax), the accidental engineer.
"There's a certain freedom to being completely screwed." - The Freshman
UUCP: ames!vsi1!hsv3!jls	      Internet: hsv3.UUCP!jls@apple.com

miked@banyan.UUCP (Mike Deem@Eng@Banyan) (12/15/90)

In article <6252@hsv3.UUCP> jls@hsv3.UUCP (James Seidman) writes:
>
>So, I decided to be real clever:  I set hWndInsertAfter equal to
>GetFocus(), figuring that at least most of the time the window with
>the focus would be in front.  But doing this makes Windows hang as soon
>as it tries it!
>

You failed to take into account that, besides main appliction windows, controls
dialog boxes, menus, and a few other things are windows. GetFocus returns the
window that has the focus, which is most likely some control, not a top app.
window.

To do what you want, start with the window retuned by GetFocus, then its parent
window, etc. until you find a window that does NOT have the style WS_CHILD. 
This will be the top application window (how has a child that) has the focus.