本文整理自网络,侵删。
本文主要是实现在Delphi里如何获取资源管理器打开的路径以及IE打开的地址列表的功能,主要是使用IShellWindows和IWebBrowser2接口,具体代码如下:
unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
type TForm1 = class(TForm) Button1: TButton; ListBox1: TListBox; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Form1: TForm1;
implementation
uses SHDocVw;{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);var I: integer; spDisp: IDispatch; IE1: IWebBrowser2; ShellWindow: IShellWindows;begin ListBox1.clear; ShellWindow := CoShellWindows.Create; for I := 0 to ShellWindow.Count - 1 do begin try spDisp := ShellWindow.Item(I); if (spDisp <> nil) then begin spDisp.QueryInterface(IWebBrowser2, IE1); if IE1 <> nil then begin ListBox1.items.add(IE1.Get_LocationURL()); end; end; except on EAccessViolation do begin exit end; end; end;end;
end.当前使用的Delphi版本:delphi10.2 操作系统window10,运行效果如下:
相关阅读 >>
Delphi winapi: gettickcount - 获取系统已启动的时间
Delphi pchar和array [0..255] of char的区别
更多相关阅读请进入《Delphi》频道 >>