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

本文共 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

你可能感兴趣的文章
我的友情链接
查看>>
03(maven+SSH)网上商城项目实战之数据库设计(PMD)
查看>>
HP D6000 盘柜配置
查看>>
常用的文件后缀
查看>>
使用ArcGIS API for Silverlight 进行复合多条件空间查询
查看>>
JavaScript之Ajax-5 JSON(JSON概述、使用JSON)
查看>>
在desktop上做AO的开发
查看>>
Mac 下安装常用软件。
查看>>
第一篇
查看>>
Istio 服务部署
查看>>
跟随外部世界的变化而变化
查看>>
mybatis之一:基本应用
查看>>
我的友情链接
查看>>
CentOS6.3下部署文件恢复神器extundelete
查看>>
Windows 2003 Server安全配置完整篇
查看>>
如何安装Oracle Database 11g数据库
查看>>
IPSEC ××× 的配置实例
查看>>
成人学习国画可能产生哪些错误的思想?
查看>>
百度地图笔记_多边形覆盖物区域加标签
查看>>
cocos2dx内存管理机制
查看>>