如何使用Windows API鼠标挂钩中的UIAutomation元素了解元素信息

问题描述

在程序中,当我将鼠标悬停时,我想了解有关该元素的一些信息,到目前为止,我已经能够获得该元素的名称。

但是我也想知道它

  1. 本地化控件类型
    自动化ID

    IsInvokePatternAvailable

    IsSelectionItemPatternAvailiable

    IsTogglePatternAvailiable。

关于元素我该怎么做?

Inspect tool

这是我到目前为止拥有的代码,可以帮助我获取元素的名称

#include "mainwindow.h"
#include "common.h"
#include <fstream>
#include "XMLParser.h"
#include "ExecutionContext.h"
#include "UIAElementUtils.h"
#include "BlockCommand.h"
#include <ShellScalingAPI.h>
#include <conio.h>
#include <thread>
#include<qthread.h>
#include <qdebug.h>

ExecutionContext gExecutionContext;

#include <QtWidgets/qapplication.h>  
//used to handle widgets,event handling,mouse movements,overall look and feel

BOOL InitializeUIAutomation(IUIAutomation** automation)
{
    CoInitialize(NULL);
    HRESULT hr = CoCreateInstance(__uuidof(CUIAutomation),NULL,CLSCTX_INPROC_SERVER,__uuidof(IUIAutomation),(void**)automation);
    return (SUCCEEDED(hr));
}


int main(int argc,char** argv)
{

    QApplication a(argc,argv);
    MainWindow w;


    //Here is the main code 
    IUIAutomation* automation = NULL;
    IUIAutomationElement* elem = NULL;
    BOOL stat = InitializeUIAutomation(&automation);
    POINT mousePt;
    BSTR elemName = NULL;
    if (stat)
    {
        while (true)
        {
            GetCursorPos(&mousePt);
            HRESULT hr = automation->ElementFromPoint(mousePt,&elem);
            if (SUCCEEDED(hr) && elem != NULL)
            {
                elem->get_CurrentName(&elemName);
                std::wstring ws(elemName,SysStringLen(elemName));
                //elem->SetFocus();
          
               // std::wcout << ws << std::endl;
                QString testing = QString::fromStdWString(ws);
                qDebug() << testing;
            }
            SysFreeString(elemName);
            elem->Release();
            Sleep(40);
        }
    }
    automation->Release();
    CoUninitialize();

    QObject::connect(&MainWindow::instance(),&MainWindow::mouseEvent,[]() {
            qDebug() << "Mouse Event";
        });
     w.show();   //displays on screen.
    return a.exec();
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...