有時候我們為了多項應用而要管理Windows的消息。我們怎樣才能做到呢?
{ 這個例子定義的程序可以收取所有發往主窗口的消息 }
Unit TesteandoEsta;
Interface
Uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls, Forms, Dialogs, Menus;
Type
TForm1 = Class (TForm)
Private {Private declarations}
Public {Public declarations}
Procedure WinMsg (Var Msg : TMsg; Var Handled : Boolean);
End;
Var
Form1 : TForm1;
Implementation
{$R *.DFM}
{ 所有發送到主窗體的消息,保存在變量Msg中。 }
Procedure TForm1.WinMsg (Var Msg : TMsg; Var Handled : Boolean);
Begin
If Msg.Message = WM_SYSCOMMAND Then Beep;
{ 接收到消息時的通知}
End;
Procedure TForm1.FormCreate (Sender : TObject);
Begin
Application.OnMessage := WinMsg;
{ 替換消息句炳}
End;