How to get list of open application (i don't think proces).
Printable View
How to get list of open application (i don't think proces).
If you want to get all open windows ..use EnumWindows.
It will return you the handle to all top level windows
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.
Regards,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);
}
Pravin.
Bad code.Quote:
Originally Posted by Pravin Kumar
Always use EnumWindows()
What is "bad" about this code?Quote:
Originally Posted by fred100
Why? :confused:Quote:
Originally Posted by fred100
I could only guess what fred100 had in mind. And my guess is - this comment from MSDN:Quote:
Originally Posted by JohnCz
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.
Possibly...Quote:
Originally Posted by VladimirF
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.
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.Quote:
Originally Posted by JohnCz
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...