Search code examples
c++winapiwindowtopmost

Set a window to be topmost


I am trying to keep my window on top of the all others. I am new to C++ Win32 programming. This is my initialization of my window in WinMain:

hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

I previously worked with dialogs, so the topmost property was really easy to use. But here, on a window I don't know how to set it. I also want to be able to trigger it. Can anybody help me?


Solution

  • Use CreateWindowEx with (extended) window style WS_EX_TOPMOST.

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