TShellWindows 获取当前浏览器URl问题

xushan123456 2011-02-08 04:30:27
想做个监控 电脑是否打开某网站的程序. 用TShellWindows 循环. 获取 有时候出错 IE 确实打开 然后获取出来的URL 数目却为 0 那位大侠 愿意指点一二. 送上全部分.
...全文
206 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
xushan123456 2011-02-17
  • 打赏
  • 举报
回复
今天没上哈..已经找到原因 是浏览器的兼容性问题 某些网站 的网址是获取不到的 不过一般的都行.. 虽然上面贴的所有代码 早都知道了 还是感谢 结贴了
kayoo 2011-02-09
  • 打赏
  • 举报
回复
具体你可以谷歌“Internet Explorer_Server”
kayoo 2011-02-09
  • 打赏
  • 举报
回复
也可以用IES对象,用个Timer。。
kye_jufei 2011-02-09
  • 打赏
  • 举报
回复
前一種方法可加多線程去創建TShellWindows,然後再去if xWin.Item[i]。。。
kye_jufei 2011-02-09
  • 打赏
  • 举报
回复
換一種方法不行嗎,自己變通一下呀。。。

unit   Unit1; 

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IEEvents, StdCtrls, ActiveX, SHDocVw;

type
TForm1 = class(TForm)
IEEvents1: TIEEvents;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure IEEvents1Quit(Sender: TObject);
procedure IEEvents1DownloadBegin(Sender: TObject);
procedure IEEvents1DownloadComplete(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure IEEvents1ProgressChange(Sender: TObject; Progress,
ProgressMax: Integer);
private
{ Private declarations }
FTimeList: TList;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
pvShell: IShellWindows;
pvWeb2: IWebBrowser2;
ovIE: OleVariant;
dwCount: Integer;
begin
// Create the shell windows interface
pvShell := CoShellWindows.Create;
// Walk the internet explorer windows
for dwCount := 0 to Pred(pvShell.Count) do
begin
// Get the interface
ovIE := pvShell.Item(dwCount);
// At this point you can evaluate the interface (LocationUrl, etc)
// to decide if this is the one you want to connect to. For demo purposes,
// the code will bind to the first one
ShowMessage(ovIE.LocationURL);
// QI for the IWebBrowser2
if (IDispatch(ovIE).QueryInterface(IWebBrowser2, pvWeb2) = S_OK) then
begin
IEEvents1.ConnectTo(pvWeb2);
// Release the interface
pvWeb2 := nil;
end;
// Clear the variant
ovIE := Unassigned;
// Break if we connected
if IEEvents1.Connected then break;
end;
// Release the shell windows interface
pvShell := nil;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
// Create the time list
FTimeList := TList.Create;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
// Free the time list
FTimeList.Free;
end;

procedure TForm1.IEEvents1DownloadBegin(Sender: TObject);
begin
// Add the current time to the list
FTimeList.Add(Pointer(GetTickCount));
end;

procedure TForm1.IEEvents1DownloadComplete(Sender: TObject);
var dwTime: LongWord;
begin
// Pull the top item off the list (make sure there is one)
if (FTimeList.Count > 0) then
begin
dwTime := LongWord(FTimeList[Pred(FTimeList.Count)]);
FTimeList.Delete(Pred(FTimeList.Count));
// Now calculate total based on current time
dwTime:= GetTickCount - dwTime;
// Display a message showing total download time
ShowMessage(Format( 'Download time for "%s " was %d ms ', [IEEvents1.WebObj.LocationURL, dwTime]));
end;
end;

procedure TForm1.IEEvents1Quit(Sender: TObject);
begin
ShowMessage( 'About to disconnect ');
end;

procedure TForm1.IEEvents1ProgressChange(Sender: TObject; Progress,
ProgressMax: Integer);
begin
Caption:=IntToStr(Progress);
end;

end.
kye_jufei 2011-02-09
  • 打赏
  • 举报
回复
constructor   TIEEvents.Create(AOwner:   TComponent); 
begin
// Perform inherited
inherited Create(AOwner);

// Set the event sink IID
FSinkIID := DWebBrowserEvents2;
end;

destructor TIEEvents.Destroy;
begin
// Disconnect
Disconnect;
// Perform inherited
inherited Destroy;
end;

procedure TIEEvents.ConnectTo(Source: IWebBrowser2);
var pvCPC: IConnectionPointContainer;
begin
// Disconnect from any currently connected event sink
Disconnect;
// Query for the connection point container and desired connection point.
// On success, sink the connection point
OleCheck(Source.QueryInterface(IConnectionPointContainer, pvCPC));
OleCheck(pvCPC.FindConnectionPoint(FSinkIID, FCP));
OleCheck(FCP.Advise(Self, FCookie));
// Update internal state variables
FSource := Source;
// We are in a connected state
FConnected := True;
// Release the temp interface
pvCPC := nil;
end;

procedure TIEEvents.Disconnect;
begin
// Do we have the IWebBrowser2 interface?
if Assigned(FSource) then
begin
try
// Unadvise the connection point
OleCheck(FCP.Unadvise(FCookie));
// Release the interfaces
FCP := nil;
FSource := nil;
except
Pointer(FCP) := nil;
Pointer(FSource) := nil;
end;
end;

// Disconnected state
FConnected := False;
end;

procedure TIEEvents.DoStatusTextChange(const Text: WideString);
begin
// Call assigned event
if Assigned(FStatusTextChange) then FStatusTextChange(Self, Text);
end;

procedure TIEEvents.DoProgressChange(Progress: Integer; ProgressMax: Integer);
begin
// Call assigned event
if Assigned(FProgressChange) then FProgressChange(Self, Progress, ProgressMax);
end;

procedure TIEEvents.DoCommandStateChange(Command: Integer; Enable: WordBool);
begin
// Call assigned event
if Assigned(FCommandStateChange) then FCommandStateChange(Self, Command, Enable);
end;

procedure TIEEvents.DoDownloadBegin;
begin
// Call assigned event
if Assigned(FDownloadBegin) then FDownloadBegin(Self);
end;

procedure TIEEvents.DoDownloadComplete;
begin
// Call assigned event
if Assigned(FDownloadComplete) then FDownloadComplete(Self);
end;

procedure TIEEvents.DoTitleChange(const Text: WideString);
begin
// Call assigned event
if Assigned(FTitleChange) then FTitleChange(Self, Text);
end;

procedure TIEEvents.DoPropertyChange(const szProperty: WideString);
begin
// Call assigned event
if Assigned(FPropertyChange) then FPropertyChange(Self, szProperty);
end;

procedure TIEEvents.DoBeforeNavigate2(const pDisp: IDispatch; var URL: OleVariant; var Flags:
OleVariant; var TargetFrameName: OleVariant; var PostData: OleVariant; var Headers: OleVariant; var Cancel: WordBool);
begin
// Call assigned event
if Assigned(FBeforeNavigate2) then FBeforeNavigate2(Self, pDisp, URL, Flags, TargetFrameName, PostData, Headers, Cancel);
end;

procedure TIEEvents.DoNewWindow2(var ppDisp: IDispatch; var Cancel: WordBool);
var
pvDisp: IDispatch;
begin
// Call assigned event
if Assigned(FNewWindow2) then
begin
if Assigned(ppDisp) then
pvDisp := ppDisp
else
pvDisp := nil;
FNewWindow2(Self, pvDisp, Cancel);
ppDisp := pvDisp;
end;
end;

procedure TIEEvents.DoNavigateComplete2(const pDisp: IDispatch; var URL: OleVariant);
begin
// Call assigned event
if Assigned(FNavigateComplete2) then FNavigateComplete2(Self, pDisp, URL);
end;

procedure TIEEvents.DoDocumentComplete(const pDisp: IDispatch; var URL: OleVariant);
begin
// Call assigned event
if Assigned(FDocumentComplete) then FDocumentComplete(Self, pDisp, URL);
end;

procedure TIEEvents.DoOnQuit;
begin
// Call assigned event
if Assigned(FOnQuit) then FOnQuit(Self);
end;

procedure TIEEvents.DoOnVisible(Visible: WordBool);
begin
// Call assigned event
if Assigned(FOnVisible) then FOnVisible(Self, Visible);
end;

procedure TIEEvents.DoOnToolBar(ToolBar: WordBool);
begin
// Call assigned event
if Assigned(FOnToolBar) then FOnToolBar(Self, ToolBar);
end;

procedure TIEEvents.DoOnMenuBar(MenuBar: WordBool);
begin
// Call assigned event
if Assigned(FOnMenuBar) then FOnMenuBar(Self, MenuBar);
end;

procedure TIEEvents.DoOnStatusBar(StatusBar: WordBool);
begin
// Call assigned event
if Assigned(FOnStatusBar) then FOnStatusBar(Self, StatusBar);
end;

procedure TIEEvents.DoOnFullScreen(FullScreen: WordBool);
begin
// Call assigned event
if Assigned(FOnFullScreen) then FOnFullScreen(Self, FullScreen);
end;

procedure TIEEvents.DoOnTheaterMode(TheaterMode: WordBool);
begin
// Call assigned event
if Assigned(FOnTheaterMode) then FOnTheaterMode(Self, TheaterMode);
end;

procedure Register;
begin
// Register the component on the Internet tab of the IDE
RegisterComponents( 'Internet ', [TIEEvents]);
end;

end.
kye_jufei 2011-02-09
  • 打赏
  • 举报
回复
implementation 

function TIEEvents._AddRef: Integer;
begin

// No more than 2 counts
result := 2;

end;

function TIEEvents._Release: Integer;
begin
// Always maintain 1 ref count (component holds the ref count)
result := 1;
end;

function TIEEvents.QueryInterface(const IID: TGUID; out Obj): HResult;
begin
// Clear interface pointer
Pointer(Obj) := nil;

// Attempt to get the requested interface
if (GetInterface(IID, Obj)) then
// Success
result := S_OK
// Check to see if the guid requested is for the event
else if (IsEqualIID(IID, FSinkIID)) then
begin
// Event is dispatch based, so get dispatch interface (closest we can come)
if (GetInterface(IDispatch, Obj)) then
// Success
result := S_OK
else
// Failure
result := E_NOINTERFACE;
end
else
// Failure
result := E_NOINTERFACE;
end;

function TIEEvents.GetIDsOfNames(const IID: TGUID; Names: Pointer; NameCount,
LocaleID: Integer; DispIDs: Pointer): HResult;
begin
// Not implemented
result := E_NOTIMPL;
end;

function TIEEvents.GetTypeInfo(Index, LocaleID: Integer; out TypeInfo): HResult;
begin
// Clear the result interface
Pointer(TypeInfo) := nil;
// No type info for our interface
result := E_NOTIMPL;
end;

function TIEEvents.GetTypeInfoCount(out Count: Integer): HResult;
begin
// Zero type info counts
Count := 0;
// Return success
result := S_OK;
end;

function TIEEvents.Invoke(DispID: Integer; const IID: TGUID; LocaleID: Integer; Flags: Word;
var Params; VarResult, ExcepInfo, ArgErr: Pointer): HResult;
var pdpParams: PDispParams;
lpDispIDs: array[0..63] of TDispID;
dwCount: Integer;
begin

// Get the parameters
pdpParams := @Params;

// Events can only be called with method dispatch, not property get/set
if ((Flags and DISPATCH_METHOD) > 0) then
begin
// Clear DispID list
ZeroMemory(@lpDispIDs, SizeOf(lpDispIDs));
// Build dispatch ID list to handle named args
if (pdpParams^.cArgs > 0) then
begin
// Reverse the order of the params because they are backwards
for dwCount := 0 to Pred(pdpParams^.cArgs) do lpDispIDs[dwCount] := Pred(pdpParams^.cArgs) - dwCount;
// Handle named arguments
if (pdpParams^.cNamedArgs > 0) then
begin
for dwCount := 0 to Pred(pdpParams^.cNamedArgs) do
lpDispIDs[pdpParams^.rgdispidNamedArgs^[dwCount]] := dwCount;
end;
end;
// Unless the event falls into the "else " clause of the case statement the result is S_OK
result := S_OK;
// Handle the event
case DispID of
102: DoStatusTextChange(pdpParams^.rgvarg^[lpDispIds[0]].bstrval);
104: DoDownloadComplete;
105: DoCommandStateChange(pdpParams^.rgvarg^[lpDispIds[0]].lval,
pdpParams^.rgvarg^[lpDispIds[1]].vbool);
106: DoDownloadBegin;
108: DoProgressChange(pdpParams^.rgvarg^[lpDispIds[0]].lval,
pdpParams^.rgvarg^[lpDispIds[1]].lval);
112: DoPropertyChange(pdpParams^.rgvarg^[lpDispIds[0]].bstrval);
113: DoTitleChange(pdpParams^.rgvarg^[lpDispIds[0]].bstrval);
250: DoBeforeNavigate2(IDispatch(pdpParams^.rgvarg^[lpDispIds[0]].dispval),
POleVariant(pdpParams^.rgvarg^[lpDispIds[1]].pvarval)^,
POleVariant(pdpParams^.rgvarg^[lpDispIds[2]].pvarval)^,
POleVariant(pdpParams^.rgvarg^[lpDispIds[3]].pvarval)^,
POleVariant(pdpParams^.rgvarg^[lpDispIds[4]].pvarval)^,
POleVariant(pdpParams^.rgvarg^[lpDispIds[5]].pvarval)^,
pdpParams^.rgvarg^[lpDispIds[6]].pbool^);
251: DoNewWindow2(IDispatch(pdpParams^.rgvarg^[lpDispIds[0]].pdispval^),
pdpParams^.rgvarg^[lpDispIds[1]].pbool^);
252: DoNavigateComplete2(IDispatch(pdpParams^.rgvarg^[lpDispIds[0]].dispval),
POleVariant(pdpParams^.rgvarg^[lpDispIds[1]].pvarval)^);
253:
begin
// Special case handler. When Quit is called, IE is going away so we might
// as well unbind from the interface by calling disconnect.
DoOnQuit;
// Call disconnect
Disconnect;
end;
254: DoOnVisible(pdpParams^.rgvarg^[lpDispIds[0]].vbool);
255: DoOnToolBar(pdpParams^.rgvarg^[lpDispIds[0]].vbool);
256: DoOnMenuBar(pdpParams^.rgvarg^[lpDispIds[0]].vbool);
257: DoOnStatusBar(pdpParams^.rgvarg^[lpDispIds[0]].vbool);
258: DoOnFullScreen(pdpParams^.rgvarg^[lpDispIds[0]].vbool);
259: DoDocumentComplete(IDispatch(pdpParams^.rgvarg^[lpDispIds[0]].dispval),
POleVariant(pdpParams^.rgvarg^[lpDispIds[1]].pvarval)^);
260: DoOnTheaterMode(pdpParams^.rgvarg^[lpDispIds[0]].vbool);
else
// Have to idea of what event they are calling
result := DISP_E_MEMBERNOTFOUND;
end;
end
else
// Called with wrong flags
result := DISP_E_MEMBERNOTFOUND;
end;
kye_jufei 2011-02-09
  • 打赏
  • 举报
回复
unit   IEEvents; 

interface

uses
Windows, SysUtils, Classes, Graphics, ComObj, ActiveX, SHDocVW;

type
// Event types exposed from the Internet Explorer interface
TIEStatusTextChangeEvent = procedure(Sender: TObject; const Text: WideString) of object;
TIEProgressChangeEvent = procedure(Sender: TObject; Progress: Integer; ProgressMax: Integer) of object;
TIECommandStateChangeEvent = procedure(Sender: TObject; Command: Integer; Enable: WordBool) of object;
TIEDownloadBeginEvent = procedure(Sender: TObject) of object;
TIEDownloadCompleteEvent = procedure(Sender: TObject) of object;
TIETitleChangeEvent = procedure(Sender: TObject; const Text: WideString) of object;
TIEPropertyChangeEvent = procedure(Sender: TObject; const szProperty: WideString) of object;
TIEBeforeNavigate2Event = procedure(Sender: TObject; const pDisp: IDispatch;
var URL: OleVariant; var Flags: OleVariant; var TargetFrameName: OleVariant;
var PostData: OleVariant; var Headers: OleVariant; var Cancel: WordBool) of object;
TIENewWindow2Event = procedure(Sender: TObject; var ppDisp: IDispatch; var Cancel: WordBool) of object;
TIENavigateComplete2Event = procedure(Sender: TObject; const pDisp: IDispatch; var URL: OleVariant) of object;
TIEDocumentCompleteEvent = procedure(Sender: TObject; const pDisp: IDispatch; var URL: OleVariant) of object;
TIEOnQuitEvent = procedure(Sender: TObject) of object;
TIEOnVisibleEvent = procedure(Sender: TObject; Visible: WordBool) of object;
TIEOnToolBarEvent = procedure(Sender: TObject; ToolBar: WordBool) of object;
TIEOnMenuBarEvent = procedure(Sender: TObject; MenuBar: WordBool) of object;
TIEOnStatusBarEvent = procedure(Sender: TObject; StatusBar: WordBool) of object;
TIEOnFullScreenEvent = procedure(Sender: TObject; FullScreen: WordBool) of object;
TIEOnTheaterModeEvent = procedure(Sender: TObject; TheaterMode: WordBool) of object;

// Event component for Internet Explorer
TIEEvents = class(TComponent, IUnknown, IDispatch)
private
// Private declarations
FConnected: Boolean;
FCookie: Integer;
FCP: IConnectionPoint;
FSinkIID: TGuid;
FSource: IWebBrowser2;
FStatusTextChange: TIEStatusTextChangeEvent;
FProgressChange: TIEProgressChangeEvent;
FCommandStateChange: TIECommandStateChangeEvent;
FDownloadBegin: TIEDownloadBeginEvent;
FDownloadComplete: TIEDownloadCompleteEvent;
FTitleChange: TIETitleChangeEvent;
FPropertyChange: TIEPropertyChangeEvent;
FBeforeNavigate2: TIEBeforeNavigate2Event;
FNewWindow2: TIENewWindow2Event;
FNavigateComplete2: TIENavigateComplete2Event;
FDocumentComplete: TIEDocumentCompleteEvent;
FOnQuit: TIEOnQuitEvent;
FOnVisible: TIEOnVisibleEvent;
FOnToolBar: TIEOnToolBarEvent;
FOnMenuBar: TIEOnMenuBarEvent;
FOnStatusBar: TIEOnStatusBarEvent;
FOnFullScreen: TIEOnFullScreenEvent;
FOnTheaterMode: TIEOnTheaterModeEvent;
protected
// Protected declaratios for IUnknown
function QueryInterface(const IID: TGUID; out Obj): HResult; override;
function _AddRef: Integer; stdcall;
function _Release: Integer; stdcall;
// Protected declaratios for IDispatch
function GetIDsOfNames(const IID: TGUID; Names: Pointer; NameCount, LocaleID:
Integer; DispIDs: Pointer): HResult; virtual; stdcall;
function GetTypeInfo(Index, LocaleID: Integer; out TypeInfo): HResult; virtual; stdcall;
function GetTypeInfoCount(out Count: Integer): HResult; virtual; stdcall;
function Invoke(DispID: Integer; const IID: TGUID; LocaleID: Integer;
Flags: Word; var Params; VarResult, ExcepInfo, ArgErr: Pointer): HResult; virtual; stdcall;
// Protected declarations
procedure DoStatusTextChange(const Text: WideString); safecall;
procedure DoProgressChange(Progress: Integer; ProgressMax: Integer); safecall;
procedure DoCommandStateChange(Command: Integer; Enable: WordBool); safecall;
procedure DoDownloadBegin; safecall;
procedure DoDownloadComplete; safecall;
procedure DoTitleChange(const Text: WideString); safecall;
procedure DoPropertyChange(const szProperty: WideString); safecall;
procedure DoBeforeNavigate2(const pDisp: IDispatch; var URL: OleVariant;
var Flags: OleVariant; var TargetFrameName: OleVariant; var PostData: OleVariant;
var Headers: OleVariant; var Cancel: WordBool); safecall;
procedure DoNewWindow2(var ppDisp: IDispatch; var Cancel: WordBool); safecall;
procedure DoNavigateComplete2(const pDisp: IDispatch; var URL: OleVariant); safecall;
procedure DoDocumentComplete(const pDisp: IDispatch; var URL: OleVariant); safecall;
procedure DoOnQuit; safecall;
procedure DoOnVisible(Visible: WordBool); safecall;
procedure DoOnToolBar(ToolBar: WordBool); safecall;
procedure DoOnMenuBar(MenuBar: WordBool); safecall;
procedure DoOnStatusBar(StatusBar: WordBool); safecall;
procedure DoOnFullScreen(FullScreen: WordBool); safecall;
procedure DoOnTheaterMode(TheaterMode: WordBool); safecall;
public
// Public declarations
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure ConnectTo(Source: IWebBrowser2);
procedure Disconnect;
property SinkIID: TGuid read FSinkIID;
property Source: IWebBrowser2 read FSource;
published
// Published declarations
property WebObj: IWebBrowser2 read FSource;
property Connected: Boolean read FConnected;
property StatusTextChange: TIEStatusTextChangeEvent read FStatusTextChange write FStatusTextChange;
property ProgressChange: TIEProgressChangeEvent read FProgressChange write FProgressChange;
property CommandStateChange: TIECommandStateChangeEvent read FCommandStateChange write FCommandStateChange;
property DownloadBegin: TIEDownloadBeginEvent read FDownloadBegin write FDownloadBegin;
property DownloadComplete: TIEDownloadCompleteEvent read FDownloadComplete write FDownloadComplete;
property TitleChange: TIETitleChangeEvent read FTitleChange write FTitleChange;
property PropertyChange: TIEPropertyChangeEvent read FPropertyChange write FPropertyChange;
property BeforeNavigate2: TIEBeforeNavigate2Event read FBeforeNavigate2 write FBeforeNavigate2;
property NewWindow2: TIENewWindow2Event read FNewWindow2 write FNewWindow2;
property NavigateComplete2: TIENavigateComplete2Event read FNavigateComplete2 write FNavigateComplete2;
property DocumentComplete: TIEDocumentCompleteEvent read FDocumentComplete write FDocumentComplete;
property OnQuit: TIEOnQuitEvent read FOnQuit write FOnQuit;
property OnVisible: TIEOnVisibleEvent read FOnVisible write FOnVisible;
property OnToolBar: TIEOnToolBarEvent read FOnToolBar write FOnToolBar;
property OnMenuBar: TIEOnMenuBarEvent read FOnMenuBar write FOnMenuBar;
property OnStatusBar: TIEOnStatusBarEvent read FOnStatusBar write FOnStatusBar;
property OnFullScreen: TIEOnFullScreenEvent read FOnFullScreen write FOnFullScreen;
property OnTheaterMode: TIEOnTheaterModeEvent read FOnTheaterMode write FOnTheaterMode;
end;

// Register procedure
procedure Register;
xushan123456 2011-02-09
  • 打赏
  • 举报
回复
不仅仅针对IE 所以BHO 排除掉了 要兼容所有浏览器 所以用TShellWindows

对这个类不是很熟悉.. 用起来经常出错.. 出错一次 重新运行程序 获取出来的数目就不对头了
xushan123456 2011-02-09
  • 打赏
  • 举报
回复
procedure Tform1.GetUrl;
var
I: Integer;
Browser: IWebBrowser2;
sw : TShellWindows ;
begin


sw := TShellWindows.Create(Application);
ShowMessage(IntToStr(sw.Count));
try
for i := 0 to sw.Count - 1 do
begin
Browser := sw.Item(i) as IWebBrowser2;
ShowMessage(Browser.LocationURL) ;
if Pos('baidu.com',Browser.LocationURL)>0 then
begin
ShowMessage('have it!');
end;
end;
except
ShowMessage('Erro!');
sw.Destroy;
end;
sw.Destroy;
end;



谁帮我改改吧.暂时还没能解决问题 我在等等 ...
gyk120 2011-02-08
  • 打赏
  • 举报
回复
winsock抓包,或者你用BHO直接绑到IE上,实时获取……
bdmh 2011-02-08
  • 打赏
  • 举报
回复
那只能通过线程不断地创建TShellWindows,来获取最新的列表,并判断xWin.Item[i]是否可用

另外你可以通过抓包的方法,来获取网络访问的网址,来判断
fisher_older 2011-02-08
  • 打赏
  • 举报
回复
楼上回答得不错。不过怎么才能实现监控呢?用按钮显然没有达到目的。
xushan123456 2011-02-08
  • 打赏
  • 举报
回复
2楼 代码你这代码我知道 ... 看清问题.. 就是获取连接 有时候 获取不出来 .为什么! 用一个循环来换取.一直到发现 有指定URL 出现 . 但是很多突然状况.比如突然关闭浏览器 都会导致错误./然后在获取时候 连接数目就不对头了 . 你自己多测试测试看就知道了
kye_jufei 2011-02-08
  • 打赏
  • 举报
回复
100分有點少。。。


unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,SHDocVw;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
xWin:TShellWindows;
i:integer;
begin
xWin:=TShellWindows.Create(nil);
for i:=0 to xWin.count -1 do
begin
//showmessage(xWin.Item[i].LocaltionURL);
showmessage((xwin.Item(i) as IWebBrowser2).LocationURL);
end;
xwin.Free;
end;

end.

1,183

社区成员

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

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