你們都知道PostMessage會丟消息,可是消息隊列的大小是多少呢,下面作了一個測試。html
1 unit Unit1; 2 3 interface 4 5 uses 6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 7 Dialogs, StdCtrls; 8 9 const 10 UM_ADD = WM_USER + 100; 11 12 type 13 TForm1 = class(TForm) 14 Label1: TLabel; 15 procedure FormCreate(Sender: TObject); 16 private 17 FVal: Integer; 18 procedure OnMsgAdd(var Msg: TMsg); message UM_ADD; 19 public 20 { Public declarations } 21 end; 22 23 var 24 Form1: TForm1; 25 26 implementation 27 28 {$R *.dfm} 29 30 procedure TForm1.FormCreate(Sender: TObject); 31 var 32 i: Integer; 33 begin 34 for i:=0 to 1000000 do 35 PostMessage(Handle, UM_ADD, 0, 0); 36 end; 37 38 procedure TForm1.OnMsgAdd(var Msg: TMsg); 39 begin 40 Inc(FVal); 41 Label1.Caption := IntToStr(FVal); 42 end; 43 44 end.
XP下運行結果:
函數