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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Number of top level windows open

Number of top level windows open

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
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.
  • H Offline
    H Offline
    heman154
    wrote on last edited by
    #1

    Does anyone know how to find the number of windows open at a given time? I've looked into enumwindows and the find/get window functions, but there must be a way to just ask the window manager for this piece of information without having to iterate through all the windows. Thanks, ~Himanshu

    D 1 Reply Last reply
    0
    • H heman154

      Does anyone know how to find the number of windows open at a given time? I've looked into enumwindows and the find/get window functions, but there must be a way to just ask the window manager for this piece of information without having to iterate through all the windows. Thanks, ~Himanshu

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

      What's wrong with:

      BOOL CALLBACK EnumProc( HWND hwnd, LPARAM lParam )
      {
      PUINT puCount = (PUINT) lParam;

      (\*puCount)++;
      
      return TRUE;
      

      }

      UINT uCount = 0;
      EnumWindows(EnumProc, (LPARAM) &uCount);
      TRACE(_T("The numer of top-level windows is: %u\n"), uCount);


      "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

      T 1 Reply Last reply
      0
      • D David Crow

        What's wrong with:

        BOOL CALLBACK EnumProc( HWND hwnd, LPARAM lParam )
        {
        PUINT puCount = (PUINT) lParam;

        (\*puCount)++;
        
        return TRUE;
        

        }

        UINT uCount = 0;
        EnumWindows(EnumProc, (LPARAM) &uCount);
        TRACE(_T("The numer of top-level windows is: %u\n"), uCount);


        "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

        T Offline
        T Offline
        Toby Opferman
        wrote on last edited by
        #3

        I don't think there is a way to just get the count aside from the enumeration API. However, you must make one distinction. Do you want: a) ALL windows on the system? b) ALL _VISIBLE_ windows on the system (There are a lot of windows on the system that are not visible)? c) ALL _TOP LEVEL_ windows on the system? There is also the question of do you want to include each little component such as each button, edit box, system tray, the desktop icons (progman), the task bar, etc. etc. etc. because all those little details get enumerated. All controls, etc. Depending on what you are looking for would determine how you write the counting code to exclude and include the correct windows when you enumerate. There is also "EnumChildWindows" which may need to be called on each top level enumerated window if you don't want just top level windows. 8bc7c0ec02c0e404c0cc0680f7018827ebee

        D 1 Reply Last reply
        0
        • T Toby Opferman

          I don't think there is a way to just get the count aside from the enumeration API. However, you must make one distinction. Do you want: a) ALL windows on the system? b) ALL _VISIBLE_ windows on the system (There are a lot of windows on the system that are not visible)? c) ALL _TOP LEVEL_ windows on the system? There is also the question of do you want to include each little component such as each button, edit box, system tray, the desktop icons (progman), the task bar, etc. etc. etc. because all those little details get enumerated. All controls, etc. Depending on what you are looking for would determine how you write the counting code to exclude and include the correct windows when you enumerate. There is also "EnumChildWindows" which may need to be called on each top level enumerated window if you don't want just top level windows. 8bc7c0ec02c0e404c0cc0680f7018827ebee

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

          Toby Opferman wrote: c) ALL _TOP LEVEL_ windows on the system? "Top level windows" were specifically asked for in the subject.


          "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

          T 1 Reply Last reply
          0
          • D David Crow

            Toby Opferman wrote: c) ALL _TOP LEVEL_ windows on the system? "Top level windows" were specifically asked for in the subject.


            "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

            T Offline
            T Offline
            Toby Opferman
            wrote on last edited by
            #5

            Ok, He'll need to filter out the invisible windows, task bar, prog man and the system tray. 8bc7c0ec02c0e404c0cc0680f7018827ebee

            T 1 Reply Last reply
            0
            • T Toby Opferman

              Ok, He'll need to filter out the invisible windows, task bar, prog man and the system tray. 8bc7c0ec02c0e404c0cc0680f7018827ebee

              T Offline
              T Offline
              Toby Opferman
              wrote on last edited by
              #6

              That's if he doesn't want those, he needs to figure out if he really does want all the top level windows or only ones seen by the task bar (which then he would need to fitler things like side tool bars), etc. 8bc7c0ec02c0e404c0cc0680f7018827ebee

              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