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

来源:互联网 发布:个人理财产品 知乎 编辑:程序博客网 时间:2024/06/04 19:07
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;
0 0
原创粉丝点击