unit WebListTrd;
interface
uses
Classes, ShDocVw, SysUtils, ActiveX;
type
TGetWebListThread = class(TThread)
private
function GetWebPointCollection(var nCount: Integer):IShellWindows;
function GetWebPageUrl(const shellWindows: IShellWindows; Index: Integer): string;
procedure CreateWebList(var sltWebList: TStringList);
protected
procedure Execute; override;
public
sltWebList:TStringList;
Constructor Create;
end;
implementation
constructor TGetWebListThread.Create;
begin
FreeOnTerminate:= True;
inherited Create(True);
Resume;
end;
procedure TGetWebListThread.Execute;
begin
CreateWebList(sltWebList);
end;
procedure TGetWebListThread.CreateWebList(var sltWebList: TStringList);
var
ShellWindows: IShellWindows;
URL: string;
I,nCount: integer;
begin
//Initializes the COM library
CoInitialize(nil);
//Clear UrlList
sltWebList:=TStringList.Create;
sltWebList.CaseSensitive:=false;
sltWebList.Clear;
// Try to get all IE windows point
ShellWindows:=GetWebPointCollection(nCount);
//Try to get url and add it to UrlList
for I:=0 to nCount-1 do
begin
URL:=GetWebPageUrl(ShellWindows,I);
if URL='' then continue;
sltWebList.Add(url)
end;
//Closes the COM library
CoUnInitialize;
end;
function TGetWebListThread.GetWebPointCollection(var nCount: Integer): IShellWindows;
begin
try
Result:=CoShellWindows.Create;
nCount:=Result.Count;
except
Result:=nil;
nCount:=0;
end;
end;
function TGetWebListThread.GetWebPageUrl(const shellWindows: IShellWindows; Index: Integer): string;
function IsUrlValid(URL: String):boolean;
begin
result:=(URL<>'')and(Pos('http://',LowerCase(Url))<>0);
end;
var
WebBrowser:IWebBrowser2;
url: string;
begin
try
WebBrowser:=shellWindows.Item(index) as IWebBrowser2;
except
WebBrowser:=nil;
end;
if WebBrowser=nil then
url:=''
else
url:=WebBrowser.LocationURL;
if not IsUrlValid(url) then url:='';
Result:=url;
end;
end.