如何用鼠标拖动页面中的连接就能打开一个新窗口浏览?像myie2那样。
还有如何获取收藏夹中的内容并添加到mainmenu中?谢谢!!!

解决方案 »

  1.   

    还有如何能在newwindow2之前获得url?
      

  2.   

    第二个问题暂时没有解决办法。我自己通过编写一个 TOleServer 继承类 THTMLDocument 的方式来捕捉所以的事件,根据这些事件,可以很方便完成拖放等自定义操作。由于时间问题,暂时只完成部分事件的捕捉,其他的类同(很方便加入的,事件的 DispID 请见了 MSHTML.pas),供参考,使用的时候 ConnectTo 到 WebBrowser 的 Document (必须先加载文档)。type
      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;
      

  3.   

    确实这个类还不算很完整,如事件不全、还有对事件指针的情况判断不全,比较完整的例子见:http://community.csdn.net/Expert/topic/3267/3267026.xml?temp=.3797876。
    这个类在我自己的计算机上调试都正常(一台是 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));
    //注:只要连接一次就可以了,以后就会把所有的事件都关联上了。