【发布时间】:2012-06-15 15:50:45
【问题描述】:
我正在开发一个小程序,以便在使用 Microsoft 远程协助 (msra.exe) 时让我的生活更轻松。使用 c++,我可以打开 msra.exe,然后找到窗口句柄。然后我想找到子窗口(按钮),并与它们进行交互。问题似乎是,我找不到我想要的按钮。 Spy++ 显示按钮有这个文本:
Window 004902F4“邀请您信任的人帮助您”按钮。
我的程序在搜索此字符串时返回该按钮不存在。有人有想法么?代码如下:
#include "stdafx.h"
#include <windows.h>
#include <string>
#include <sys/types.h>
#include <stdlib.h>
#include <Windows.h>
#include <process.h>
using std::string;
void openRA(void * dummy);
int _tmain(int argc, _TCHAR* argv[])
{
_beginthread(openRA, 0, NULL);
Sleep(1000);
HWND handle = NULL;
handle = FindWindow(NULL, TEXT("Windows Remote Assistance"));
if(handle == NULL){
printf("handle was null\n");
}
else{
printf("handle was not null\n");
}
HWND button1 = NULL;
Sleep(1000);
button1 = FindWindowEx(handle, 0, 0, TEXT("Invite someone you trust to help you"));
if(button1 == NULL){
printf("Button1 was null");
}
else{
printf("I found he button!");
}
fflush(stdout);
return 0;
}
void openRA( void * dummy){
printf("I'm inside this function\n");
system("msra.exe &");
}
编辑:
这是 spy++ 显示的图像。
【问题讨论】:
-
我在多个窗口中遇到了这个确切的问题。事实证明,使用您看到的数字句柄是可行的,但这当然不是一个非常长期的解决方案。我想知道是什么让 Spy++ 能够找到他们,而不是我们。
-
FindWindowEx()不会递归扫描所有后代控件。您确定按钮是主框架的直接子级吗? -
@FrédéricHamidi,我绝对确定我尝试过的一些是直子。
-
你知道如何使用数字句柄吗?当我尝试 TEXT("004902F4") 时,它似乎没有找到它。
-
我怎么知道它是否是主框架的直接子框架?它与 Windows Remote Assistence 位于同一线程中。