Virtual Developer Workshop: Containerized Development with Docker

Sample Image

Making a window visible always even if it's not the active window is very easy all you have to do is to enable "system modal" style in the window properties. But making a Dialog, SDI/MDI base application visible always at runtime requires more than just enabling some properties.

This article is for developers who want their Dialog, SDI/ MDI base application to be always be visible even if it is not the active window.

I've been working on an application, which can make itself always visible, as desired by the user . I tried to find an article in codeguru that will solve the problem but I didn't found one. so after an hour of research I've came up with this code hope you'll find it useful as I did.

Its very easy to do, for dialog base applications all you have to do is to add this method to your dialog:

void CTopDlgDemoDlg::StayOnTop() const
 CRect rect;

 // get the current window size and position
 GetWindowRect( rect );

 // now change the size, position, and Z order 
 // of the window.
 ::SetWindowPos(m_hWnd ,       // handle to window
                HWND_TOPMOST,  // placement-order handle
                rect.left,     // horizontal position
                rect.top,      // vertical position
                rect.Width(),  // width
                rect.Height(), // height
                SWP_SHOWWINDOW // window-positioning options);

// add a control button and command handler for the button to your dialog.
// then invoke StayOnTop().
void CTopDlgDemoDlg::OnBtnClick() 
 // make this dialog always on top.

You can also use this method in SDI/MDI base applications; just add the same method in your CMainFrame class and invoke it!

void CMainFrame::OnViewMaketop() 
 // make this window always on top.


Download demo project - 12 Kb


  • the way to implement but do not need to get the current window size and position

    Posted by darena on 05/16/2006 06:01am

    ::SetWindowPos(m_hWnd ,       // handle to window
                    HWND_TOPMOST,  // placement-order handle
                    0,     // horizontal position
                    0,      // vertical position
                    0,  // width
                    0, // height
                    SWP_NOMOVE|SWP_NOSIZE // window-positioning options);

  • Good !

    Posted by kapildev on 04/24/2006 07:08am

    Nice finding !

  • How can i....

    Posted by jimmymjoy on 03/11/2004 08:26am

    Is it possible to create a window which stays always on the top and it should be actve always. In this case when i click some other applications which is already opened, the focus of the window is lost. ie no other application should not work while this active window is there including the windows key. thankx jim

  • Can this be restricted to a application ?

    Posted by Legacy on 01/22/2004 08:00am

    Originally posted by: Ajit

    Is there any way to restrict a dialog box to be "Always on Top" only for its parent application and not for whole system ? It will be something like "property pages". But I want it for the dialog box.

  • good!

    Posted by Legacy on 10/11/2003 07:00am

    Originally posted by: LinGuang

    thank you!

  • It wont work >.< (im newb)

    Posted by Legacy on 10/02/2003 07:00am

    Originally posted by: Brandon

    hey ya that code dont work for me i dont know why (as i just started taking a class few weaks ago, only in highschool) but at home i like to mes around, and like i was wondering like wats the script to make my dialog alwas on top (without having to click a button). Also the name of my dialog is: DisableClose so like if u can replace the name of like the C(wateveryourprogramis) cuz im newb >.<

  • Always on top with Flash?

    Posted by Legacy on 06/18/2003 07:00am

    Originally posted by: Claudia Azor�n

    Hi, how can I do an always on top window with Flash (Remoting MX or ColdFusion), it's possible?
    Or with JSP? I have to do that the content of a tutorial runs in an always on top window, like in the book serie Dr. Max? Do you know it?

    Thank's you very much! :)

  • ok so how do i...

    Posted by Legacy on 09/09/2002 07:00am

    Originally posted by: david rush

    ...create an app/dialog which is never on top?

  • Where can get the rsource.rc file ?

    Posted by Legacy on 07/16/2002 07:00am

    Originally posted by: jacky.xue

    Sorry i just can't find this file .Would you show me how to get this file ,or create my myself ?

  • Always On Top

    Posted by Legacy on 03/21/2002 08:00am

    Originally posted by: joby

    how to do this one in SDK..

  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date