ertemsoft
asked on
How do I get the URL and change the active tab in Google Chrome
Antiporn want to do is to have a lot of application.
How do I get the URL and change the active tab in Google Chrome.
How do I get the URL and change the active tab in Google Chrome.
First, you have to replace function FindIExplorer with you own function FindGoggleChrome to get the right window handle.
After that you can check functionality...
After that you can check functionality...
ASKER
Hello Thommy
I use this method but it did not work in chrome
procedure GetCurrentURL(url,Title: string);
var
DDEClient : TDDEClientConv;
p, q: PChar;
i: Integer;
begin
DDEClient := TDDEClientConv.Create(nil) ;
try
with DDEClient do if SetLink('IExplore', 'WWW_GetWindowInfo') or
SetLink('Netscape', 'WWW_GetWindowInfo') or
SetLink('Mosaic', 'WWW_GetWindowInfo') or
SetLink('Netscp6', 'WWW_GetWindowInfo') or
SetLink('Mozilla', 'WWW_GetWindowInfo') or
SetLink('Firefox', 'WWW_GetWindowInfo') then
p := RequestData('0xFFFFFFFF')
else raise Exception.Create('Could not establish browser DDE link');
if Assigned(p) then try
q := p;
Assert(q^ = '"');
SetLength(URL, StrLen(q));
Inc(q);
i := 0;
while q^ <> '"' do begin
if (q^ = '\') and (q[1] = '"') then Inc(q);
Inc(i);
URL[i] := q^;
Inc(q);
end;
SetLength(URL, i);
SetLength(Title, StrLen(q));
i := 0;
Inc(q, 3);
while q^ <> '"' do begin
if (q^ = '\') and (q[1] = '"') then Inc(q);
Inc(i);
Title[i] := q^;
Inc(q);
end;
SetLength(Title, i);
finally
StrDispose(p);
end else raise Exception.Create('Could not fetch browser data');
finally
DDEClient.Free;
end;
end;
I use this method but it did not work in chrome
procedure GetCurrentURL(url,Title: string);
var
DDEClient : TDDEClientConv;
p, q: PChar;
i: Integer;
begin
DDEClient := TDDEClientConv.Create(nil)
try
with DDEClient do if SetLink('IExplore', 'WWW_GetWindowInfo') or
SetLink('Netscape', 'WWW_GetWindowInfo') or
SetLink('Mosaic', 'WWW_GetWindowInfo') or
SetLink('Netscp6', 'WWW_GetWindowInfo') or
SetLink('Mozilla', 'WWW_GetWindowInfo') or
SetLink('Firefox', 'WWW_GetWindowInfo') then
p := RequestData('0xFFFFFFFF')
else raise Exception.Create('Could not establish browser DDE link');
if Assigned(p) then try
q := p;
Assert(q^ = '"');
SetLength(URL, StrLen(q));
Inc(q);
i := 0;
while q^ <> '"' do begin
if (q^ = '\') and (q[1] = '"') then Inc(q);
Inc(i);
URL[i] := q^;
Inc(q);
end;
SetLength(URL, i);
SetLength(Title, StrLen(q));
i := 0;
Inc(q, 3);
while q^ <> '"' do begin
if (q^ = '\') and (q[1] = '"') then Inc(q);
Inc(i);
Title[i] := q^;
Inc(q);
end;
SetLength(Title, i);
finally
StrDispose(p);
end else raise Exception.Create('Could not fetch browser data');
finally
DDEClient.Free;
end;
end;
This will return url of active GOOGLE CHROME tab:
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_AutocompleteEditVi ew') 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(@FindGoogleChr ome, Memo1.Handle);
end;
end.
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(
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_AutocompleteEditVi
h:=FindWindowEx(TheHandle,
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
end;
Result := True; //Continue searching other IExplorer windows.
end;
procedure TForm1.Button1Click(Sender
begin
EnumWindows(@FindGoogleChr
end;
end.
ASKER
Hello
thank you very very much tommy.
thank you very very much tommy.
Concerning your second question of how to change active tabs:
You can change Tabs in Google Chrome by pressing key combination CTRL+1 for first tab, CTRL+2 for second tab and so on.
We can use PostMessage to send keys to Google Chrome...
You can change Tabs in Google Chrome by pressing key combination CTRL+1 for first tab, CTRL+2 for second tab and so on.
We can use PostMessage to send keys to Google Chrome...
ASKER
thank you Thommy
How to PostMessage with the active tab to send the ur ?l. Can you give an example ?
Best Regards
How to PostMessage with the active tab to send the ur ?l. Can you give an example ?
Best Regards
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hello
Thank you very much tommy
Thank you very much tommy
Thank you very much for the points!!!
Do you already have a solution for sending key combinations like CTRL-1, CTRL-2 and so on to GOOGLE CHROME for changing active tabs???
Do you already have a solution for sending key combinations like CTRL-1, CTRL-2 and so on to GOOGLE CHROME for changing active tabs???
https://www.experts-exchange.com/questions/20271021/Get-url-for-all-opened-web-pages.html