如何从“FindWindow”函数指定的窗口中获取控件列表?例如,我有一个记事本窗口的句柄
HWND Window = FindWindow(L"Notepad", L"dummy.txt - Notepad");
然后我可以通过
HWND WindowEX = FindWindowEx(Window, NULL, L"EDIT", NULL);
但是如何获取控件的完整列表并将它们记录在数组中?
如何从“FindWindow”函数指定的窗口中获取控件列表?例如,我有一个记事本窗口的句柄
HWND Window = FindWindow(L"Notepad", L"dummy.txt - Notepad");
然后我可以通过
HWND WindowEX = FindWindowEx(Window, NULL, L"EDIT", NULL);
但是如何获取控件的完整列表并将它们记录在数组中?
我已经用旧方法完成了
array<HWND>^ childs = gcnew array<HWND>(1000);
array<String^>^ childsnames = gcnew array<String^>(1000);
int childcount = 0;
public:
delegate bool EnumDelegate(HWND hWnd, int lParam);
public:
[DllImport("user32.dll", EntryPoint = "EnumChildWindows", ExactSpelling = false, CharSet = CharSet::Unicode, SetLastError = true)]
static bool EnumChildWindows(HWND hwndParent, EnumDelegate ^lpEnumCallbackFunction, int lParam);
bool enumchildproc(HWND hWnd, int lParam)
{
int nLength = GetWindowTextLength(hWnd);
LPWSTR strbTitle = (LPWSTR)VirtualAlloc((LPVOID)NULL,
(DWORD)(nLength + 1), MEM_COMMIT,
PAGE_READWRITE);
//GetWindowText(hWnd, strbTitle, 255);
GetClassNameW(hWnd, strbTitle, 255);
String ^strTitle = gcnew String(strbTitle);
childs[childcount] = hWnd;
childsnames[childcount] = strTitle;
childcount++;
return true;
}
void refreshChilds(HWND Parent, ComboBox^ cb)
{
cb->Items->Clear();
childcount = 0;
int i = 0;
Array::Clear(childs, 0, 1000);
Array::Clear(childsnames, 0, 1000);
EnumDelegate ^filter = gcnew EnumDelegate(this, &MyForm::enumchildproc);
EnumChildWindows(Parent, filter, 0);
for (i = 0; i < childcount; i++)
{
cb->Items->Add(childsnames[i]);
}
}
refreshChilds() 函数将用子类名填充组合框。