耗脑细胞无数,终于搞定,呵呵。 用DDE: //URL:string; DDE.ServiceApplication:='iexplore'; if DDE.SetLink('iexplore','www_GetWindowInfo') then URL:=DDE.RequestData('1,0'); Label1.Caption:=URL;
//uses DDEManprocedure TForm1.Button1Click(Sender: TObject); var DDE:TDdeClientConv; begin DDE:=TDdeClientConv.Create(self); if DDE.SetLink('IExplore','WWW_GetWindowInfo') then Label1.Caption:=DDE.RequestData('0xFFFFFFFF,sURL,sTitle') else ShowMessage('IE is not running'); DDE.Free; end;
需要使用SHDocVW.pas,代码如下:unit Unit1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,ShdocVW, StdCtrls;type TForm1 = class(TForm) Button1: TButton; ListBox1: TListBox; ListBox2: TListBox; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject); var xs:IShellWindows; ib:IWebbrowser2; i:Integer; begin xs:=CoShellWindows.Create; for i:=0 to xs.Count -1 do begin ib:=xs.Item(i) as IWebbrowser2; ListBox1.Items.Add(ib.LocationURL); ListBox2.Items.Add(ib.LocationName); end; end;end. 引用ShdocVW,建立一个IShellWindows对象,访问其中的成员就可以了。
用GetActiveWindow()可以取得当前活动的窗口句柄,配合EnumWindow或者FindWindow即可,如果句柄相等,就是活动的IE了,然后GetWindowText() OR Senmessage(h,wm_gettext,.....)都可以取得Title,取得IE地址就麻烦一点儿。
还没给分我就来给个详解: function GetIEFromHWND(WHandle: HWND; var IE: IWebbrowser2): HRESULT; var hInst: HWND; lRes: Cardinal; MSG: Integer; pDoc: IHTMLDocument2; ObjectFromLresult: TObjectFromLresult; begin hInst := LoadLibrary('Oleacc.dll'); @ObjectFromLresult := GetProcAddress(hInst, 'ObjectFromLresult'); if @ObjectFromLresult <> nil then begin try MSG := RegisterWindowMessage('WM_HTML_GETOBJECT'); SendMessageTimeOut(WHandle, MSG, 0, 0, SMTO_ABORTIFHUNG, 1000, lRes); Result := ObjectFromLresult(lRes, IHTMLDocument2, 0, pDoc); if Result = S_OK then (pDoc.parentWindow as IServiceprovider).QueryService(IWebbrowserApp, IWebbrowser2, IE); finally FreeLibrary(hInst); end; end; end; procedure GetIE(var IE: IWebbrowser2); var Wnd: HWND; WndChild: HWND; x: Olevariant; vaClsID, vaEnabled, vaDummy: Olevariant; begin Wnd := FindWindow('IEFrame', nil); //wnd:=GetForegroundWindow; if Wnd = 0 then begin exit; end; WndChild := FindWindowEX(Wnd, 0, 'Shell DocObject View', nil); if WndChild <> 0 then begin WndChild := FindWindowEX(WndChild, 0, 'Internet Explorer_Server', nil); if WndChild <> 0 then begin GetIEFromHWnd(WndChild, ie); ShowMessage(ie.LocalUrl); end; end; end;
Lin(林),你给的地址是个英文网站 呀,没中文的吗我的英文不行 All Products | Support | Search | microsoft.com Guide Home | Magazines | Libraries | Developer Centers | Resources | Downloads | Code | Search MSDN |-------------------------------------------------------------------------------- Downloads MS Product Catalog Microsoft Accessibility-------------------------------------------------------------------------------- Server Products Developer Tools Office Family Windows Family MSN-------------------------------------------------------------------------------- Knowledge Base Product Support Options Service Partner Referrals Year 2000 Compliance-------------------------------------------------------------------------------- Search microsoft.com MSN Web Search-------------------------------------------------------------------------------- microsoft.com Home MSN Home-------------------------------------------------------------------------------- Contact Us Events Newsletters Profile Center Training & Certification Free E-mail Account-------------------------------------------------------------------------------- Voices MSDN Magazine MSJ MIND MSDN Newspaper .NET Show-------------------------------------------------------------------------------- MSDN Library Web Workshop Code Center Downloads-------------------------------------------------------------------------------- BizTalk Server Commerce Server DirectX E-Business Internet Explorer .NET Framework & Tools Office SQL Server Visual Studio Web Services Windows XML
More...-------------------------------------------------------------------------------- Bug Center DLL Help Database Support Newsgroups Members Helping Members User Groups Chats Training Events Developer Books Component Resources
那个站点我也没法上!!!
[email protected]
用DDE: //URL:string;
DDE.ServiceApplication:='iexplore';
if DDE.SetLink('iexplore','www_GetWindowInfo') then
URL:=DDE.RequestData('1,0');
Label1.Caption:=URL;
比如我现打开多个IE,想取得当前所选择的IE的URL该如何做?
var
DDE:TDdeClientConv;
begin
DDE:=TDdeClientConv.Create(self);
if DDE.SetLink('IExplore','WWW_GetWindowInfo') then
Label1.Caption:=DDE.RequestData('0xFFFFFFFF,sURL,sTitle')
else
ShowMessage('IE is not running');
DDE.Free;
end;
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,ShdocVW,
StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
ListBox2: TListBox;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
var
xs:IShellWindows;
ib:IWebbrowser2;
i:Integer;
begin
xs:=CoShellWindows.Create;
for i:=0 to xs.Count -1 do begin
ib:=xs.Item(i) as IWebbrowser2;
ListBox1.Items.Add(ib.LocationURL);
ListBox2.Items.Add(ib.LocationName);
end;
end;end.
引用ShdocVW,建立一个IShellWindows对象,访问其中的成员就可以了。
function GetIEFromHWND(WHandle: HWND; var IE: IWebbrowser2): HRESULT;
var
hInst: HWND;
lRes: Cardinal;
MSG: Integer;
pDoc: IHTMLDocument2;
ObjectFromLresult: TObjectFromLresult;
begin
hInst := LoadLibrary('Oleacc.dll');
@ObjectFromLresult := GetProcAddress(hInst, 'ObjectFromLresult');
if @ObjectFromLresult <> nil then begin
try
MSG := RegisterWindowMessage('WM_HTML_GETOBJECT');
SendMessageTimeOut(WHandle, MSG, 0, 0, SMTO_ABORTIFHUNG, 1000, lRes);
Result := ObjectFromLresult(lRes, IHTMLDocument2, 0, pDoc);
if Result = S_OK then
(pDoc.parentWindow as IServiceprovider).QueryService(IWebbrowserApp, IWebbrowser2, IE);
finally
FreeLibrary(hInst);
end;
end;
end;
procedure GetIE(var IE: IWebbrowser2);
var
Wnd: HWND;
WndChild: HWND;
x: Olevariant;
vaClsID, vaEnabled, vaDummy: Olevariant;
begin
Wnd := FindWindow('IEFrame', nil);
//wnd:=GetForegroundWindow;
if Wnd = 0 then
begin
exit;
end;
WndChild := FindWindowEX(Wnd, 0, 'Shell DocObject View', nil);
if WndChild <> 0 then begin
WndChild := FindWindowEX(WndChild, 0, 'Internet Explorer_Server', nil);
if WndChild <> 0 then
begin
GetIEFromHWnd(WndChild, ie);
ShowMessage(ie.LocalUrl);
end;
end;
end;
All Products | Support | Search | microsoft.com Guide Home | Magazines | Libraries | Developer Centers | Resources | Downloads | Code | Search MSDN |--------------------------------------------------------------------------------
Downloads
MS Product Catalog
Microsoft Accessibility--------------------------------------------------------------------------------
Server Products
Developer Tools
Office Family
Windows Family
MSN--------------------------------------------------------------------------------
Knowledge Base
Product Support Options
Service Partner Referrals
Year 2000 Compliance--------------------------------------------------------------------------------
Search microsoft.com
MSN Web Search--------------------------------------------------------------------------------
microsoft.com Home
MSN Home--------------------------------------------------------------------------------
Contact Us
Events
Newsletters
Profile Center
Training & Certification
Free E-mail Account--------------------------------------------------------------------------------
Voices
MSDN Magazine
MSJ
MIND
MSDN Newspaper
.NET Show--------------------------------------------------------------------------------
MSDN Library
Web Workshop
Code Center
Downloads--------------------------------------------------------------------------------
BizTalk Server
Commerce Server
DirectX
E-Business
Internet Explorer
.NET Framework & Tools
Office
SQL Server
Visual Studio
Web Services
Windows
XML
More...--------------------------------------------------------------------------------
Bug Center
DLL Help Database
Support
Newsgroups
Members Helping Members
User Groups
Chats
Training
Events
Developer Books
Component Resources
show toc sync toc index
Web Workshop | Reusing Browser Technology
Browser Extensions --------------------------------------------------------------------------------Browser extensions, introduced in Microsoft® Internet Explorer 5, allow developers to add functionality to the browser and enhance the user interface.Overviews/TutorialsAdding Explorer Bars This tutorial explains how to add an Explorer Bar in Internet Explorer.
Adding Menu Items This tutorial explains how to add a menu item that runs a Microsoft® Windows® application or that runs a script to the Tools menu or Help menu in Internet Explorer.
Adding Toolbar Buttons This tutorial explains how to add a toolbar button to the Internet Explorer user interface.
Browser Extensions Browser extensions allow developers to provide easy access to their browser enhancements by adding elements (like an Explorer Bar) to the default user interface. Introduced in Internet Explorer 4.0, this feature enables developers to create Explorer Bars and add entries into the standard context menus. Beginning with Internet Explorer 5, this feature allows developers to add entries into the Tools menu and buttons to the toolbar.
Creating Custom Explorer Bars, Tool Bands, and Desk Bands The Explorer Bar was introduced with Internet Explorer 4.0 to provide a display area adjacent to the browser pane. It is basically a child window within the Internet Explorer window, and it can be used to display information and interact with the user in much the same way. Explorer Bars are most commonly displayed as a vertical pane on the left-hand side of the browser pane. However, an Explorer Bar can also be displayed horizontally, below the browser pane.
Customizing the Browser Toolbar This tutorial explains how to customize the appearance of the toolbar area in Internet Explorer.
Explorer Bar Style Guide This guide will help you design Explorer Bars to add to the Microsoft®Internet Explorer user interface.
Toolbar Button Style Guide This guide will help you design icons for toolbar buttons that you add to the Internet Explorer user interface.
Web Accessories Web Accessories are browser enhancements that any developer can create using browser extensions. Users can then add these Web Accessories to their copy of Internet Explorer. By creating Web Accessories, developers have a very powerful way to enable new features and functionality. MethodsGetBandInfo Retrieves the information for a band object. InterfacesIDeskBand IDeskBand is used to obtain information about a band object. See the Creating Custom Explorer Bars, Tool Bands, and Desk Bands article for more information about band objects. StructuresDESKBANDINFO Contains and receives information for a band object. This structure is used with the IDeskBand::GetBandInfo method. Back to top
Did you find this topic useful? Suggestions for other topics? Write us!
© 2001 Microsoft Corporation. All rights reserved. Terms of use.
。