通过TApplicationEvents响应消息

1

源代码:
------------------------------------------------------------------------

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    ApplicationEvents1: TApplicationEvents;
    procedure FormCreate(Sender: TObject);
    procedure ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Memo1.Clear;
end;

{响应 WM_MOUSEMOVE 以外的所有消息}
procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
  var Handled: Boolean);
begin
  if Msg.message <> WM_MOUSEMOVE then
    Memo1.Lines.Add('$' + IntToHex(Msg.message, 4));
end;

end.

界面代码:
---------------------------------------------------------------------

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'TApplicationEvents'
  ClientHeight = 215
  ClientWidth = 325
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object Memo1: TMemo
    Left = 4
    Top = 8
    Width = 313
    Height = 161
    Lines.Strings = (
      'Memo1')
    TabOrder = 0
  end
  object ApplicationEvents1: TApplicationEvents
    OnMessage = ApplicationEvents1Message
    Left = 40
    Top = 152
  end
end

posted @ 2010-02-14 16:01  猪悟能  阅读(726)  评论(0编辑  收藏  举报