如保获得外部IE内核浏览器的事件-仅有的60分 ( 积分: 60 )

  • 主题发起人 主题发起人 xawangting
  • 开始时间 开始时间
X

xawangting

Unregistered / Unconfirmed
GUEST, unregistred user!
这段代码中怎么样可以得到IE对象的事件,请高手指教
type
TObjectFromLResult = function(LRESULT: lResult; const IID: TIID; WPARAM: wParam; out pObject): HRESULT; stdcall;
//This function detects the Window
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;

如果成功,我分全给。
 
这段代码中怎么样可以得到IE对象的事件,请高手指教
type
TObjectFromLResult = function(LRESULT: lResult; const IID: TIID; WPARAM: wParam; out pObject): HRESULT; stdcall;
//This function detects the Window
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;

如果成功,我分全给。
 
得到了IWebbrowser以后其他和BHO里面一样。这段代码表支持98。是MSDN里面来的。
 
给点代码提示吧,我是有点迷糊啊
 
先用上面的代码得到IWebBrowser2接口,然后
InterfaceConnect(IE, DWebBrowserEvents2, Self, FConnection);

IE就是 IWebBrowser2接口,self是任意一个实现了IDispatch接口的对象,Fconnection是记录这个连接点句柄单,找个整型保存起来,断开连接到时候要用。连接成功以后,所有时间都会激发IDisptach接口的Invoke方法。

InterfaceConnect的帮助如下
Unit

ComObj

Category

COM utilities

Delphi syntax:

procedure InterfaceConnect(const Source: IUnknown; const IID: TIID; const Sink: IUnknown; var Connection: Longint);

Description

Call InterfaceConnect from a client application to register an object that implements an outgoing server connection. Typically, this object is an event sink that a client uses to respond to server events. When an event occurs, the server (event source) calls its outgoing interface for the event, and the client, which implements the interface as an event sink, receives the call

InterfaceConnect obtains an IConnectionPoint interface from a COM server advising on a particular connection point. IConnectionPoint lets the server expose an outgoing interface for an object, typically an event sink. IConnectionPointContainer enumerates the connection points supported by the server, so that a caller can find the right connection point. The IConnectionPointContainer and IConnectionPoint interfaces comprise the standard COM event-handling mechanism.

Source is an IUnknown interface for the server object that defines and calls the outgoing interface.

IID is the GUID of the outgoing interface.

Sink is the IUnknown interface of the client object that implements the outgoing interface.

Connection returns a token that represents the connection. It must be saved for use by the InterfaceDisconnect procedure that is called to terminate the connection established by calling InterfaceConnect.

Note: A demo containing this procedure resides in Demos/ActiveX directory.
 
接受答案了.
 
后退
顶部