onlyou13

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm2 = class(TForm)
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
    FWorkHandle: THandle;
    procedure WorkWindowProc(var message: TMessage);
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

const
  WM_PROGRESS = WM_USER + $A;
  EventTimer1 = 1020;
  EventTimer2 = 1021;

implementation

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);
begin
  PostMessage(FWorkHandle, WM_PROGRESS, 0, 0);
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
  FWorkHandle := AllocateHWnd(WorkWindowProc);
  SetTimer(FWorkHandle, EventTimer1, 1000, nil);
  SetTimer(FWorkHandle, EventTimer2, 100, nil);
end;

procedure TForm2.FormDestroy(Sender: TObject);
begin
  KillTimer(FWorkHandle, EventTimer1);
  KillTimer(FWorkHandle, EventTimer2);
  DeallocateHWnd(FWorkHandle);
end;

procedure TForm2.WorkWindowProc(var message: TMessage);
begin
  case message.Msg of
    WM_PROGRESS:
      Caption := 'hello WM_BURNPROGRESS';
    WM_COPYDATA:
      Caption := 'hello WM_COPYDATA';
    WM_TIMER:
      begin
        case message.WParam of
          EventTimer1:
            Caption := 'hello WM_TIMER Event1  ' + IntToStr(GetTickCount);
          EventTimer2:
            Caption := 'hello WM_TIMER Event2  ' + IntToStr(GetTickCount);
        end;
      end;
  else
    //Dispatch(message);
  end;
end;

end.

  

posted on 2018-10-23 15:33  onlyou13  阅读(122)  评论(0编辑  收藏  举报