请问有什么办法能在同一应用程序里接受消息,并使某一状态随消息的改变而改变?
谢谢!

解决方案 »

  1.   

    定义自己的消息,和消息处理函数,在消息处理函数里改变某一状态如
    const 
      mymessage = wm_user+1;  TForm1 = class(TForm)
      private
        procedure ProMymessage(var msg:tmessage);message mymessage;
      public
        { Public declarations }
      end;
      
        procedure ProMymessage(var msg:tmessage);message mymessage;
    就是消息处理函数,后面要用关键字message
      

  2.   

    wndproc
    这个函数实际上就是包含很多消息的一个case,
    可以考虑在里面修改
      

  3.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;const
      wm_my = wm_user+12;   ///自己定义的消息type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
        procedure prowm_my(var msg:tmessage);message wm_my; //自己定义的消息的处理函数
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}{ TForm1 }procedure TForm1.prowm_my(var msg: tmessage);
    var s:string;i:integer;
    begin
      for i:=1 to msg.LParam do
      begin
        s:=s+chr(pbyte(msg.WParam+i-1)^);
      end;
      showmessage(s);
    end;procedure TForm1.Button1Click(Sender: TObject);  //发送消息同时带着pp字符串的地址和字符的个数
    var pp:string;
    begin
      pp:='i am a message';
      sendmessage(handle,wm_my,integer(pp),length(pp));
    end;end.