Solved

Get Chrome URL & Process Name

Posted on 2011-03-01
12
2,441 Views
Last Modified: 2012-08-14
Hi, how can I get the Chrome URL and the process name from the active window?
0
Comment
Question by:eNarc
  • 6
  • 3
12 Comments
 
LVL 19

Expert Comment

by:Thommy
ID: 35014934
This is how you can do it with Internet Explorer...

http://www.festra.com/wwwboard/messages/3565.html
0
 
LVL 19

Expert Comment

by:Thommy
ID: 35014943
This is another EE question where I have already answered the part of your question how to get Chrome url...

http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_26553357.html
0
 
LVL 19

Expert Comment

by:Thommy
ID: 35014956
Again for you out of the above mentioned EE link:
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_26553357.html
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  TheHandle:THandle;

implementation

{$R *.dfm}

function GetGoogleActiveTabAddress(wnd: THandle; Param: Integer): Bool; stdcall;
var
 wndClass: array[0..127] of char;
 len:integer;
 h:hwnd;
 S:string;
 i:integer;
begin
 //Get the object class name.
 GetClassName(wnd, wndClass, SizeOf(wndClass));

 if (wndClass = 'Chrome_AutocompleteEditView') then begin
   h:=FindWindowEx(TheHandle,0,wndClass,nil);

   len:=SendMessage(h, WM_GETTEXTLENGTH, 0, 0);

   SetLength(S, len);

   SendMessage(h, WM_GETTEXT, len+1, lparam(@S[1]));

   for i:=1 to length(S) do begin
     SendMessage(Param, WM_CHAR, ord(S[i]), 0); //Paste from the ClipBoard to the Memo1.
   end;
   SendMessage(Param, WM_CHAR, 13, 0); //Send ENTER to the Memo1.



 end;
 Result := True;                               //Continue searching.
end;

function FindGoogleChrome(wnd: THandle; Param: Integer): Bool; stdcall;
var
 wndClass: array[0..127] of char;
begin
 //Get the object class name.
 GetClassName(wnd, wndClass, SizeOf(wndClass));

 if wndClass = 'Chrome_WidgetWin_0' then begin
   TheHandle:=wnd;
   EnumChildWindows(wnd, @GetGoogleActiveTabAddress, Param); //Enum the child objects.
 end;
 Result := True; //Continue searching other IExplorer windows.
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  EnumWindows(@FindGoogleChrome, Memo1.Handle);
end;

end.

Open in new window

0
 
LVL 19

Accepted Solution

by:
Thommy earned 500 total points
ID: 35015052
This is a demo app to show how to control Goggle Chrome from Delphi...
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Edit1: TEdit;
    Button5: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  TheHandle:THandle;
  TabCount: integer;
  ActiveTab: integer;
  ActiveTabEditHwnd: hwnd;

implementation

const
  LPARAM_KEYUP = $C000;

{$R *.dfm}

function GetGoogleActiveTabAddress(wnd: THandle; Param: Integer): Bool; stdcall;
var
 wndClass: array[0..127] of char;
 len:integer;
 h:hwnd;
 S:string;
 i:integer;
begin
 //Get the object class name.
 GetClassName(wnd, wndClass, SizeOf(wndClass));

 if (wndClass = 'Chrome_AutocompleteEditView') then begin
   h:=FindWindowEx(TheHandle,0,wndClass,nil);

   ActiveTabEditHwnd:=h;

   len:=SendMessage(h, WM_GETTEXTLENGTH, 0, 0);

   SetLength(S, len);

   SendMessage(h, WM_GETTEXT, len+1, lparam(@S[1]));

   for i:=1 to length(S) do begin
     SendMessage(Param, WM_CHAR, ord(S[i]), 0); //Paste from the ClipBoard to the Memo1.
   end;
   SendMessage(Param, WM_CHAR, 13, 0); //Send ENTER to the Memo1.



 end;
 Result := True;                               //Continue searching.
end;

function FindGoogleChrome(wnd: THandle; Param: Integer): Bool; stdcall;
var
 wndClass: array[0..127] of char;
begin
 //Get the object class name.
 GetClassName(wnd, wndClass, SizeOf(wndClass));

 if wndClass = 'Chrome_WidgetWin_0' then begin
   inc(TabCount);
   TheHandle:=wnd;
   EnumChildWindows(wnd, @GetGoogleActiveTabAddress, Param); //Enum the child objects.
 end;
 Result := True; //Continue searching other IExplorer windows.
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  TabCount:=0;
  EnumWindows(@FindGoogleChrome, Memo1.Handle);
  ActiveTab:=0;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  BringWindowToTop(TheHandle);
  PostMessage(TheHandle,WM_KEYDOWN,VK_F11,0);
  PostMessage(TheHandle,WM_KEYUP,VK_F11,0);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  BringWindowToTop(TheHandle);
  PostMessage(TheHandle,WM_KEYDOWN,VK_F5,0);
  PostMessage(TheHandle,WM_KEYUP,VK_F5,0);
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  BringWindowToTop(TheHandle);

  PostMessage(TheHandle, WM_KEYDOWN, VK_CONTROL, 0);
  PostMessage(TheHandle, WM_KEYDOWN, Ord('2'), 0);
  PostMessage(TheHandle, WM_KEYUP, Ord('2'), LPARAM_KEYUP);
  PostMessage(TheHandle, WM_KEYUP, VK_CONTROL, LPARAM_KEYUP);
end;

procedure TForm1.Button5Click(Sender: TObject);
var
  i: integer;
begin
  BringWindowToTop(TheHandle);

  //clear active url
  SendMessage(ActiveTabEditHwnd,EM_SETSEL,0,-1);
  SendMessage(ActiveTabEditHwnd,WM_CLEAR,0,0);

  //pass new url
  for i:=1 to length(Edit1.Text) do begin
    PostMessage(ActiveTabEditHwnd, WM_CHAR, ord(Edit1.Text[i]), 0);
  end;

  //Open new url
  PostMessage(ActiveTabEditHwnd, WM_KEYDOWN, VK_RETURN, 0);
  PostMessage(ActiveTabEditHwnd, WM_KEYUP, VK_RETURN, 0);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Button1Click(self);
end;

end.

Open in new window

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 19

Expert Comment

by:Thommy
ID: 35015140
Google Chrome has a multi-process architecture, meaning tabs can run in separate processes from each other, and from the main browser process.

The name of the process is chrome.exe.

If you have spawned different processes you will find multiple chrome.exe in your process explorer...
ProcessExplorer.JPG
0
 
LVL 19

Expert Comment

by:Thommy
ID: 35293721
Sorry mlmcc, I missed your administrative comment from 27/03/11 01:01 AM, where you asked for help on closing this question. I would have posted my recommendation earlier, if I had recognized it:

I do not understand why the question is to be deleted without assigning points!!!

In my opinion i have provided enough information to solve the problem...

Especially my following comment (ID:35014943 Author:ThommyDate:02/03/11 08:40 AM)
with a link to an EE question concerning the same problem, that I have answered before, will help the asker...
0
 
LVL 5

Author Comment

by:eNarc
ID: 35299567
Hi Sorry for the delay, my delphi had been messed up.

I've tested your code and it works perfectly, and I also object to this being closed and deleted because it has working code involved.

thankyou tommy. and sorry it had taken so long.
0
 
LVL 5

Author Comment

by:eNarc
ID: 35299585
I object this question being closed and deleted, what tommy provided is working code.

I'd like to accept this for the solution.

ID:35015052
Author:Thommy
Date:02/03/11 08:02 AM

thankyou
0
 
LVL 5

Author Closing Comment

by:eNarc
ID: 35299592
Perfect
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now