Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 13th, 2008, 3:11 PM   #1
pcbrainbuster
Programmer
 
Join Date: Dec 2007
Posts: 93
Rep Power: 2 pcbrainbuster is on a distinguished road
Exclamation Going through all windows -

Sup guys,

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

Thanks.
pcbrainbuster is offline   Reply With Quote
Old Jan 13th, 2008, 10:44 PM   #2
Ancient Dragon
PFO God In Training
 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 653
Rep Power: 4 Ancient Dragon is on a distinguished road
Re: Going through all windows -

EnumWindows()
Ancient Dragon is offline   Reply With Quote
Old Jan 14th, 2008, 2:20 AM   #3
pcbrainbuster
Programmer
 
Join Date: Dec 2007
Posts: 93
Rep Power: 2 pcbrainbuster is on a distinguished road
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.
pcbrainbuster is offline   Reply With Quote
Old Jan 14th, 2008, 3:11 AM   #4
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,318
Rep Power: 5 grumpy will become famous soon enough
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, .....
grumpy is offline   Reply With Quote
Old Jan 14th, 2008, 1:29 PM   #5
pcbrainbuster
Programmer
 
Join Date: Dec 2007
Posts: 93
Rep Power: 2 pcbrainbuster is on a distinguished road
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.
pcbrainbuster is offline   Reply With Quote
Old Jan 15th, 2008, 2:06 AM   #6
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,318
Rep Power: 5 grumpy will become famous soon enough
Re: Going through all windows -

Quote:
Originally Posted by pcbrainbuster View Post
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++.
grumpy is offline   Reply With Quote
Old Jan 15th, 2008, 2:13 AM   #7
pcbrainbuster
Programmer
 
Join Date: Dec 2007
Posts: 93
Rep Power: 2 pcbrainbuster is on a distinguished road
Re: Going through all windows -

LOL :p, thanks for telling me that . But what about the main problem?

Thanks.
pcbrainbuster is offline   Reply With Quote
Old Jan 15th, 2008, 2:16 AM   #8
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,318
Rep Power: 5 grumpy will become famous soon enough
Re: Going through all windows -

The ingredients are in the posts above; you work it out.
__________________
Dear God
So far today I've done all right. I haven't been grumpy yet. But in a few minutes, God, I'm going to get out of bed, and from then on I'm going to need a lot more help.
AMEN
grumpy is offline   Reply With Quote
Old Jan 15th, 2008, 11:27 AM   #9
pcbrainbuster
Programmer
 
Join Date: Dec 2007
Posts: 93
Rep Power: 2 pcbrainbuster is on a distinguished road
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.
pcbrainbuster is offline   Reply With Quote
Old Jan 15th, 2008, 11:41 AM   #10
Wizard1988
Professional Programmer
 
Wizard1988's Avatar
 
Join Date: Oct 2005
Location: Chitown
Posts: 423
Rep Power: 4 Wizard1988 is on a distinguished road
Re: Going through all windows -

If you have Visual Studio I suggest you play around with Spy++
__________________

Wizard1988 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Typical Revisons from windows 2000 to windows xp ronaldr C++ 2 Nov 23rd, 2007 11:17 PM
looking for a good windows programming book cwl157 Coder's Corner Lounge 3 May 30th, 2007 7:51 AM
Search for and close open windows badbasser98 C++ 13 Feb 27th, 2006 1:04 PM
Windows Vista, well sort of coldDeath Coder's Corner Lounge 21 Sep 6th, 2005 2:00 PM
Net Group /ADD (on a windows box, non domain controller) Infinite Recursion Other Programming Languages 1 Apr 13th, 2005 3:27 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:31 PM.

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