zoukankan      html  css  js  c++  java
  • 给TWebBrowser添加鼠标事件

    学习用IsChild(WebBrowser1.Handle,   Msg.Hwnd)判断鼠标事件是否来自TWebBrowser

    unit   Unit1;
    interface
    uses
        Windows,   Messages,   SysUtils,   Variants,   Classes,   Graphics,   Controls,   Forms,
        Dialogs,   OleCtrls,   SHDocVw,   StdCtrls,   MSHTML;
    type
        TForm1   =   class(TForm)
            WebBrowser1:   TWebBrowser;
            procedure   FormCreate(Sender:   TObject);
            procedure   WebBrowser1DocumentComplete(Sender:   TObject;
                const   pDisp:   IDispatch;   var   URL:   OleVariant);
        private
            {   Private   declarations   }
            FLoaded:   Boolean;
            procedure   AppMsg(var   Msg:   TagMsg;   var   Handled:   Boolean);
            procedure   GetContronl;
        public
            {   Public   declarations   }
        end;
    var
        Form1:   TForm1;
    implementation
    {$R   *.dfm}
    procedure   TForm1.AppMsg(var   Msg:   TagMsg;   var   Handled:   Boolean);
    var
        mPoint   :   TPoint;
    begin
        if   IsChild(WebBrowser1.Handle,   Msg.Hwnd)   and
              (Msg.Message   =   WM_MOUSEMOVE)   and   FLoaded   then
        begin
            GetCursorPos(mPoint);
            GetContronl;
            //PopupMenu1.Popup(mPoint.X,   mPoint.Y);
            Handled:=True;
        end;
    end;
    procedure   TForm1.FormCreate(Sender:   TObject);
    begin
        FLoaded   :=   False;
        WebBrowser1.Navigate( 'http://www.kitop.com ');
        Application.OnMessage   :=   AppMsg;
    end;
    procedure   TForm1.GetContronl;
    var
        E:   IHTMLElement;
        tmpStr:   String;
        myPoint:   TPoint;
    begin
        myPoint   :=   Mouse.CursorPos;
        myPoint   :=   WebBrowser1.ScreenToClient(myPoint);
        {
        myPoint.X   :=   myPoint.X   +   100;
        myPoint.Y   :=   myPoint.Y   +   100;
        }
        E   :=   (WebBrowser1.Document   as   IHTMLDocument2).elementFromPoint(myPoint.X,   myPoint.Y);
        //E   :=   (WebBrowser1.Document   as   IHTMLDocument2).elementFromPoint(100,   100);
          //ShowMessage(E.title);
          tmpStr   :=   Format( '%s,%s,%s,%s;X:%d;Y:%d ',[E.className,E.id,E.tagName,E.innerHTML,
            myPoint.X,myPoint.Y]);
        Caption   :=   tmpStr;
    end;
    procedure   TForm1.WebBrowser1DocumentComplete(Sender:   TObject;
        const   pDisp:   IDispatch;   var   URL:   OleVariant);
    begin
        FLoaded   :=   True;
    end;
    end.

  • 相关阅读:
    完美数据迁移-MongoDB Stream的应用
    补习系列(3)-springboot中的几种scope
    补习系列(2)-springboot mime类型处理
    hdfs directory item limit
    git-format-patch
    SPARK-18560
    hdfs OutOfMemoryError
    hdfs 路径不支持‘:’
    java.io.UTFDataFormatException: encoded string too long:
    scala-maven-plugin excludes
  • 原文地址:https://www.cnblogs.com/delphi7456/p/1896632.html
Copyright © 2011-2022 走看看