0

Since the official release of Microsoft Edge, Ialready saw several examples about how get active url from Microsoft Edge, mainly in C#.NET code.

But until now don't have saw no one have done a Delphi version for this. Now I'm here exactly for know if someone already have done this. I'm needing much.

My last attempt was:

function GetEdgeActiveTabURL(Wnd: HWnd; Param: LParam): Bool; stdcall;
var
  urls: TStrings;
  hWndMainWindow, hWndTab: HWND;
  Buffer : array[0..255] of Char;
  res : boolean;
begin
  res := true;
  urls := TStrings(Param);
  SendMessage(Wnd, WM_GETTEXT, Length(Buffer), integer(@Buffer[0]));
  hWndMainWindow := FindWindow('ApplicationFrameWindow', Buffer);
  application.ProcessMessages;
  if hWndMainWindow <> 0 then
  begin
    hWndTab := FindWindowEx(hWndMainWindow, 0, 'Internet Explorer_Server', nil);
    if hWndTab <> 0 then
    begin
      SendMessage(hWndTab, WM_GETTEXT, Length(Buffer), integer(@Buffer));
      urls.Add(Buffer);
      res := false;
    end;
  end;
  Result := res;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
  Urls: TStringList;
begin
  Urls := TStringList.Create;
  try
    EnumWindows(@GetEdgeActiveTabURL, LParam(Urls));
    Memo1.Lines.AddStrings(Urls);
  finally
    FreeAndNil(Urls);
  end;

end;

EDITED:

OK, So, this is all that I have until now, but this show me only name of control. How get value?

 uses
     ActiveX, UIAutomationClient_TLB {http://pastebin.com/a0b5J0FM};

     private
        { Private declarations }
        procedure FindItems(Recurse: Boolean);

    procedure TForm1.FindItems(Recurse: Boolean);
    var
      UIAuto: TCUIAutomation;
      condition: IUIAutomationCondition;
      collection: IUIAutomationElementArray;
      Length: Integer;
      Count: Integer;
      itemElement: IUIAutomationElement;
      retVal: Integer;
      val: WideString;

      ExpandCollapsePattern: IUIAutomationExpandCollapsePattern;
      FElement: IUIAutomationElement;
    begin
      UIAuto := TCUIAutomation.Create(nil);

      UIAuto.CreateTrueCondition(condition);

      UIAuto.ElementFromHandle(GetForegroundWindow, FElement);

      FElement.FindAll(TreeScope_Descendants, condition, collection);

      collection.Get_Length(length);

      for Count := 0 to length - 1 do
      begin
        collection.GetElement(Count, itemElement);
        itemElement.Get_CurrentControlType(retVal);

        if (retVal = UIA_EditControlTypeId) then
        begin
          ItemElement.Get_CurrentName(val);
          TThread.Synchronize(nil,
            procedure
            begin
              mmo1.lines.Add(val);
            end);

          itemElement.GetCurrentPattern(UIA_ExpandCollapsePatternId, IInterface(ExpandCollapsePattern));
          if Assigned(ExpandCollapsePattern) then
          begin
            ExpandCollapsePattern.Expand;
            if Recurse = True then
              FindItems(False);
          end;
        end;
      end;
      UIAuto.Free;
    end;

    procedure TForm1.tmr1Timer(Sender: TObject);
    begin
     TThread.CreateAnonymousThread(procedure begin CoInitializeEx(nil, 2); FindItems(true); CoUninitialize; end).Start;
     end;
  • Please show a .NET example that works. Maybe it can be translated to native code, like Delphi. In any case, your use of `WM_GETTEXT` and `FindWindow()` to find the `ApplicationFrameWindow` window is overkill, use `GetClassName()` instead and check the result for `ApplicationFrameWindow`. And you can't use `WM_GETTEXT` with an `Internet Explorer_Server` window. [Get the IHTMLDocument2 interface from the HWND](https://support.microsoft.com/en-us/kb/249232) and then you can read the [`IHTMLDocument2.url`](https://msdn.microsoft.com/en-us/library/mshtml.ihtmldocument2.url.aspx) property. – Remy Lebeau Feb 29 '16 at 04:00
  • 1
    Your code doesn't seem to bear any relation to the task at hand. Edge is a WinRT app. Your calls to ProcessMessages belie a lack of clarity. Do you jam them in any whenever your code doesn't work? – David Heffernan Feb 29 '16 at 07:39
  • Anyway, this is a task for UI Automation. There are many examples of such code. So I've closed this as a dupe. Translating to Delphi should be trivial since the interfaces are the same for all languages. – David Heffernan Feb 29 '16 at 08:20
  • Someonme of you, could help me, posting as a answer a translated version from this C# code that you suggested on duplicate question? I'm not good for this task of translate :-( –  Feb 29 '16 at 12:01
  • Stack Overflow is not a translation service. It sounds as though you need to hire a programmer to add to your team. You are surely going to need a programmer to make any real progress here. – David Heffernan Feb 29 '16 at 14:34
  • @DavidHeffernan, I updated my question, see above. –  Feb 29 '16 at 21:54

0 Answers0