I'm trying to get the info about the current window under the cursor, I got the function working when I manually specify the hwnd
, how I could get the hwnd
from the current window under the mouse?
#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;
}