我定义了一个消息const WM_IEC103=WM_User+$1000;然后给一个form发送消息procedure TForm1.Button1Click(Sender: TObject);
var
  hd: THandle;
  InfoNum:integer;
begin
  hd := FindWindow('TForm_103Communicate',nil);
  if hd <> 0 then
    sendmessage(hd,WM_IEC103,5,0);
end;在TForm_103Communicate中,我定义了一个接收函数
procedure TForm_103Communicate.Commnunicate(var msg:Tmessage);
var Data_Main103:TData_103;
    i:integer;
begin
     if Tmessage(msg).Msg=WM_IEC103 then
     showmessage('haha');
end;然后用Timer来调用Commnunicate
procedure TForm_103Communicate.Timer1Timer(Sender: TObject);
begin
     Commnunicate(msg);//msg是一个全局变量在public中定义
end;为什么接受不到这个消息呢?

解决方案 »

  1.   

    //tryconst
      WM_IEC103 = WM_USER + $1000;type
      TForm1 = class(TForm)
      private
        { Private declarations }
        procedure WMIEC103(var Msg: TMessage); message WM_IEC103;
      public
        { Public declarations }
      end;//....procedure TForm1.WMIEC103(var Msg: TMessage);
    begin
      Caption := Format('%.6f', [Now]);
    end;
      

  2.   

    procedure WMICE103(var msg:TMessage):message WM_IEC103;procedure TForm_103Communicate.WMICE103(var msg:Tmessage);
    begin
      showmessage('haha');
    nnd;
      

  3.   

    我知道接受消息不需要timer来实时察看,但是我现在要用Timer定时处理一些事情,处理之前我必须知道是否有消息传递,所以我询问大家为什么在Timer中调用接受消息之后就收不到消息了呢?