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. How can I make a modeless topmost for the desktop ?

How can I make a modeless topmost for the desktop ?

Scheduled Pinned Locked Moved C / C++ / MFC
questioncomhelp
6 Posts 4 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.
  • Y Offline
    Y Offline
    yarp
    wrote on last edited by
    #1

    I've got an application where I want a modeless dialog to stay on top of other applications. When I call SetWindowPos for the main window, this window stays on top of the others but when I try the same code for the modeless it just stay on top of its parent. The code is just basic SetWindowPos: SetWindowPos(m_hWnd, NULL, 0, 0, 0, 0, HWND_TOPMOST); Is there a trick or a way to make that modeless topmost ? or is it a problem from my program ? :) Yarp http://www.senosoft.com/

    I A S Y 4 Replies Last reply
    0
    • Y yarp

      I've got an application where I want a modeless dialog to stay on top of other applications. When I call SetWindowPos for the main window, this window stays on top of the others but when I try the same code for the modeless it just stay on top of its parent. The code is just basic SetWindowPos: SetWindowPos(m_hWnd, NULL, 0, 0, 0, 0, HWND_TOPMOST); Is there a trick or a way to make that modeless topmost ? or is it a problem from my program ? :) Yarp http://www.senosoft.com/

      I Offline
      I Offline
      Iain Clarke Warrior Programmer
      wrote on last edited by
      #2

      Just a guess, but you need to make the parent of your modeless dialog be the desktop, rather than your main window. You can se the *owner* of your dialog to be your main window... Iain.

      Y 1 Reply Last reply
      0
      • I Iain Clarke Warrior Programmer

        Just a guess, but you need to make the parent of your modeless dialog be the desktop, rather than your main window. You can se the *owner* of your dialog to be your main window... Iain.

        Y Offline
        Y Offline
        yarp
        wrote on last edited by
        #3

        Sure, this is a good idea. If I can't find a clean solution I will try this. Doesn't mean your solution is a dirty one, just looking for the perfect one if any ;) Yarp http://www.senosoft.com/

        1 Reply Last reply
        0
        • Y yarp

          I've got an application where I want a modeless dialog to stay on top of other applications. When I call SetWindowPos for the main window, this window stays on top of the others but when I try the same code for the modeless it just stay on top of its parent. The code is just basic SetWindowPos: SetWindowPos(m_hWnd, NULL, 0, 0, 0, 0, HWND_TOPMOST); Is there a trick or a way to make that modeless topmost ? or is it a problem from my program ? :) Yarp http://www.senosoft.com/

          A Offline
          A Offline
          Arman S
          wrote on last edited by
          #4

          Try SetForegroundWindow -- ====== Arman

          1 Reply Last reply
          0
          • Y yarp

            I've got an application where I want a modeless dialog to stay on top of other applications. When I call SetWindowPos for the main window, this window stays on top of the others but when I try the same code for the modeless it just stay on top of its parent. The code is just basic SetWindowPos: SetWindowPos(m_hWnd, NULL, 0, 0, 0, 0, HWND_TOPMOST); Is there a trick or a way to make that modeless topmost ? or is it a problem from my program ? :) Yarp http://www.senosoft.com/

            S Offline
            S Offline
            S Douglas
            wrote on last edited by
            #5

            yarp wrote:

            The code is just basic SetWindowPos: SetWindowPos(m_hWnd, NULL, 0, 0, 0, 0, HWND_TOPMOST); Is there a trick or a way to make that modeless topmost ?

            Try this instead. SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOSIZE); CWnd::SetWindowPos[^]


            DEBUGGING : Removing the needles from the haystack.

            1 Reply Last reply
            0
            • Y yarp

              I've got an application where I want a modeless dialog to stay on top of other applications. When I call SetWindowPos for the main window, this window stays on top of the others but when I try the same code for the modeless it just stay on top of its parent. The code is just basic SetWindowPos: SetWindowPos(m_hWnd, NULL, 0, 0, 0, 0, HWND_TOPMOST); Is there a trick or a way to make that modeless topmost ? or is it a problem from my program ? :) Yarp http://www.senosoft.com/

              Y Offline
              Y Offline
              yarp
              wrote on last edited by
              #6

              I found a solution as suggested by Iain. The other ways din't work: Here's the function that makes it : void CfrmImg::EnableStayOnTop(bool bDesktop) { // Desktop topmost if (bDesktop) { ::SetWindowLongPtr(m_hWnd, GWL_HWNDPARENT, NULL); ::SetWindowPos(m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); } // Application topmost else { if (::GetParent(m_hWnd)==NULL) ::SetWindowLongPtr(m_hWnd, GWL_HWNDPARENT, (LONG_PTR)frmMain->m_hWnd); ::SetWindowPos(m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); } } I recall this is for a modeless dialog - don't know if it makes sense for modals. The SetWindowLongPtr with GWL_HWNDPARENT parameter is a dirty hack. MSDN says SetParent should be used instead, but with SetParent it didn't work (I presume I have to change the windows style as suggested by MSDN - this is a later clean up work). At the moment I'm happy with my stay on top function. Thanks all for your assistance. Yarp http://www.senosoft.com/

              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