如何从窗口获得控件列表,由"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]);
}
}
refreshchildren()函数将用孩子的类名填充组合框。