delphi chrome获取html5,如何使用delphi从Chrome获取网址

这篇博客介绍了一种使用Delphi编程语言来获取Chrome活动页面URL的方法。通过枚举窗口并查找特定的Chrome窗口句柄,然后获取Chrome浏览器中活动标签页的URL。虽然代码示例简单且快速实现,但可能需要调整以适应多个Chrome实例。
摘要由CSDN通过智能技术生成

以下是我从活动选项卡中检索URL之前的操作方法.您可以将其扩展为包含Chrome的所有标签.

另外一个注意事项,正如您所看到的,它抓住了它找到的chrome.exe的第一个句柄.要使此功能适应多个Chrome运行实例,您需要对其进行调整以获取每个Chrome实例的句柄.

我把它放在一起非常快,所以不要考虑这种“生产”质量.只需创建一个新的vcl应用程序并在表单上删除TMemo和TButton,并将Button1Click分配给TButton的OnClick事件.

unit main;

interface

uses

Windows,

Messages,

SysUtils,

Classes,

Controls,

Forms,

StdCtrls;

type

TForm1 = class(TForm)

Memo1: TMemo;

Button1: TButton;

procedure Button1Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

function GetActivePageUrlFromChrome(Handle: HWnd; Param: LParam): Bool; stdcall;

var

Form1 : TForm1;

implementation

{$R *.dfm}

function GetActivePageUrlFromChrome(Handle: HWnd; Param: LParam): Bool; stdcall;

var

List: TStrings;

hWndChrome, hWndChromeChild: HWND;

Buffer : array[0..255] of Char;

begin

List := TStrings(Param);

//get the window caption

SendMessage(Handle, WM_GETTEXT, Length(Buffer), integer(@Buffer[0]));

//look for the chrome window with "Buffer" caption

hWndChrome := FindWindow('Chrome_WidgetWin_0', Buffer);

if hWndChrome <> 0 then

begin

hWndChromeChild := FindWindowEx(hWndChrome, 0, 'Chrome_AutocompleteEditView', nil);

if hWndChromeChild <> 0 then

begin

SendMessage(hWndChromeChild, WM_GETTEXT, Length(Buffer), integer(@Buffer));

List.Add(Buffer);

end;

end;

Result := True;

end;

procedure TForm1.Button1Click(Sender: TObject);

var

slChromeUrl : TStringList;

begin

slChromeUrl := TStringList.Create;

try

EnumWindows(GetActivePageUrlFromChrome, LParam(slChromeUrl));

Memo1.Lines.AddStrings(slChromeUrl);

finally

FreeAndNil(slChromeUrl);

end;

end;

end.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值