I used EnumChildWindows
and I can get the Handle
, ClassName
and WindowText
of all the child windows. But I also want to get all the child windows' Rectangle
. Is it possible?
This is my code:
#include <iostream>
#include <windows.h>
using namespace std;
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
char class_name[100];
char title[100];
GetClassNameA(hwnd,class_name, sizeof(class_name));
GetWindowTextA(hwnd,title,sizeof(title));
cout <<"Window name : "<<title<<endl;
cout <<"Class name : "<<class_name<<endl;
cout <<"hwnd : "<<hwnd<<endl<<endl;
return TRUE;
}
int main()
{
POINT pt;
Sleep(3000);
GetCursorPos(&pt);
HWND hwnd = WindowFromPoint(pt);
HWND hwndParent = GetParent(hwnd);
EnumChildWindows(hwndParent,EnumWindowsProc,0);
system("PAUSE");
return 0;
}
Also, how can I stored all the data (handle,classname,windowtext,rectangle) of each child windows? Maybe in a vector list?
For your first question, you may have a look here.
For your second question, you may define a structure with the fields you need, e.g.
EDIT
I added a bit more code and explanation. This example should compile and run just fine.
std::vector
is a sequence container that encapsulates dynamic size arrays 1.When you declare
myChildWindows
in the main function, it is initialized to an empty vector, that can contain Objects of TypeMyWindow
. You can add and remove objects to that vector dynamically, i.e. you do not have to specify the size of the vector at compile time, like for example with an array. We then pass the pointer to this vector to your callbackEnumWindowsProc
. In this callback, we use this pointer to add Objects of typeMyWindow
to the vector. WhenEnumChildWindows
returns, we can have a look at our vector by printing every object contained in the vector.