Set a window to be topmost

Use CreateWindowEx with (extended) window style WS_EX_TOPMOST.

Disclaimer: it's about 15 years or so since I touched that stuff.


SetWindowPos(hwnd01, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);

Note: SWP_NOMOVE | SWP_NOSIZE are for ignoring 3rd, 4th, 5th, 6th parameters of the SetWindowPos function.

The second parameter can be:

  • HWND_BOTTOM

  • HWND_NOTOPMOST (set window to be a normal window)

  • HWND_TOP

  • HWND_TOPMOST (set window to be always on top)


see SetWindowPos, hWndInsertAfter parameter. passing HWND_TOPMOST should do what you want.

additionally, you may want to pass SWP_NOMOVE | SWP_NOSIZE to uFlags parameter if you want to keep position and size unchanged.