Delphi 自定义消息使用

2022-02-07  本文已影响0人  bshoes

  TMessage 消息结构

PMessage = ^TMessage;

TMessage =packedrecord

Msg: Cardinal;

case Integer of

0: (  WParam: WPARAM;    LParam: LPARAM;    Result: LRESULT);

1: (  WParamLo: Word;      WParamHi: Word;      LParamLo: Word;      LParamHi: Word;      ResultLo: Word;      ResultHi: Word);

end;

消息定义

procedure MyMsg(var Msg: TMessage); message WM_USER + 1000;//用户消息上加

begin

case Msg.WParam of

end;

if (Msg.LParam mod 2)=0 then

begin

end;

end;

消息发送

function SendMessage(  hWnd: HWND;Msg: UINT;wParam: WPARAM;lParam: LPARAM): LRESULT;stdcall;

//目标窗口句柄  定义的消息编码 参数一 参数二 返回值

function PostMessage(  hWnd: HWND;Msg: UINT;wParam: WPARAM;lParam: LPARAM): BOOL;stdcall;

//返回值表示:是否发送成功

SendMessage(Self.Handle, WM_USER + 1000,1,10);// 发送消息后会等待处理结果

PostMessage(Self.Handle, WM_USER + 1000,1,10);//把消息送入消息队列.不等待结果

上一篇 下一篇

猜你喜欢

热点阅读