码迷,mamicode.com
首页 > 其他好文 > 详细

全局消息

时间:2014-10-21 00:42:36      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:io   os   ar   使用   for   sp   div   on   log   

unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;
type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    Msg: LongInt;
    { Private declarations }
  protected
   //重载系统消息监听函数
    procedure WndProc(var Message: TMessage); override;
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
//注册一个系统级消息,消息名字最好独一无二,否则不能返回的消息id给msg变量
Msg := RegisterWindowMessage(‘WINDOWS_SYSTEM_TINGHUATONGFANGPC_DIGITALEDU_GQ‘);
end;
procedure TForm1.WndProc(var Message: TMessage);
begin
  if( Message.Msg = Msg) and (Message.WParam=1) then begin
    Caption := ‘‘;
    ShowMessage(‘收到消息了‘);
  end
  else begin
    inherited;
  end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
  M: TMessage;
  B: DWord;
begin
  M.Msg := Msg;
  //向整个PC发送全局消息
  B := BSM_ALLCOMPONENTS;
  //(BSF_POSTMESSAGE表示使用POST方式发送
  BroadcastSystemMessage(BSF_POSTMESSAGE, @B , M.Msg, 1, 0);
end;
end.

全局消息

标签:io   os   ar   使用   for   sp   div   on   log   

原文地址:http://www.cnblogs.com/kaibosoft/p/4039224.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!