You can use a WH_MOUSE_LL hook
(if (wParam == WM_LBUTTONDOWN)... then MSLLHOOKSTRUCT.pt to get POINT, then same code)
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
How i could get the title
or HWND
of the window in which her taskbar button thumbnail is being clicked?
Using CBTProc
i listen to HCB_ACTIVATE
and i call UIAutomation
reading ElementFromPoint
the problem is... sometimes it works to get the title and sometimes it get another thing than the title
when this happens title
are blank and classname
is SysListView32
.
I think this happens when the call to HCB_ACTIVATE
is received and the thumbnail already disappeared, then ElementFromPoint
get another thing than the window thumbnail.
I would like to not use a global hook in CBT, there's any other way to achieve this task?
std::wstring AccWindowFromPoint()
{
BSTR name = NULL;
if (SUCCEEDED(CoInitialize(NULL)))
{
CComPtr<IUIAutomation> automation;
if (SUCCEEDED(automation.CoCreateInstance(CLSID_CUIAutomation8))) // or CLSID_CUIAutomation
{
POINT pos{};
GetCursorPos(&pos);
CComPtr<IUIAutomationElement> pElement;
if (SUCCEEDED(automation->ElementFromPoint(pos, &pElement)))
{
pElement->get_CurrentName(&name);
UIA_HWND uia_hwnd = nullptr;
pElement->get_CurrentNativeWindowHandle(&uia_hwnd);
BSTR classname = nullptr;
pElement->get_CurrentClassName(&classname);
RECT rect;
pElement->get_CurrentBoundingRectangle(&rect);
Print("[accwindowfrompoint]"
"\nname: ", name,
"\nclassname: ", classname, "\n");
}
else
Print("[AccWindowFromPoint] failed to get ElementFromPoint\n");
}
else
Print("[AccWindowFromPoint] failed to CoCreateInstance\n");
}
else
Print("[AccWindowFromPoint] failed to CoInitialize\n");
//CoUninitialize();
if (name == NULL)
return L"";
std::wstring wstrName(name);
return wstrName;
}
You can use a WH_MOUSE_LL hook
(if (wParam == WM_LBUTTONDOWN)... then MSLLHOOKSTRUCT.pt to get POINT, then same code)