Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   Going through all windows - (http://www.programmingforums.org/showthread.php?t=14936)

pcbrainbuster Jan 13th, 2008 3:11 PM

Going through all windows -
 
Sup guys,

Is there any function that retrieves the handles to all visible windows on screen(not including controls)?

Thanks.

Ancient Dragon Jan 13th, 2008 10:44 PM

Re: Going through all windows -
 
EnumWindows()

pcbrainbuster Jan 14th, 2008 2:20 AM

Re: Going through all windows -
 
I did try to use that function but for some reason I came up with an outrageous number like 272. I am sure that there aren't that many visible windows on my screen :) Any ideas?

Thanks.

grumpy Jan 14th, 2008 3:11 AM

Re: Going through all windows -
 
EnumWindows() tends to be pretty reliable with picking up windows on the screen -- and it picks up ALL windows, whether visible or not. The issue is probably that your definition of "window" is somewhat more limited that the one used by the OS -- a window is just a particular type of system resource.

Several system applications (and even the odd background service, which sometimes needs to communicate with the user) have windows that are invisible until they are needed. Some things that are also routinely on the desktop are actually windows even if they don't look like a window: examples include the task bar, each icon in the notification area of the taskbar, the start menu, toolbars, the desktop itself, .....

pcbrainbuster Jan 14th, 2008 1:29 PM

Re: Going through all windows -
 
Thanks for that reply! But the thing is that I in fact am aware of that :) Is there any way to use that function to pick up JUST TOP LEVEL windows?

I'm not sure that your aware of this(not that many people are) but as far as I know a top level window is a window the has the WS_OVERLAPPED or WS_OVERLAPPEDWINDOW styles.

Please reply even if you don't know how to do this(because this is really important to me and I need to know if you know. :)

Thanks.

grumpy Jan 15th, 2008 2:06 AM

Re: Going through all windows -
 
Quote:

Originally Posted by pcbrainbuster (Post 139626)
I'm not sure that your aware of this(not that many people are) but as far as I know a top level window is a window the has the WS_OVERLAPPED or WS_OVERLAPPEDWINDOW styles.

Please reply even if you don't know how to do this(because this is really important to me and I need to know if you know. :)

Well, you've demonstrated that you don't know what a top level window is.

A top-level window is one that has no parent (eg GetParent() will return NULL). It has nothing to do with the WS_OVERLAPPED style.

WS_OVERLAPPED is a style commonly used by applications for their main window. WS_OVERLAPPEDWINDOW is a combination of that style with some other common ones (so it has a caption, maximize button, etc etc). However, it is not mandatory that applications use these styles

To check if a window has the a particular bit set do this;
:

int window_has_style = (GetWindowLong(window, GWL_STYLE) & style_bit);
For example, to check is a window is visible, style_bit would have the value WS_VISIBLE (and the above is functionally equivalent to calling IsWindowVisible(window)). Similarly, to check for the overlapped style, use the value WS_OVERLAPPED.

And, to nag mods again, this is win32 API stuff that (except for the code example which is C) works in any language under windows operating systems. It has nothing to do with C++.

pcbrainbuster Jan 15th, 2008 2:13 AM

Re: Going through all windows -
 
LOL :p, thanks for telling me that :). But what about the main problem?

Thanks.

grumpy Jan 15th, 2008 2:16 AM

Re: Going through all windows -
 
The ingredients are in the posts above; you work it out.

pcbrainbuster Jan 15th, 2008 11:27 AM

Re: Going through all windows -
 
Hmm, actually you gave me an idea. I could use EnumWindows(...) to enumarate all windows then can check to see if the current window in the enumaration function has the styles WS_VISIBLE and possibly WS_OVERLAPPED/WINDOW and then store the handles in a HWND vector for later use.

There is just two questions remaining -

1) First of all how can I stop the enumaration when all windows have been processed? Because to my understanding it keeps on going.
2) And last, is a folder window a top level one?

Thanks.

Wizard1988 Jan 15th, 2008 11:41 AM

Re: Going through all windows -
 
If you have Visual Studio I suggest you play around with Spy++


All times are GMT -5. The time now is 3:40 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC