|
-
June 18th, 2008, 10:31 PM
#1
EnumWindows and EnumChildWindows loop bringing up some strange results
I have an enumeration set up kind of like this (Its missing the code that actually does something, but you should get the point)
Code:
BOOL CALLBACK EW_Main (HWND hWnd, LPARAM lParam)
EnumChildWindows (hWnd, &EW_Main, (LPARAM) hWnd);
return true;
}
int main()
{
EnumWindows (&EW_Main, hWnd);
}
I wrote that into the box so excuse any errors but you should be able to figure out what I'm getting at.
My question is why EW_Main is being passed the same handle multiple times. Is it the way I've structured the enumeration?
Please tell me if I was too confusing, I'm not exactly sure how to explain this.
-
June 19th, 2008, 03:05 AM
#2
Re: EnumWindows and EnumChildWindows loop bringing up some strange results
What you have wrote is just fine. You pass the handle again to enumerate the children of the the new hwnd that it just found and does a dig until it finds the last hwnd that doesn't own anything and goes on. This is from my understanding. This is why you pass the function again, so you get the children of that hwnd sent to your Wm_Main . I don't know why you set your lparam to the hwnd, but I know what I would use it for 
Code:
#include <windows.h>
#include <iostream.h>
using namespace std;
BOOL CALLBACK EW_Main (HWND hWnd, LPARAM lParam){
int I = 0;
while( I < (int)lParam)
{
cout << " ";
I++;
}
cout << hWnd << endl;
EnumChildWindows( hWnd, &EW_Main, lParam + 1 );
Sleep(100);
return true;
}
int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow)
{
EnumWindows (&EW_Main, 0);
return 1;
}
I put a time delay with the sleep, so you can actually see the output. Anything else?
-
June 19th, 2008, 12:07 PM
#3
Re: EnumWindows and EnumChildWindows loop bringing up some strange results
I do know it works, the callback function is being passed the same window multiple times though, and I'm just trying to figure out why that is.
ANd I have the lParam set as the handle because I'm creating a list of bottom level windows, any window with a parent is discarded.
Thanks for your help
-
June 19th, 2008, 06:16 PM
#4
Re: EnumWindows and EnumChildWindows loop bringing up some strange results
Oh sorry. I misunderstood your post. I looked over the api again and found some information saying that the enumchildwindows will enumerate all windows that are children and their children, so you don't call it more than once per parent window. This is from http://www.softlookup.com/tutorial/vc++/vcu09fi.asp
EnumChildWindows. The EnumChildWindows function enumerates all child windows of a given window, identified by a handle that is supplied in the call to EnumChildWindows. The enumeration is accomplished by a user-defined callback function, the address of which is also supplied in the call to EnumChildWindows. This function also enumerates descendant windows; that is, child windows that are themselves children (or descendants) of child windows of the window specified in the call to EnumChildWindows.
One thing to note that microsoft has a remark for EnumWindows
The EnumWindows function does not enumerate child windows, with the exception of a few top-level windows owned by the system that have the WS_CHILD style.
ANd I have the lParam set as the handle because I'm creating a list of bottom level windows, any window with a parent is discarded.
You said you only wanted the the bottom level window(s). Are you referring to the main window or the children. Microsoft calls the Top level windows the parent with that exception.
If you only want the parent windows, Why call enumchildwindows.
Here is some code that may help.
Code:
#include <windows.h>
#include <iostream.h>
using namespace std;
BOOL CALLBACK EW_Main_Children (HWND hWnd, LPARAM lParam){
// gather here children
cout << " " << hWnd << endl;
}
BOOL CALLBACK EW_Main (HWND hWnd, LPARAM lParam){
//gather parent
cout << hWnd << endl;
//call for children
EnumChildWindows( hWnd, &EW_Main_Children, 0);
Sleep(10);
return true;
}
int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow)
{
EnumWindows (&EW_Main, 0);
return 1;
}
Did I understand you correctly? If not, I will try again.
-
June 22nd, 2008, 01:50 PM
#5
Re: EnumWindows and EnumChildWindows loop bringing up some strange results
Thanks! That was the problem. And I'm looking for a window that doesn't have any child windows, not necessarily top level. Thanks again!
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
|