【发布时间】:2021-09-05 16:33:44
【问题描述】:
我正在尝试获取有关光标下当前窗口的信息,当我手动指定hwnd 时,我的功能正常工作,我如何从鼠标下的当前窗口中获取hwnd?
#include <UIAutomation.h>
POINT p;
GetCursorPos(&p);CComPtr<IAccessible> pAcc;
VARIANT varChild;
if (SUCCEEDED(AccessibleObjectFromWindow((HWND)hwnd,
OBJID_WINDOW,IID_IAccessible, reinterpret_cast<void**>(&pAcc))))
{
CComBSTR bstrName, bstrValue, bstrDescription;
varChild.vt = VT_I4;
varChild.lVal = CHILDID_SELF;
if (SUCCEEDED(pAcc->get_accName(varChild, &bstrName)))
auto name = bstrName.m_str;
if (SUCCEEDED(pAcc->get_accValue(varChild, &bstrValue)))
auto value = bstrValue.m_str;
if (SUCCEEDED(pAcc->get_accValue(varChild, &bstrDescription)))
auto description = bstrDescription.m_str;
}
【问题讨论】:
-
WindowFromPoint(),ChildWindowFromPoint(),RealChildWindowFromPoint()
标签: c++ winapi microsoft-ui-automation