-4

I try use SetWindowPos,But someone told me it was wrong to do that.

WIN32 program , How to top window in WIN8/WIN10 ? like the Task Manager。

daijiepei
  • 13
  • 4

1 Answers1

1

Two ways to make a window "top most".

When you create the window with CreateWindowEx, specify WS_EX_TOPMOST as an extended style.

CreateWindowEx(WS_EX_TOPMOST, ...);

For an existing window, use SetWindowPos:

DWORD flags = SWP_NOMOVE | SWP_NOSIZE;
SetWindowPos(hwnd, HWND_TOPMOST, 0,0,0,0, flags);

Either way is fine.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
selbie
  • 100,020
  • 15
  • 103
  • 173
  • @selble DWORD dwType = GetWindowLongPtrW(hwnd, GWL_EXSTYLE); dwType |= WS_EX_TOPMOST; SetWindowLongPtrW(hwnd, GWL_EXSTYLE, dwType); SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); – daijiepei Nov 03 '17 at 07:45
  • @daijiepei - yep. – selbie Nov 03 '17 at 07:54