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

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;

转载于:https://my.oschina.net/renyuansoft/blog/692604

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值