Enum Windows, finding only parent of a child window?

Sorry for the confusing title! , Ok I have a window that has about 20 windows that come from that, of that 20 only one of them has child windows , 3 of them (and that's the one I actually want).

Spy++ has no captions for any of these windows and the handles of the children change everytime the main window is opened. So I am looking for a way to say "Enumerate all children of this window that has children itself and then store that handle". Is this possible :) ?
Last edited on
You will want the EnumWindows API function. Documentation is here:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633497(v=vs.85).aspx

But try looking at examples first, because they are generally more helpful than the documentation. Some examples:
http://simplesamples.info/Windows/EnumWindows.html
http://www.cplusplus.com/forum/windows/25280/
http://www.dreamincode.net/forums/topic/217257-enumerating-windows/

In your case you would want an EnumWindowsProc that counts the number of children windows. And then another EnumWindowsProc that calls the counting proc for all 20 of the windows you mentioned in your post.
Let me know if this helps :)
Thanks for the reply!

Ok It seems to be just returning the caption of a specified window rather than the windows/controls attached to each? Is there an easy way to loop through all windows or controls attached to each window? and display them line by line and from that I guess I would try to find which one of those hand child windows/controls attached to it?

Edit. I will try to be more helpful.

1
2
3
4
5
6
7
8
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) 
{
	TCHAR buffer[512];
	SendMessage(hwnd, WM_GETTEXT, sizeof(buffer), (LPARAM)(void*)buffer);
	std::cout << buffer << std::endl;

	return TRUE;
}



1
2
3
4
int main ()
{
    EnumWindowsProc(Lobbys, 0);
}


So instead of the SendMessage(hwnd, WM_GETTEXT, sizeof(buffer), (LPARAM)(void*)buffer); GETTEXT grabbing the text of the window I specifiy I wonder if I can get it to list all controls off of it?
Last edited on
EnumWindowsProc function pointers are meant to be passed to EnumWindows. You seem to be calling one by itself in your main function. What you want to do instead is call EnumWindows and pass a function pointer to an EnumWindowsProc function. This might seem a little confusing, but EnumWindowsProc is actually a function type. Kind of like int is a type of data variable. EnumWindows is a function in the Windows API that can accept a pointer to a function that has the EnumWindowsProc type.

EnumWindowsProcA could count the number of child windows
EnumWindowsProcB could return success if it finds a window with 3 children

Then in main call EnumWindows with the hwnd to the window that holds 20 windows and the EnumWindowsProcB pointer.
In EnumWindowsProcB call EnumWindows with the EnumWindowsProcA pointer and if you get 3 return a success to main somehow.

So basically:
Loop through all the child windows by calling another EnumWindows instead of calling cout to display the window's title.
Last edited on
Topic archived. No new replies allowed.