Ihtmledithost接口在DELPHI中实现后,怎样连接到Twebbrowser中去(在线等待) ( 积分: 100 )

  • 主题发起人 主题发起人 rjw
  • 开始时间 开始时间
R

rjw

Unregistered / Unconfirmed
GUEST, unregistred user!
Ihtmledithost接口在DELPHI中实现后,怎样连接到Twebbrowser中去,我查了一下,是要用到IServiceProvider接口的QueryService 方法,可该怎么做呢,请高手指教!!!
 
Ihtmledithost接口在DELPHI中实现后,怎样连接到Twebbrowser中去,我查了一下,是要用到IServiceProvider接口的QueryService 方法,可该怎么做呢,请高手指教!!!
 
着个问题怎么没人知道,是我问题太烂,还是分数太少,各为高人千万不要客气,灌水啊
 
灌水我会滴,关注很久了,就等楼主或这句话了[:D]
 
我想了解好你在DFW里精通这方面的好少
 
刚找了点资料,这个和楼主说的一样,需要通过IServiceProvider的QueryService

而在WebBrowser里面没有OnQueryService事件,所以只有通过它的其他事件,比如OnNewWindow2,设置它的ppDisp为楼主的IHTMLEditHost接口
下面是全文
http://www.euromind.com/iedelphi/HTMLEdit/HTMLEdit2.htm

IHTMLEditHost provides you a way to control how elements are resized and moved when the user grabs and drags the handles on a control element. For instance, you could cause an element to resize or move by specific increments (a snap-to-grid feature), limit resizing to a minimum or maximum size, or constrain the area to which an element can be moved.

Whenever the MSHTML Editor is activated, it looks to see if an IHTMLEditHost is available. The Editor first asks the host application for an IServiceProvider interface. If it finds IServiceProvider, it will query for an IHTMLEditHost interface pointer.

In EmbeddedWB you can use OnQueryService to connect TEditHost:

function TForm1.EmbeddedWB1QueryService(const rsid, iid: TGUID;
out Obj: IUnknown): HRESULT;
begin
Result := S_OK;
if
IsEqualGUID(rsid, SID_SHTMLEDitHost) and (ActiveDesigner <> nil)
then
obj := EditHost1
else
result := E_NOTIMPL;
end;


The IHTMLEditHost interface will remain active until the Editor is turned off or the WebBrowser navigates to a new page. At this point, the Editor releases its pointer to any IHTMLEditHost interface it holds.

TEditHost consists of one method, OnSnapRect. This method has three arguments:

pIElement: a pointer to an IHTMLElement interface for the element that is being moved or resized.
prcNew: a RECT which initially contains the element's size and position. Use this RECT to control how MSHTML resizes or moves the element.
eHandle: an ELEMENT_CORNER enumeration value. The ELEMENT_CORNER enumeration value tells you which handle the user has grabbed to resize the element, if any. If no handle has been grabbed—if eHandle is set to ELEMENT_CORNER_NONE—the element is being moved rather than resized.



The following code demonstrates how to process each of the nine ELEMENT_CORNER values:

function TForm1.EditHost1SnapRect(const pIElement: IHTMLElement;
var prcNew: tagRECT; eHandle: TOleEnum): HRESULT;
begin
case eHandle of
ELEMENT_CORNER_NONE: // Code for moving the element
ELEMENT_CORNER_TOP: // Code for resizing the element
ELEMENT_CORNER_LEFT: // Code for resizing the element
ELEMENT_CORNER_BOTTOM: // Code for resizing the element
ELEMENT_CORNER_RIGHT: // Code for resizing the element
ELEMENT_CORNER_TOPLEFT: // Code for resizing the element
ELEMENT_CORNER_TOPRIGHT: // Code for resizing the element
ELEMENT_CORNER_BOTTOMLEFT: // Code for resizing the element
ELEMENT_CORNER_BOTTOMRIGHT: // Code for resizing the element
end;
result := S_OK;
end;




Since IHTMLEditHost can't be "turned off" during the editing, TEditHost has a propery Enabled that can be turned on and off. If TEdithost is not Enabled the OnSnapRect Event is not called.

Edithost1.Enabled:=FALSE;

另外还有这个控件的代码
//***********************************************************
// TEdithost ver 1.00 (Jan. 14, 2000) *
// *
// For Delphi 4/5 *
// Freeware Component *
// by *
// Per Linds?Larsen *
// per.lindsoe@larsen.dk *
// *
// Documentation and updated versions: *
// *
// http://www.euromind.com/iedelphi *
//***********************************************************

unit Edithost;

interface

uses
mshtml_tlb, Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;



const

SID_SHTMLEditHost: TGUID = (D1: $3050F6A0; D2: $98B5; D3: $11CF; D4: ($BB, $82, $00, $AA, $00, $BD, $CE, $0B));


type


TSnapRect = function (const pIElement: IHTMLElement; var prcNew: tagRECT; eHandle: _ELEMENT_CORNER): HResult of object;

TEditHost = class(TComponent, IUnknown, IHTMLEditHost)
private
{ Private declarations }
FSnapRect : TSnapRect;
FEnabled : Boolean;
protected
{ Protected declarations }
function SnapRect(const pIElement: IHTMLElement; var prcNew: tagRECT; eHandle: _ELEMENT_CORNER): HResult; stdcall;
public
{ Public declarations }
published
{ Published declarations }
property OnSnapRect : TSnapRect read FSnapRect write FSnapRect;
property Enabled : Boolean read FEnabled write FEnabled;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Samples', [TEditHost]);
end;

{ TEditHost }

function TEditHost.SnapRect(const pIElement: IHTMLElement;
var prcNew: tagRECT; eHandle: _ELEMENT_CORNER): HResult;
begin
Result:=S_OK;
If Assigned(FSnapRect) and FEnabled then
Result:=FSnapRect(pIElement, prcNew, eHandle);
end;

end.

看看对楼主有帮助不,这种问题通常都是自己解决的
 
我试了一下,newWindow2事件只在打开新窗口时触发,实现Ihtmledithost接口的类的实例
不能转换为IDispatch接口,不能付给ppDisp
 
NewWindow2的方式,其实是TInternetExplorer的InvokeEvent2方法实现的,根据传入的参数决定使用哪个事件,也就是
251: if Assigned(FOnNewWindow2) then
FOnNewWindow2(Self, Params[0] (*var IDispatch*), Params[1] (*var WordBool*));

不知道这个东西怎么赋值过去,楼主看看我给你的哪个链接,多少应该有些帮助,这种问题比较少会有现成答案,楼主自己还需要多动些脑子


另:
楼主点击一下哪个订阅邮件的按钮,别人有回复就马上可以看到的
 
后退
顶部