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 know if a window is above another

How know if a window is above another

Scheduled Pinned Locked Moved C / C++ / MFC
question
6 Posts 5 Posters 1 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
    Schehaider_Aymen
    wrote on last edited by
    #1

    I have 2 windows, let's say a FileZilla window and a Notepad Window. And I have the FileZilla window is on the top of the Notepad one (like cards; on above the other). I want to know how could I get the information that the FileZilla window is above the notepad's one ? I tried GetWindowLong But no chance.

    LONG wndState1 = ::GetWindowLong(handler1, GWL_EXSTYLE);

    LONG wndState2 = ::GetWindowLong(handler2, GWL_EXSTYLE);

    both results is equal to 256. Is there a trick for that ?

    "The Only Limit Is Only Your Imagination."

    R V L 3 Replies Last reply
    0
    • S Schehaider_Aymen

      I have 2 windows, let's say a FileZilla window and a Notepad Window. And I have the FileZilla window is on the top of the Notepad one (like cards; on above the other). I want to know how could I get the information that the FileZilla window is above the notepad's one ? I tried GetWindowLong But no chance.

      LONG wndState1 = ::GetWindowLong(handler1, GWL_EXSTYLE);

      LONG wndState2 = ::GetWindowLong(handler2, GWL_EXSTYLE);

      both results is equal to 256. Is there a trick for that ?

      "The Only Limit Is Only Your Imagination."

      R Offline
      R Offline
      Rick York
      wrote on last edited by
      #2

      Try calling EnumDesktopWindows. I think it will give the window handles in their z-order to the callback function. I am not sure about this though. It would be fairly easy to contrive a test app to experiment with it. You might find EnumWindows will do it also. Between the two you should be able to determine what you want. Once you get the window handles in their z order you will have to determine which window is which, likely by their titles.

      1 Reply Last reply
      0
      • S Schehaider_Aymen

        I have 2 windows, let's say a FileZilla window and a Notepad Window. And I have the FileZilla window is on the top of the Notepad one (like cards; on above the other). I want to know how could I get the information that the FileZilla window is above the notepad's one ? I tried GetWindowLong But no chance.

        LONG wndState1 = ::GetWindowLong(handler1, GWL_EXSTYLE);

        LONG wndState2 = ::GetWindowLong(handler2, GWL_EXSTYLE);

        both results is equal to 256. Is there a trick for that ?

        "The Only Limit Is Only Your Imagination."

        V Offline
        V Offline
        Victor Nijegorodov
        wrote on last edited by
        #3

        this discussion could also help: [c# - How to get the z-order in windows? - Stack Overflow](https://stackoverflow.com/questions/825595/how-to-get-the-z-order-in-windows)

        S 1 Reply Last reply
        0
        • V Victor Nijegorodov

          this discussion could also help: [c# - How to get the z-order in windows? - Stack Overflow](https://stackoverflow.com/questions/825595/how-to-get-the-z-order-in-windows)

          S Offline
          S Offline
          Schehaider_Aymen
          wrote on last edited by
          #4

          I need smthing that works with c++. :)

          "The Only Limit Is Only Your Imagination."

          Richard Andrew x64R 1 Reply Last reply
          0
          • S Schehaider_Aymen

            I need smthing that works with c++. :)

            "The Only Limit Is Only Your Imagination."

            Richard Andrew x64R Offline
            Richard Andrew x64R Offline
            Richard Andrew x64
            wrote on last edited by
            #5

            If you can do C++, then you can surely translate from C#. Especially since the functions you need to call are right in the code. :rolleyes:

            The difficult we do right away... ...the impossible takes slightly longer.

            1 Reply Last reply
            0
            • S Schehaider_Aymen

              I have 2 windows, let's say a FileZilla window and a Notepad Window. And I have the FileZilla window is on the top of the Notepad one (like cards; on above the other). I want to know how could I get the information that the FileZilla window is above the notepad's one ? I tried GetWindowLong But no chance.

              LONG wndState1 = ::GetWindowLong(handler1, GWL_EXSTYLE);

              LONG wndState2 = ::GetWindowLong(handler2, GWL_EXSTYLE);

              both results is equal to 256. Is there a trick for that ?

              "The Only Limit Is Only Your Imagination."

              L Offline
              L Offline
              leon de boer
              wrote on last edited by
              #6

              Windows API has the function GetTopWindow GetTopWindow function (Windows)[^] From the TopWindow you want walk down thru the chain via GetNextWindow GetNextWindow function (Windows)[^] So in your case you want to ask the topWindow of the window that contains both FileZilla window and a Notepad Window. You can then walk along the chain using GetNextWindow and see which is above which just by asking the window title. Something like this will work

              char buf[256];
              HWND Wnd = GetTopWindow( /*handle of window containing both*/ );
              GetWindowText(Wnd, &buf[0], sizeof(buf));
              while (Wnd != 0 && !stricmp(&buf[0], "FileZilla") && !stricmp(&buf[0], "NotePad"))
              {
              Wnd = GetNextWindow(Wnd, GW_HWNDNEXT); // Next window
              GetWindowText(Wnd, &buf[0], sizeof(buf)); // Get it's title
              }
              if (Wnd == 0) {
              /* Error neither window found */
              }
              else {
              /* Wnd is the topmost of 2 windows title and the string title is in buf */
              }

              It is equivalent to EnumChildWindows function (Windows)[^] However for the simplicity you have it isn't worth setting up the enumeration function.

              In vino veritas

              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