博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Receive Windows Messages In NonWindowed Control
阅读量:6274 次
发布时间:2019-06-22

本文共 2135 字,大约阅读时间需要 7 分钟。

View Code
interfaceuses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  Dialogs;type  TMsgReceiver = class(TObject)  private    fMsgHandlerHWND : HWND;    WM_MY_UNIQUE_MESSAGE : Cardinal;    procedure WndMethod(var Msg: TMessage);  public    Point : TPoint;    constructor Create;    destructor Destroy; override;  end;  TClickSendForm = class(TForm)    procedure FormCreate(Sender: TObject);    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer);    procedure FormDestroy(Sender: TObject);  private    WM_MY_UNIQUE_MESSAGE : Cardinal;    fMsgReceiver: TMsgReceiver;    function GetMsgReceiver: TMsgReceiver;    property MsgReceiver : TMsgReceiver read GetMsgReceiver;  public    {
Public declarations } end;var ClickSendForm: TClickSendForm;implementation{
$R *.dfm}procedure TClickSendForm.FormCreate(Sender: TObject);begin //instantiate MsgReceiver MsgReceiver; WM_MY_UNIQUE_MESSAGE := RegisterWindowMessage('MSG_MY_UNIQUE_MESSAGE');end;{
TMsgReceiver }constructor TMsgReceiver.Create;begin inherited Create; fMsgHandlerHWND := AllocateHWnd(WndMethod); WM_MY_UNIQUE_MESSAGE := RegisterWindowMessage('MSG_MY_UNIQUE_MESSAGE');end;destructor TMsgReceiver.Destroy;begin DeallocateHWnd(fMsgHandlerHWND); inherited;end;procedure TMsgReceiver.WndMethod(var Msg: TMessage);begin if Msg.Msg = WM_MY_UNIQUE_MESSAGE then begin Point.X := Msg.LParam; Point.Y := Msg.WParam; //just to receive some "output" Windows.Beep(Point.X, Point.Y); end else Msg.Result := DefWindowProc(fMsgHandlerHWND, Msg.Msg, Msg.wParam, Msg.lParam);end;procedure TClickSendForm.FormDestroy(Sender: TObject);begin FreeAndNil(fMsgReceiver);end;procedure TClickSendForm.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);begin PostMessage(HWND_BROADCAST, WM_MY_UNIQUE_MESSAGE, x, y);end;function TClickSendForm.GetMsgReceiver: TMsgReceiver;begin if fMsgReceiver = nil then fMsgReceiver := TMsgReceiver.Create; result := fMsgReceiver;end;end.

转载于:https://www.cnblogs.com/Jekhn/archive/2012/04/21/2461508.html

你可能感兴趣的文章
小程序 · 跳转带参数写法,兼容url的出错
查看>>
flutter error
查看>>
Flask框架从入门到精通之模型数据库配置(十一)
查看>>
10年重新出发
查看>>
2019年-年终总结
查看>>
聊聊elasticsearch的RoutingService
查看>>
让人抓头的Java并发(一) 轻松认识多线程
查看>>
从源码剖析useState的执行过程
查看>>
地包天如何矫正?
查看>>
中间件
查看>>
Android SharedPreferences
查看>>
css面试题
查看>>
Vue组建通信
查看>>
用CSS画一个带阴影的三角形
查看>>
前端Vue:函数式组件
查看>>
程鑫峰:1.26特朗.普力挺美元力挽狂澜,伦敦金行情分析
查看>>
safari下video标签无法播放视频的问题
查看>>
01 iOS中UISearchBar 如何更改背景颜色,如何去掉两条黑线
查看>>
对象的继承及对象相关内容探究
查看>>
Spring: IOC容器的实现
查看>>