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?
You can now press Ctrl+Space to set any currently active window to be always on top. Press Ctrl+Space again set the window to no longer be always on top. And if you don't like the Ctrl+Space combination, you can change the ^SPACE part of the script to set a new keyboard shortcut.
You can use the GetTopWindow function to search all child windows of a parent window and return a handle to the child window that is highest in z-order. The GetNextWindow function retrieves a handle to the next or previous window in z-order.
Gets or sets a value that indicates whether a window appears in the topmost z-order. public: property bool Topmost { bool get(); void set(bool value); }; C# Copy.
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)
Use CreateWindowEx
with (extended) window style WS_EX_TOPMOST
.
Disclaimer: it's about 15 years or so since I touched that stuff.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With