bool UIAutoInvoke(HWND hwnd)
{
IUIAutomation* sp_utomation = nullptr;
IUIAutomationElement* sp_hwnd_element = nullptr;
IUIAutomationInvokePattern* pToggle = nullptr;
HRESULT hr = S_FALSE;
bool result = false;
do
{
hr = CoCreateInstance(CLSID_CUIAutomation, NULL, CLSCTX_INPROC_SERVER, IID_IUIAutomation, reinterpret_cast(&sp_utomation));
if (FAILED(hr) || sp_utomation == nullptr) break;
hr = sp_utomation->ElementFromHandle(hwnd, &sp_hwnd_element);
if (FAILED(hr) || sp_hwnd_element == nullptr) break;
hr = sp_hwnd_element->GetCurrentPattern(UIA_InvokePatternId, reinterpret_cast(&pToggle));
if (FAILED(hr) || pToggle == nullptr) break;
result = pToggle->Invoke() == S_OK;
} while (false);
console.log("UIAuto Invoke:{}", result);
if (pToggle) pToggle->Release();
if (sp_hwnd_element) sp_hwnd_element->Release();
if (sp_utomation) sp_utomation->Release();
return result;
}
0