unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, SUIForm;  Const
     SX_MyMessage =  WM_USER  + 101;
     SX_MyMessage2 =  WM_USER  + 102;   TYPE
      TECG = array[0..299] of integer;
  const ecg1:TECG = ( 63, 63, 63, 63, 63, 64, 64, 65, 65, 66,//1
                      67, 68, 67, 67, 66, 65, 64, 63, 63, 63,
                      63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
                      63, 60, 59, 61, 63, 73, 84, 95, 79, 63, //4
                      61, 60, 58, 57, 55, 57, 60, 60, 60, 60,
                      60, 60, 61, 61, 61, 62, 62, 62, 62, 62,
                      62, 63, 63, 63, 63, 64, 64, 65, 65, 65,
                      66, 66, 67, 68, 68, 69, 68, 67, 67, 67, //8
                      66, 65, 63, 62, 60, 60, 60, 60, 61, 61,
                      61, 61, 61, 62, 62, 62, 63, 63, 63, 63,  //10
                      63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
                      63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
                      63, 63, 63, 63, 63, 63, 63, 63, 63, 63,  //13
                      63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
                      63, 63, 63, 63, 63, 63, 63, 63, 63, 63,  //15
                      63, 63, 63, 63, 63, 64, 64, 65, 65, 66,//1
                      67, 68, 67, 67, 66, 65, 64, 63, 63, 63,
                      63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
                      63, 60, 59, 61, 63, 73, 84, 95, 79, 63, //4
                      61, 60, 58, 57, 55, 57, 60, 60, 60, 60,
                      60, 60, 61, 61, 61, 62, 62, 62, 62, 62,
                      62, 63, 63, 63, 63, 64, 64, 65, 65, 65,
                      66, 66, 67, 68, 68, 69, 68, 67, 67, 67, //8
                      66, 65, 63, 62, 60, 60, 60, 60, 61, 61,
                      61, 61, 61, 62, 62, 62, 63, 63, 63, 63,  //10
                      63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
                      63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
                      63, 63, 63, 63, 63, 63, 63, 63, 63, 63,  //13
                      63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
                      63, 63, 63, 63, 63, 63, 63, 63, 63, 63  //15
                      );type
  TForm1 = class(TForm)
    PaintBox1: TPaintBox;
    button1  : Tbutton;
    Button2: TButton;    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
     Procedure   SXMyMessage(var msg :TMessage);message  SX_MyMessage;
     Procedure   SXMyMessage2(Var msg : TMessage); message SX_MyMessage2;
     procedure drawdemo;
    { Public declarations }
    procedure DrawWave(pt1:Tpaintbox;cc,ptwidth,newwidth :integer);
  end;var
  Form1: TForm1;
  arraytmp :  integer;
  demo     :  Boolean;implementation{$R *.dfm}Procedure  Tform1.SXMyMessage2(var Msg : TMessage);
BeginEnd;Procedure  TForm1.SXMyMessage(var msg:TMessage);
Begin  if demo then
  button1Click(Self)
  Else
  DrawWave(paintbox1,1,paintbox1.ClientWidth,arraytmp);
End;procedure Tform1.drawWave(pt1:Tpaintbox;cc,ptwidth,newwidth:integer);
var
  j,tmp:  integer;
  k  :    integer;
Begin
    k := 1;
    pt1.Canvas.Pen.Width := 1;
    Case cc of
      0 : pt1.Canvas.Pen.Color := ClRed;
      1 : pt1.Canvas.Pen.Color := ClBtnFace;
    End;
     newwidth := newwidth * 4;
    if  newwidth >ptwidth then
       tmp := newwidth mod ptwidth
    Else
       tmp := newwidth;
    pt1.Canvas.MoveTo((tmp),ecg1[1]);
    for j := tmp  downto 1 do
    Begin
      pt1.Canvas.LineTo((j),ecg1[k]);
      k := k+1;
      k := k mod 300;
    End;
End;procedure TForm1.Button1Click(Sender: TObject);
begin
    form1.drawdemo;
end;Procedure    TForm1.drawdemo;
Begin
  if  not demo then
        arraytmp  := PaintBox1.ClientWidth + 1;
 if (arraytmp <  form1.PaintBox1.ClientWidth) Then
   Begin
      DrawWave(paintbox1,1,paintbox1.ClientWidth,arraytmp-1);
      DrawWave(paintbox1,0,paintbox1.ClientWidth,arraytmp);
      Arraytmp := arraytmp + 1;
      Sleep(20);
      SendMessage(Handle,SX_MyMessage,0,0);
   End;
End;procedure TForm1.FormCreate(Sender: TObject);
begin
  demo  := True;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
  demo  := false;
  SendMessage(Handle,SX_MyMessage2,0,0);
end;end.
是这样的,我想让程序在绘制过程中停止下来,但是点了button1后,它就要给完才结束,我点了button2呢,它有什么都不绘制,觉得很奇怪,可能不是sendmessage的问题,但是觉得用消息又应当能解决这个问题,所以就发到这里了.

解决方案 »

  1.   

    不大明白你的意思Procedure  Tform1.SXMyMessage2(var Msg : TMessage);
    BeginEnd;
    button2里面发送了SendMessage(Handle,SX_MyMessage2,0,0);这个消息,当你SXMyMessage2过程,什么事情都没做,当然不绘制呀
      

  2.   

    我的button2发了个空消息过去是表示我的demo已经变成false了啊?
    按照想法,点button1让它成绘图状态,button2就是让它停止不画了.
      

  3.   

    可以这么说,现在点了button1后,程序就在不停地绘图,button2是点都点不了,要等button1完全执行了,才能点到button2.
      

  4.   

    在你的drawWave方法的循环里加上
    Application.ProcessMessages;
      

  5.   

    我在drawWave的循环里加了application.ProcessMessage,停到是能停止,不过有时不点button2它还是要自己停止的.
      

  6.   

    我不知道这个application.Processmessage是不是有限定时间的.