eATM

VC++ 调用UIAutomation点击按钮

				
					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<void**>(&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<IUnknown**>(&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;
}
				
			

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注