Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Force window on top

Force window on top

Scheduled Pinned Locked Moved C / C++ / MFC
question
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Shay Harel
    wrote on last edited by
    #1

    Hi, I wrote an application that has to warn a user of a certain state. I want to make sure the user sees my window. How do a I force it to be always on top of all other applications running ? This window is a simple CDialog derived window. Thanks in advance, Shay

    D 1 Reply Last reply
    0
    • S Shay Harel

      Hi, I wrote an application that has to warn a user of a certain state. I want to make sure the user sees my window. How do a I force it to be always on top of all other applications running ? This window is a simple CDialog derived window. Thanks in advance, Shay

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Does SetWindowPos() or BringWindowToTop() work for you?


      "Take only what you need and leave the land as you found it." - Native American Proverb

      S 1 Reply Last reply
      0
      • D David Crow

        Does SetWindowPos() or BringWindowToTop() work for you?


        "Take only what you need and leave the land as you found it." - Native American Proverb

        S Offline
        S Offline
        Shay Harel
        wrote on last edited by
        #3

        Almost there.... I want to force it on top of all windows and SetWindowPost seems to do the best work. However, I need a way to get the exact size of the bottom right corner. This code is crashing for me: LPRECT lpRect; this->GetWindowRect(lpRect); this->SetWindowPos(&CWnd::wndTopMost,10,10,lpRect->right,lpRect->bottom,SWP_SHOWWINDOW);

        D B 2 Replies Last reply
        0
        • S Shay Harel

          Almost there.... I want to force it on top of all windows and SetWindowPost seems to do the best work. However, I need a way to get the exact size of the bottom right corner. This code is crashing for me: LPRECT lpRect; this->GetWindowRect(lpRect); this->SetWindowPos(&CWnd::wndTopMost,10,10,lpRect->right,lpRect->bottom,SWP_SHOWWINDOW);

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          Shay Harel wrote:

          LPRECT lpRect;

          Change to: RECT Rect;


          "Take only what you need and leave the land as you found it." - Native American Proverb

          S 1 Reply Last reply
          0
          • D David Crow

            Shay Harel wrote:

            LPRECT lpRect;

            Change to: RECT Rect;


            "Take only what you need and leave the land as you found it." - Native American Proverb

            S Offline
            S Offline
            Shay Harel
            wrote on last edited by
            #5

            this one worked, thanks !

            1 Reply Last reply
            0
            • S Shay Harel

              Almost there.... I want to force it on top of all windows and SetWindowPost seems to do the best work. However, I need a way to get the exact size of the bottom right corner. This code is crashing for me: LPRECT lpRect; this->GetWindowRect(lpRect); this->SetWindowPos(&CWnd::wndTopMost,10,10,lpRect->right,lpRect->bottom,SWP_SHOWWINDOW);

              B Offline
              B Offline
              Blake Miller
              wrote on last edited by
              #6

              Also, you could be seriously jacking up your window position, if it is already positioned near the upper left corner with only a little bit of the lower right corner showing. I strongly recommend something like: this->SetWindowPos( &CWnd::wndTopMost,10,10, Rect.right - Rect.left, // its width Rect.bottom - Rect.Top, // its height SWP_SHOWWINDOW); Or even this->SetWindowPos( &CWnd::wndTopMost,10,10, max(Rect.right - Rect.left, 100), // its width max(Rect.bottom - Rect.Top, 100), // its height SWP_SHOWWINDOW); If you are REALLY paranoid, like me :omg:

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups