您的位置:首页 > 编程语言 > Delphi

Delphi截获webbrowser中关闭及右键消息处理一例

2016-06-15 21:12 561 查看
procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean);

var

setINI: Tinifile;

oldPoint, newPoint: TPOINT;

begin

  if Msg.message = WM_CLOSE then {//判断是否关闭消息}  begin

    if Msg.HWND = Form1.handle then Form1.Close;

    if Msg.HWND = Form1.WebBrowser2.handle then begin //验证消息是否WebBrowser发来的

      Form1.WebBrowser2.Navigate('about:blank');

      Form1.HomePage.ActivePageIndex := 0;

    end;

    Handled := true;

  end;

  //如果是Webbrowser,则不许使用右键菜单

  if IsChild(Form1.WebBrowser2.handle, Msg.HWND) and ((Msg.message = WM_RBUTTONDOWN) or (Msg.message = WM_RBUTTONUP)) then begin

    GetCursorPos(oldPoint); //保存当前鼠标位置。

    Form1.edtx.Text := IntToStr(oldPoint.X);

    Form1.edty.Text := IntToStr(oldPoint.Y);

    //鼠标位置写到配置文件

    setINI := Tinifile.Create(GetCurDir + 'renyuansoft.ini');

    setINI.WriteInteger('SET', 'x1', strtoint(Form1.edtx.Text));

    setINI.WriteInteger('SET', 'y1', strtoint(Form1.edty.Text));

    x1 := strtoint(Form1.edtx.Text);

    y1 := strtoint(Form1.edty.Text);

    setINI.Free;

    Handled := true;

  end;

end;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: