首页 > 解决方案 > 如何使用纯 C 检索自动化元素的控件类型

问题描述

Objective:通过纯 C 从 Uiautomation 元素中获取控件类型名称作为字符串(即 Button、Checkbox、Menu、MenuItem 等)

到目前为止,我有以下代码:

#define COBJMACROS
#include "UiAutomationClient.h"
#include "UiAutomationCore.h" 

POINT pt;
IUIAutomation *pAutomation = NULL;
IUIAutomationElement *element = NULL;
CONTROLTYPEID element_type;

GetCursorPos(&pt);
hr = IUIAutomation_ElementFromPoint(pAutomation, pt, &element);
if(SUCCEEDED(hr) && element != NULL){
   hr = IUIAutomationElement_get_CurrentControlType(element,&element_type);
   if(SUCCEEDED(hr)){
     ????    
   }
}

据我了解 get_CurrentControlType 我得到了控件类型的 ID,但我对该控件类型的名称感兴趣。有没有人知道该怎么做?提前谢谢

标签: ccomui-automation

解决方案


推荐阅读