我用了如下代码,可不能实现。
类部分:
TWebB = class(Twebbrowser)
private
{ Private declarations } protected
{ Protected declarations }
public
function DragEnter(const dataObj: IDataObject; grfKeyState: Longint;pt: TPoint; var dwEffect: Longint): HResult; stdcall;
function DragOver(grfKeyState: Longint; pt: TPoint;var dwEffect: Longint): HResult; stdcall;
function DragLeave: HResult; stdcall;
function Drop(const dataObj: IDataObject; grfKeyState: Longint; pt: TPoint;var dwEffect: Longint): HResult; stdcall;
程序部分
var web1:tweb;
form1.FormCreate
begin
web:=tweb.create(nil);
OleInitialize(NIL);
RegisterDragDrop(web.Handle, IDropTarget(web));
end;
类部分:
TWebB = class(Twebbrowser)
private
{ Private declarations } protected
{ Protected declarations }
public
function DragEnter(const dataObj: IDataObject; grfKeyState: Longint;pt: TPoint; var dwEffect: Longint): HResult; stdcall;
function DragOver(grfKeyState: Longint; pt: TPoint;var dwEffect: Longint): HResult; stdcall;
function DragLeave: HResult; stdcall;
function Drop(const dataObj: IDataObject; grfKeyState: Longint; pt: TPoint;var dwEffect: Longint): HResult; stdcall;
程序部分
var web1:tweb;
form1.FormCreate
begin
web:=tweb.create(nil);
OleInitialize(NIL);
RegisterDragDrop(web.Handle, IDropTarget(web));
end;
虽然是监视复制粘贴的,但是理论上对拖放也应该有效
// Put this Code at the end of your unit:initialization
OleInitialize(nil);finalization
OleUninitialize;
或许你应该找找用Delphi开发,使用IE控件的代码
D:\Program Files\Borland\Delphi7\Demos\Ipcdemos
THTMLDocumentEvent = procedure (Sender: TObject; const pEvtObj:
IHTMLEventObj) of object; THTMLDocument = class(TOleServer)
private
FIntf: IHTMLDocument2;
FOnClick: THTMLDocumentEvent;
FOnMouseMove: THTMLDocumentEvent;
function GetDefaultInterface: IHTMLDocument2;
protected
procedure InitServerData; override;
procedure InvokeEvent(DispID: TDispID; var Params: TVariantArray); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Connect; override;
procedure ConnectTo(svrIntf: IHTMLDocument2);
procedure Disconnect; override;
property DefaultInterface: IHTMLDocument2 read GetDefaultInterface;
published
property OnClick: THTMLDocumentEvent read FOnClick write FOnClick;
property OnMouseMove: THTMLDocumentEvent read FOnMouseMove write
FOnMouseMove;
end;{
******************************** THTMLDocument *********************************
}
constructor THTMLDocument.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
end;destructor THTMLDocument.Destroy;
begin
inherited Destroy;
end;procedure THTMLDocument.Connect;
var
punk: IUnknown;
begin
if FIntf = nil then
begin
punk := GetServer;
ConnectEvents(punk);
FIntf:= punk as IHTMLDocument2;
end;
end;procedure THTMLDocument.ConnectTo(svrIntf: IHTMLDocument2);
begin
Disconnect;
FIntf := svrIntf;
ConnectEvents(FIntf);
end;procedure THTMLDocument.Disconnect;
begin
if FIntf <> nil then
begin
DisconnectEvents(FIntf);
FIntf := nil;
end;
end;function THTMLDocument.GetDefaultInterface: IHTMLDocument2;
begin
if FIntf = nil then
Connect;
Assert(FIntf <> nil, 'DefaultInterface is NULL. Component is not connected to Server. You must call ''Connect'' or ''ConnectTo'' before this operation');
Result := FIntf;
end;procedure THTMLDocument.InitServerData;
const
CServerData: TServerData = (
ClassID: '{25336920-03F9-11CF-8FD0-00AA00686F13}';
IntfIID: '{332C4425-26CB-11D0-B483-00C04FD90119}';
EventIID: '{3050F613-98B5-11CF-BB82-00AA00BDCE0B}';
LicenseKey: nil;
Version: 500);
begin
ServerData := @CServerData;
end;procedure THTMLDocument.InvokeEvent(DispID: TDispID; var Params: TVariantArray);
var
pDisp: IDispatch;
pEventObj: IHTMLEventObj;
begin
if DispID = -1 then Exit;
pDisp := Params[0];
if pDisp.QueryInterface(IHTMLEventObj, pEventObj) <> 0 then Exit;
case DispID of
-1: Exit; // DISPID_UNKNOWN
-600: if Assigned(FOnClick) then
FOnClick(Self, pEventObj);
-606: if Assigned(FOnMouseMove) then
FOnMouseMove(Self, pEventObj);
end;
end;
可该如何使用THTMLDocument类呢?(如何让THEMLDocument和TWEBBROWSER关联)
这个类在我自己的计算机上调试都正常(一台是 2000,一台是 XP,IE都是 6.0),而且已经在程序里使用了。有个网友说在 IE 5.0 不行,会提示出错,确实我自己没有试过。关于这个类的编写,大家可以定义 TWebBrowser,其中的类:TInternetExplorer,就很类似,我就是参考这个写出来的。使用办法就是(我已经把这个类编译成组件了):WebBrowser1.Navigate('about:blank');
while WebBrowser1.ReadyState <> READYSTATE_COMPLETE do
Application.ProcessMessages;
HTMLDocument1.ConnectTo(ITHMLDocument2(WebBrowser1.Document));
//注:只要连接一次就可以了,以后就会把所有的事件都关联上了。