fork(5) download
  1. /***
  2.  * THIS IS AN PUBLIC WINDOWS C++ MINI-APP
  3.  * TO DEMONSTRATE MAKING A CONSOLE WINDOW ALWAYS ON TOP
  4.  *
  5.  * COMPILE & USE ON WINDOWS (not here :P)
  6. ***/
  7. #include <iostream> // standard input/output C++ library
  8.  
  9. #define _WIN32_WINNT 0x0500 // to use certain API, the windows version must be set to 0x0500 or more
  10. #include <windows.h> // using main Windows library for C++ Windows API
  11.  
  12. using namespace std; // to make this example clearer - not recommended for production
  13.  
  14. int main() {
  15.  
  16. // GetConsoleWindow() => returns:
  17. // "handle to the window used by the console
  18. // associated with the calling process
  19. // or NULL
  20. // if there is no such associated console."
  21. HWND consoleWindowHandle = GetConsoleWindow(); // getting the console window handle
  22.  
  23. if( consoleWindowHandle ){
  24. cout << endl << "Setting up associated console window ON TOP !";
  25. SetWindowPos(
  26. consoleWindowHandle, // window handle
  27. HWND_TOPMOST, // "handle to the window to precede
  28. // the positioned window in the Z order
  29. // OR one of the following:"
  30. // HWND_BOTTOM or HWND_NOTOPMOST or HWND_TOP or HWND_TOPMOST
  31. 0, 0, // X, Y position of the window (in client coordinates)
  32. 0, 0, // cx, cy => width & height of the window in pixels
  33. SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW // The window sizing and positioning flags.
  34. );
  35. // OPTIONAL - SET WINDOW'S "SHOW STATE"
  36. ShowWindow(
  37. consoleWindowHandle, // window handle
  38. SW_NORMAL // how the window is to be shown
  39. // SW_NORMAL => "Activates and displays a window.
  40. // If the window is minimized or maximized,
  41. // the system restores it to its original size and position.
  42. // An application should specify this flag
  43. // when displaying the window for the first time."
  44. );
  45. cout << endl << "Done.";
  46. } else {
  47. cout << endl << "There is no console window associated with this app :(";
  48. }
  49.  
  50. char buffer = 'y';
  51. while( buffer != 'n' ){
  52. cout << endl << "Continue? (y/n):";
  53. cin >> buffer;
  54. }
  55.  
  56.  
  57. return 0;
  58. }
  59.  
  60. /***
  61. References:
  62.  
  63. GetConsoleWindow => http://msdn.microsoft.com/en-us/library/windows/desktop/ms683175%28v=vs.85%29.aspx
  64. SetWindowPos => http://msdn.microsoft.com/en-us/library/windows/desktop/ms633545(v=vs.85).aspx
  65. ShowWindow => http://msdn.microsoft.com/en-us/library/windows/desktop/ms633548(v=vs.85).aspx
  66. Setting WINVER or _WIN32_WINNT => http://msdn.microsoft.com/en-us/library/windows/desktop/aa383745(v=vs.85).aspx#setting_winver_or__win32_winnt
  67. ***/
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:4:21: fatal error: windows.h: No such file or directory
 #include <windows.h>
                     ^
compilation terminated.
stdout
Standard output is empty