CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Apr 2008
    Posts
    21

    Get all open window

    How to get list of open application (i don't think proces).

  2. #2
    Join Date
    Apr 2008
    Posts
    133

    Re: Get all open window

    If you want to get all open windows ..use EnumWindows.
    It will return you the handle to all top level windows

  3. #3
    Join Date
    Feb 2000
    Location
    Indore, India
    Posts
    1,046

    Re: Get all open window

    Hello,

    You can use FindWindow call to get windows of whatever type of relation to the specified window.

    For example, the code given below will get all the windows open on desktop.

    Code:
    // Get the topmost window in Z order
    HWND hWnd = GetWindow(hwnd, GW_HWNDFIRST);
    while (hWnd != NULL)		// If the window handle is valid
    {
    	if (IsWindowVisible(hWnd))	// If the window is visible
    	{
    		// Get window details and process info
    		...
    	}
    	// Loops through all windows
    	hWnd = GetWindow(hWnd, GW_HWNDNEXT);
    }
    Regards,
    Pravin.
    Let me know if I have helped by rating this post

    Recent FAQs

    Drag an image
    Area of a window exposed on desktop
    Display rotated bitmap

  4. #4
    Join Date
    Jan 2008
    Posts
    178

    Re: Get all open window

    Quote Originally Posted by Pravin Kumar
    For example, the code given below will get all the windows open on desktop.
    Bad code.
    Always use EnumWindows()

  5. #5
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: Get all open window

    Quote Originally Posted by fred100
    Bad code.
    What is "bad" about this code?

    Quote Originally Posted by fred100
    Always use EnumWindows()
    Why?
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  6. #6
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Get all open window

    Quote Originally Posted by JohnCz
    What is "bad" about this code?

    Why?
    I could only guess what fred100 had in mind. And my guess is - this comment from MSDN:

    EnumWindows Function

    Remarks

    ...This function is more reliable than calling the GetWindow function in a loop. An application that calls GetWindow to perform this task risks being caught in an infinite loop or referencing a handle to a window that has been destroyed.
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  7. #7
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: Get all open window

    Quote Originally Posted by VladimirF
    I could only guess what fred100 had in mind. And my guess is - this comment from MSDN:
    Possibly...

    Well, it is always possible to shoot yourself in a foot.
    Using EnumWindows can also lead to a potential return of window handle after is destroyed.
    IsWindow is good to check it.

    I take, Pravin Kumar snippet is just demonstrating one of possible approaches. I really do not see anything wrong with this code and there is no reason to call it "bad".
    Unless of course we have misses something else.
    Last edited by JohnCz; April 26th, 2008 at 05:53 PM.
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  8. #8
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Get all open window

    Quote Originally Posted by JohnCz
    ...Unless of course we have misses something else.
    GetWindow() gets you the next window in the Z-order; that order might change between your calls, either missing some windows or returning to windows you already visited before.
    EnumWindows takes a snapshot and goes through it. Of course, you might want to check if the window still exist by the time you get to process it...
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured