学习 Message(5): 关于 TApplicationEvents.OnMessage 的第二个参数
2008-10-25 12:03
501 查看
TApplicationEvents.OnMessage 的第二个参数 Handled 如果是 True, 表示消息已经处理过了, 到此为止.
我们可以利用这个特性来屏蔽一些消息, 譬如给 TWebBrowser 屏蔽右键菜单:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, AppEvnts, StdCtrls; type TForm1 = class(TForm) Memo1: TMemo; ApplicationEvents1: TApplicationEvents; procedure ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean); procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean); begin if Msg.message = WM_LBUTTONDOWN then begin Memo1.Lines.Add('OnMessage'); Handled := False; {Handled 默认是 False, 这句可以省略} // Handled := True; {如果这样, 下面 OnMouseDown 事件将不会得到执行} end; end; procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin Memo1.Lines.Add('OnMouseDown'); end; end.
我们可以利用这个特性来屏蔽一些消息, 譬如给 TWebBrowser 屏蔽右键菜单:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, OleCtrls, SHDocVw, AppEvnts; type TForm1 = class(TForm) WebBrowser1: TWebBrowser; ApplicationEvents1: TApplicationEvents; procedure FormCreate(Sender: TObject); procedure ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean); end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean); begin if IsChild(WebBrowser1.Handle, Msg.hwnd) and (Msg.message = WM_RBUTTONDOWN) then begin Handled := True; end; end; procedure TForm1.FormCreate(Sender: TObject); begin WindowState := wsMaximized; WebBrowser1.Align := alTop; WebBrowser1.Navigate('http://www.cnblogs.com/del/'); end; end.
相关文章推荐
- 学习 Message(5): 关于 TApplicationEvents.OnMessage 的第二个参数 可以屏蔽 TWebBrowser右键菜单:
- 学习 Message(4): 通过 Application.OnMessage 或 TApplicationEvents 响应消息
- Application.OnMessage 或 TApplicationEvents 响应消息 (转自:万老师的博客)
- 学习官方示例 - TApplication.OnMessage
- 关于on_delete的参数错误
- 关于Application.DoEvents()(转载)
- 关于Metasploit-学习笔记-基础命令以及参数
- 关于Fragment懒加载的学习和使用+参数传递的方法
- 【乐视云学习笔记】关于Letv乐视云点播的视频暂停之后,按home回到桌面后重新onResume回到Activity,视频自动播放的情况
- 关于Ibatis.net ,将List<T> 作为参数的学习笔记
- 关于onActivityResult方法接收不到传递参数的问题
- 关于listen的第二个参数backlog的一些问答见解
- 通过 Application.OnMessage 响应消息
- 【Scikit-Learn 中文文档】模型选择:选择估计量及其参数 - 关于科学数据处理的统计学习教程 - scikit-learn 教程 | ApacheCN
- 关于Application.DoEvents()(转载)
- 【Scikit-Learn 中文文档】模型选择:选择估计量及其参数 - 关于科学数据处理的统计学习教程 - scikit-learn 教程 | ApacheCN
- OpenCV学习笔记(19)关于CV_8UC1,CV_8UC2等参数
- C语言学习4: 函数返回值与传入参数,关于函数值传递和类型隐性转换,变量不同的作用域,static变量,多文件编译例如两个C文件,显示函数调用语句跳转,递归,斐波那契数列,多文件编译相同变量的问题。
- 关于字符串replace方法第二个参数探究
- 【Scikit-Learn 中文文档】模型选择:选择估计量及其参数 - 关于科学数据处理的统计学习教程 - scikit-learn 教程 | ApacheCN