Always on top C#

As @AlexanderVX's answer shows an quick answer, I wanted to also show you my final implementation with appropriate comments explaining what does what :) :

Don't forget to set Windows version same or greater than 0x0500 and include windows.h library:

#define _WIN32_WINNT 0x0500 #include

I've put mini-app example on: http://ideone.com/CeLQj3

Example with explanation:

// GetConsoleWindow() => returns: // "handle to the window used by the console // associated with the calling process // or NULL // if there is no such associated console." HWND consoleWindowHandle = GetConsoleWindow(); if( consoleWindowHandle ){ cout << endl << "Setting up associated console window ON TOP !"; SetWindowPos( consoleWindowHandle, // window handle HWND_TOPMOST, // "handle to the window to precede // the positioned window in the Z order // OR one of the following:" // HWND_BOTTOM or HWND_NOTOPMOST or HWND_TOP or HWND_TOPMOST 0, 0, // X, Y position of the window (in client coordinates) 0, 0, // cx, cy => width & height of the window in pixels SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW // The window sizing and positioning flags. ); // OPTIONAL ! - SET WINDOW'S "SHOW STATE" ShowWindow( consoleWindowHandle, // window handle SW_NORMAL // how the window is to be shown // SW_NORMAL => "Activates and displays a window. // If the window is minimized or maximized, // the system restores it to its original size and position. // An application should specify this flag // when displaying the window for the first time." ); cout << endl << "Done."; } else { cout << endl << "There is no console window associated with this app :("; }

References:

PS: I wanted to post this as an edit to @AlexanderVX's answer, but most of stackoverflow's reviewers somehow thought that "This edit deviates from the original intent of the post"...