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. Detecting whether a window is topmost

Detecting whether a window is topmost

Scheduled Pinned Locked Moved C / C++ / MFC
question
3 Posts 2 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
    Shree
    wrote on last edited by
    #1

    How can I determine whether a window on the desktop is a topmost window or not. I need to bring a window momentarily to the top (with HWND_TOPMOST), and then to restore it back to the position it was. I can use GetWindow(hWnd, HWND_RREV) to determine the previous window, and use this handle in SetWindowPos(). But since I have altered the TOPMOST position, how do I restore it?

    D 1 Reply Last reply
    0
    • S Shree

      How can I determine whether a window on the desktop is a topmost window or not. I need to bring a window momentarily to the top (with HWND_TOPMOST), and then to restore it back to the position it was. I can use GetWindow(hWnd, HWND_RREV) to determine the previous window, and use this handle in SetWindowPos(). But since I have altered the TOPMOST position, how do I restore it?

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

      Would GetForegroundWindow() be of any use?


      "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

      S 1 Reply Last reply
      0
      • D David Crow

        Would GetForegroundWindow() be of any use?


        "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

        S Offline
        S Offline
        Shree
        wrote on last edited by
        #3

        The window might be topmost, but not on the foreground. For example, We can set MSN to Always on top, and the task manager, which is always on top. Both of these are topmost windows, but any of them could be in the foreground. The following line solved the problem: bool isTopmost = GetWindowLong(hWnd, GWL_EXSTYLE) & WS_EX_TOPMOST

        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