C++ console application always on top?

always-on-top, c++, console-application, windows

Solution

The link in OP post refers to Windows.

First you need to obtain a handle for your console window: https://support.microsoft.com/kb/124103

Or even better and modern: GetConsoleWindow way to get that console handle.

Then you need to do quite a simple trick:

::SetWindowPos(hwndMyWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
::ShowWindow(hwndMyWnd, SW_NORMAL);

Problem

I am NOT looking for: - making another window always on top - making any sort of GUI - dialogs etc... on top I am however looking for a way how to make my simple C++ console application to stay always on top, just to be clear - I am looking for a way how to do this programaticly :) I tried hard searching but only found the above - what I do not want... So is there a way how to make your console app always on top programaticly in C++ on Windows? PS: Yes there is an existing question with a coresponding title but the OP of that question is actually looking for something else (keyboard hooks,...) - so answers there are off-topic to my question. Solution: Quick answer => see accepted answer by @AlexanderVX Example & explanation => my answer below

Original source

Related problems