Advertisement
Guest User

Untitled

a guest
Jul 10th, 2021
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. std::string GetUrl(Process* process) {
  2.     CoInitialize(NULL);
  3.     HWND hwnd = NULL;
  4.     while (true) {
  5.         if ((*process).exeName == "chrome.exe" or (*process).exeName == "opera.exe") {
  6.             hwnd = FindWindowEx(0, hwnd, L"Chrome_WidgetWin_1", NULL);
  7.         }
  8.         else if ((*process).exeName == "firefox.exe") {
  9.             hwnd = FindWindowEx(0, hwnd, L"MozillaWindowClass", NULL);
  10.         }
  11.  
  12.         if (!hwnd)
  13.             break;
  14.         if (!IsWindowVisible(hwnd))
  15.             continue;
  16.         CComQIPtr<IUIAutomation> uia;
  17.         if (FAILED(uia.CoCreateInstance(CLSID_CUIAutomation)) || !uia)
  18.             return "Error5";
  19.        
  20.         CComPtr<IUIAutomationElement> element;
  21.         if (FAILED(uia->ElementFromHandle(hwnd, &element)) || !element)
  22.             return "Error4";
  23.         if ((*process).exeName == "chrome.exe" or (*process).exeName == "opera.exe") {
  24.             CComPtr<IUIAutomationCondition> condition;
  25.  
  26.             uia->CreatePropertyCondition(UIA_ControlTypePropertyId,
  27.                 CComVariant(UIA_EditControlTypeId), &condition);
  28.            
  29.             CComPtr<IUIAutomationElement> edit;// СМОТРЕТЬ СЮДА!!!!!!!!!!
  30.             if (FAILED(element->FindFirst(TreeScope_Descendants, condition, &edit))
  31.                 || !edit)
  32.                 continue;
  33.            
  34.  
  35.             CComVariant url;
  36.             edit->GetCurrentPropertyValue(UIA_ValueValuePropertyId, &url);
  37.             (*process).url = ConvertCComVariantToStr(url);
  38.             return "Done";
  39.     }
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement