Qt通过句柄获取其它进程控件实例

1.通过spy++获取想要获取控件的句柄id
通过spy++获取另一个软件的文本框的句柄通过spy++获取另一个软件的文本框的id

2.Qt写代码,

根据句柄获取文本框的内容

void getTextFromExternalWindow(HWND hwnd)
{
    const int bufferSize = 256;
    TCHAR buffer[bufferSize];

    // 获取窗口文本内容
    int length = GetWindowText(hwnd, buffer, bufferSize);

    if (length > 0)
    {
        QString text = QString::fromWCharArray(buffer);
        qDebug() << "Text from external window:" << text;
    }
    else
    {
        qDebug() << "Failed to get text from external window.";
    }
}

通过WindowsAPI查找窗口,然后查找子窗口,然后输入获取的文本框句柄,需要user32.dll

#include <windows.h>
    HWND hwnd = FindWindow(nullptr, L"Control Center Series 30");
    
    if (hwnd != nullptr)
    {
        HWND hwndChild = FindWindowEx(hwnd, NULL,NULL,  L"Devices");  // 获取子窗口句柄
        if (hwndChild == NULL) {
            qDebug() << "Child window not found!\n";
            return 1;
        }
        
        
        // 假设你有一个句柄的数值
        intptr_t handleValue = 0x006F044A;  // 这里假设句柄值为 00020574,实际情况下会根据具体需求修改auto (250)
        
        // 将句柄数值转换为 HWND 类型
        HWND hwnd1 = reinterpret_cast<HWND>(handleValue);
        
        getTextFromExternalWindow(hwnd1);
    }
    else
    {
        qDebug() << "External window not found.";
    }

3.输出结果
运行结果

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值