-
April 25th, 2008, 04:41 AM
#1
Get all open window
How to get list of open application (i don't think proces).
-
April 25th, 2008, 04:47 AM
#2
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
-
April 25th, 2008, 05:23 AM
#3
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.
-
April 25th, 2008, 08:37 AM
#4
Re: Get all open window
Originally Posted by Pravin Kumar
For example, the code given below will get all the windows open on desktop.
Bad code.
Always use EnumWindows()
-
April 26th, 2008, 10:10 AM
#5
Re: Get all open window
Originally Posted by fred100
Bad code.
What is "bad" about this code?
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.
-
April 26th, 2008, 11:56 AM
#6
Re: Get all open window
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...
-
April 26th, 2008, 01:53 PM
#7
Re: Get all open window
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.
-
April 26th, 2008, 04:49 PM
#8
Re: Get all open window
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|