Colen
Colen

Reputation: 13888

How can I make a child window topmost?

I have a parent form, with some child windows (not forms - just windows, for example label controls) inside it. Under certain circumstances, I want one of those child windows to be drawn "above" the others, to display a message over the entire main form.

I've tried setting HWND_TOPMOST and HWND_TOP on the child windows, but it doesn't seem to have any effect at all. Am I doing something wrong, or do HWND_TOPMOST and HWND_TOP only work on forms, as opposed to controls within forms?

Thanks.

Upvotes: 2

Views: 4251

Answers (2)

I came across that problem when I wanted to put a scroll bar control on top of all the child windows.

My solution was:

  1. Use WS_CLIPSIBLINGS to all the child windows. This prevents overlapping areas of sibling windows from being redrawn.
  2. Use SetWindowPos with HWND_TOP on hWndInsertAfter to put it on top of other controls.

Upvotes: 2

dthorpe
dthorpe

Reputation: 36072

HWND_TOPMOST only applies to top level windows, not child windows.

Use SetWindowPos withthe HWND_TOP flag to change the target child window's zorder to put it at the top of the zorder among its siblings.

Note that zorder in child windows only applies to siblings - hwnds with the same parent.

Upvotes: 4

Related Questions