Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
- hr = CoCreateInstance(CLSID_CUIAutomation8, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pUIAutomation));
- if (SUCCEEDED(hr))
- {
- // Test with french or english calc
- HWND hWndDest = FindWindow(L"ApplicationFrameWindow", L"Calculatrice");
- if (!hWndDest)
- hWndDest = FindWindow(L"ApplicationFrameWindow", L"Calculator");
- if (hWndDest)
- {
- if (IsIconic(hWndDest))
- {
- ShowWindow(hWndDest, SW_RESTORE);
- Sleep(200);
- }
- IUIAutomationElement* pRoot = NULL;
- hr = pUIAutomation->ElementFromHandle(hWndDest, &pRoot);
- if (SUCCEEDED(hr))
- {
- IUIAutomationCondition* pTrueCondition = NULL;
- hr = pUIAutomation->CreateTrueCondition(&pTrueCondition);
- IUIAutomationElementArray* pElementArray = NULL;
- hr = pRoot->FindAll(TreeScope_Descendants, pTrueCondition, &pElementArray);
- if (SUCCEEDED(hr))
- {
- int nCount;
- hr = pElementArray->get_Length(&nCount);
- for (int i = 0; i < nCount; i++)
- {
- {
- IUIAutomationElement* pElement = NULL;
- hr = pElementArray->GetElement(i, &pElement);
- if (SUCCEEDED(hr))
- {
- BSTR bstrId;
- pElement->get_CurrentAutomationId(&bstrId);
- if (lstrcmp(bstrId, L"num8Button") == 0)
- {
- IUnknown* pUnknown = NULL;
- IUIAutomationLegacyIAccessiblePattern* pLegacyIAccessiblePattern = NULL;
- hr = pElement->GetCurrentPattern(UIA_LegacyIAccessiblePatternId, &pUnknown);
- hr = pUnknown->QueryInterface(IID_PPV_ARGS(&pLegacyIAccessiblePattern));
- if (SUCCEEDED(hr))
- {
- hr = pLegacyIAccessiblePattern->DoDefaultAction();
- pLegacyIAccessiblePattern->Release();
- }
- }
- pElement->Release();
- }
- }
- }
- }
- pTrueCondition->Release();
- pRoot->Release();
- }
- }
- pUIAutomation->Release();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement