Advertisement
Guest User

Untitled

a guest
Aug 30th, 2020
789
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.84 KB | None | 0 0
  1. HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
  2. hr = CoCreateInstance(CLSID_CUIAutomation8, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pUIAutomation));
  3. if (SUCCEEDED(hr))
  4. {
  5.     // Test with french or english calc
  6.     HWND hWndDest = FindWindow(L"ApplicationFrameWindow", L"Calculatrice");
  7.     if (!hWndDest)
  8.         hWndDest = FindWindow(L"ApplicationFrameWindow", L"Calculator");
  9.     if (hWndDest)
  10.     {
  11.         if (IsIconic(hWndDest))
  12.         {
  13.             ShowWindow(hWndDest, SW_RESTORE);
  14.             Sleep(200);
  15.         }
  16.         IUIAutomationElement* pRoot = NULL;
  17.         hr = pUIAutomation->ElementFromHandle(hWndDest, &pRoot);
  18.         if (SUCCEEDED(hr))
  19.         {
  20.             IUIAutomationCondition* pTrueCondition = NULL;
  21.             hr = pUIAutomation->CreateTrueCondition(&pTrueCondition);
  22.             IUIAutomationElementArray* pElementArray = NULL;
  23.             hr = pRoot->FindAll(TreeScope_Descendants, pTrueCondition, &pElementArray);
  24.             if (SUCCEEDED(hr))
  25.             {
  26.                 int nCount;
  27.                 hr = pElementArray->get_Length(&nCount);
  28.                 for (int i = 0; i < nCount; i++)
  29.                 {
  30.                     {
  31.                         IUIAutomationElement* pElement = NULL;
  32.                         hr = pElementArray->GetElement(i, &pElement);
  33.                         if (SUCCEEDED(hr))
  34.                         {
  35.                             BSTR bstrId;
  36.                             pElement->get_CurrentAutomationId(&bstrId);
  37.                             if (lstrcmp(bstrId, L"num8Button") == 0)
  38.                             {
  39.                                 IUnknown* pUnknown = NULL;
  40.                                 IUIAutomationLegacyIAccessiblePattern* pLegacyIAccessiblePattern = NULL;
  41.                                 hr = pElement->GetCurrentPattern(UIA_LegacyIAccessiblePatternId, &pUnknown);
  42.                                 hr = pUnknown->QueryInterface(IID_PPV_ARGS(&pLegacyIAccessiblePattern));
  43.                                 if (SUCCEEDED(hr))
  44.                                 {
  45.                                     hr = pLegacyIAccessiblePattern->DoDefaultAction();
  46.                                     pLegacyIAccessiblePattern->Release();
  47.                                 }
  48.                             }
  49.                             pElement->Release();
  50.                         }
  51.                     }
  52.                 }
  53.             }
  54.             pTrueCondition->Release();
  55.             pRoot->Release();
  56.         }
  57.     }
  58.     pUIAutomation->Release();
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement