E.g。我有一个名为“S1Window”的窗口,它有控件(静态文本,登录框等)
我需要一个登录框的句柄
我试过
BOOL CALLBACK EnumChilds(HWND hwnd, LPARAM lParam)
{
char class_name[80];
char title[80];
GetClassName(hwnd, class_name, sizeof(class_name));
GetWindowText(hwnd, title, sizeof(title));
std::cout << "Window title: " << title << std::endl;
std::cout << "Class name: " << class_name << std::endl << std::endl;
return TRUE;
}
int _tmain(int argc, _TCHAR* argv[])
{
HWND hnd= FindWindowA("", "S1Window");
EnumChildWindows(hnd, EnumChilds, 0);
}
但是我打开了所有窗户
答案 0 :(得分:2)
实际上,您应该将NULL作为lpClassName参数而不是空字符串传递。试试这个:
int _tmain(int argc, _TCHAR* argv[])
{
HWND hnd = FindWindowA( NULL, "S1Window" );
if( hnd == NULL ) {
return 1;
}
EnumChildWindows( hnd, EnumChilds, 0 );
return 0;
}