How to know Element information using UIAutomation Element in Windows API Mouse Hook

312 Views Asked by At

In my program, when i hover my mouse, i want to know some information about the element, so far i am able to get the name of the element.

But i also want to know its

  1. localized control type
    Automation ID

    IsInvokePatternAvailable

    IsSelectionItemPatternAvailiable

    IsTogglePatternAvailiable.

about the element How can i do that ? Inspect tool

Here is the code i have so far which helps me get the name of element

#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();
}
0

There are 0 best solutions below