如何查找到特定的IE窗口,然后获得它的接口控制IE中的网页

zxtyhy 2008-07-27 10:53:45
如题。
已经实现查找IE窗口,那么如何才能得到接口来控制IE中的网页呢?
...全文
162 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
elongwang1 2011-05-31
  • 打赏
  • 举报
回复
这种方法比用web控件更麻烦一点,似乎要向IE发送网页控件的消息。这种方法需要使用VC.net可以实现,似乎哈!
coffeemay 2008-07-28
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 gyk120 的回复:]
能否说下具体功能,控制网页干什么??
Webbrowser应该有相关功能吧
[/Quote]
zxtyhy 2008-07-28
  • 打赏
  • 举报
回复
to:gyk120
Webbrowser是有很多控制的功能,但是,我查找到的是IE窗口,不是自己做的Form窗口的。
例如:如何得到一个IE窗口当前打开的网页地址?如何得到其中的连接地址?如何得到图片等等
to:redlegend_126_com
FindWindow我已经实现了,而且也能够区分是否是IE窗口了,现在问题是如何得到IE中打开的网页,如何控制网页?
redlegend_126_com 2008-07-28
  • 打赏
  • 举报
回复
FindWindow查找后,直接控制
gyk120 2008-07-28
  • 打赏
  • 举报
回复
还有一种是枚举窗口,不需要通过接口来完成,不过会麻烦一些
gyk120 2008-07-28
  • 打赏
  • 举报
回复
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, shellapi, ddeman, shdocvw,registry;

type
TForm1 = class(TForm)
ListBox1: TListBox;
Button1: TButton;
Button2: TButton;
procedure ListBox1DblClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
IEXPLORE:string;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}


procedure TForm1.ListBox1DblClick(Sender: TObject);
begin
WinExec(PChar(IEXPLORE+' "'+listbox1.items[listbox1.itemindex]+'"'),SW_NORMAL);
end;

procedure TForm1.Button1Click(Sender: TObject);
const
maxx = 30;
var
ShellWindow: IShellWindows;
nCount: integer;
spDisp: IDispatch;
i: integer;
vi: OleVariant;
IE1: IWebBrowser2;
begin
listbox1.clear;
ShellWindow := CoShellWindows.Create;
nCount := ShellWindow.Count;
for i := 0 to nCount - 1 do
begin
vi := i;
try
spDisp := ShellWindow.Item(vi);
except
exit
end;
if (spDisp <> nil) then
begin
try
spDisp.QueryInterface(iWebBrowser2, IE1);
except
on EAccessViolation do
begin
exit
end;
end;
if (IE1 <> nil) then
begin
listbox1.items.add(IE1.Get_LocationURL());
end;
end;
end;
deletefile(extractfilepath(paramstr(0)) + 'Address.d' + inttostr(maxx));
for i := maxx - 1 downto 0 do
renamefile(extractfilepath(paramstr(0)) + 'Address.d' + format('%.2d', [i]), 'Address.d' + format('%.2d', [i + 1]));
listbox1.items.savetofile(extractfilepath(paramstr(0)) + 'Address.d00');
end;

procedure TForm1.Button2Click(Sender: TObject);
var
i: integer;
begin
for i := 0 to listbox1.items.count - 1 do
begin
WinExec(PChar(IEXPLORE+' "'+listbox1.items[i]+'"'),SW_NORMAL);
end;
end;

procedure TForm1.FormShow(Sender: TObject);
var
s: string;
reg:TRegistry;
begin
s := extractfilepath(paramstr(0)) + 'Address.d00';
if fileexists(s) then
listbox1.items.loadfromfile(s);
reg:=TRegistry.create;
reg.rootkey:=HKEY_LOCAL_MACHINE;
reg.openkey('Software\Microsoft\Windows\CurrentVersion\App Paths\IEXPLORE.EXE',true);
IEXPLORE:=reg.ReadString('');
reg.closekey;
reg.free;
end;

end.
gyk120 2008-07-28
  • 打赏
  • 举报
回复
得到打开的网页我这倒有个办法,用IShellWindows接口可以完成
cccc813 2008-07-28
  • 打赏
  • 举报
回复
看源代码。
gyk120 2008-07-27
  • 打赏
  • 举报
回复
能否说下具体功能,控制网页干什么??
Webbrowser应该有相关功能吧

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧