gpt4 book ai didi

c++ - 无法使用 FindWindowEx 函数找到子窗口

转载 作者:搜寻专家 更新时间:2023-10-31 01:53:32 26 4
gpt4 key购买 nike

我正在开发一个小程序,以便在使用 Microsoft 远程协助 (msra.exe) 时让我的生活更轻松。使用 C++,我可以打开 msra.exe,然后找到窗口句柄。然后我想找到子窗口(按钮),并与它们交互。问题似乎是,我找不到我想要的按钮。 Spy++ 显示按钮具有以下文本:

窗口 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++ Image

最佳答案

顶级窗口的标题为“Windows 远程协助”。这是 FindWindow 返回的窗口。

这包含一个嵌入式对话框,该对话框还具有标题“Windows 远程协助”并包含您感兴趣的按钮。

该按钮不是顶级窗口的直接子级,因此 FindWindowEx 找不到它。

使用 EnumChildWindows 递归枚举顶级窗口的所有子窗口并自行检查标题。

关于c++ - 无法使用 FindWindowEx 函数找到子窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11054134/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com