Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Always on top?

Posted on 2004-09-20
2
Medium Priority
?
1,044 Views
Last Modified: 2006-11-17
Is there a way to set a console program to be "always on top" of other open windows?
0
Comment
Question by:fattumsdad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 12105264
Get the console's window handle like in http://support.microsoft.com/default.aspx?scid=kb;en-us;124103 ("How To Obtain a Console Window Handle")

   HWND GetConsoleHwnd(void)
   {
       #define MY_BUFSIZE 1024 // Buffer size for console window titles.
       HWND hwndFound;         // This is what is returned to the caller.
       char pszNewWindowTitle[MY_BUFSIZE]; // Contains fabricated
                                           // WindowTitle.
       char pszOldWindowTitle[MY_BUFSIZE]; // Contains original
                                           // WindowTitle.

       // Fetch current window title.

       GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE);

       // Format a "unique" NewWindowTitle.

       wsprintf(pszNewWindowTitle,"%d/%d",
                   GetTickCount(),
                   GetCurrentProcessId());

       // Change current window title.

       SetConsoleTitle(pszNewWindowTitle);

       // Ensure window title has been updated.

       Sleep(40);

       // Look for NewWindowTitle.

       hwndFound=FindWindow(NULL, pszNewWindowTitle);

       // Restore original window title.

       SetConsoleTitle(pszOldWindowTitle);

       return(hwndFound);
   }


and modify the window style

HWND hWnd = GetConsoleHwnd();
LONG lStyle = GetWindowLong ( hWnd, GWL_EXSTYLE);

lStyle |= WS_EX_TOPMOST; // add "WS_EX_TOPMOST"

SetWindowLong ( hWnd, GWL_EXSTYLE, lStyle);

That style bit is

"Specifies that a window created with this style should be placed above all non-topmost windows and should stay above them, even when the window is deactivated."
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 12105283
You may try that:

Find the window handle with:

   HWND hwnd = FindWindow("Command");

and make it topmost by

   RECT rect;
   GetWindowRect(hwnd, &rect);
   SetWindowPos(hwnd, HWND_TOPMOST,
                         rect.left, rect.right, rect.width(), rect.height(),
                         SWP_SHOWWINDOW);


Regards, Alex
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question