微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐