在网上抄的代码,不知道在Delphi中如何操作,才能输入以下代码?好像是鼠标滚动代码,我不知道如何操作,才能让下面代码起作用?procedure TForm1.SetLabelCaption( ANum: Integer );
begin
   Label1.Caption := IntToStr( ANum );
end;procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
  var Handled: Boolean);
var
  Rotation: ShortInt;
begin
   if Msg.message = WM_MOUSEWHEEL then
   begin
      Rotation := HIWORD( Msg.wParam );
      if Rotation > 0 then
         Inc( Num )
      else
         Dec( Num );
      SetLabelCaption( Num );
      Handled := True;
   end;
end;

解决方案 »

  1.   


    procedure TForm1.FormCreate(Sender: TObject);
    begin
      Application.OnMessage := ApplicationEvents1Message;
    end;
      

  2.   


    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, AppEvnts;type
      TForm1 = class(TForm)
        Label1: TLabel;
        ApplicationEvents1: TApplicationEvents;
        procedure ApplicationEvents1Message(var Msg: tagMSG;
          var Handled: Boolean);
      private
        { Private declarations }
        procedure SetLabelCaption( ANum: Integer );
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}
    procedure TForm1.SetLabelCaption( ANum: Integer );
    begin
       Label1.Caption := IntToStr( ANum );
    end;
    procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
      var Handled: Boolean);
    var
      Rotation: ShortInt;
      num:integer;
    begin
       if Msg.message = WM_MOUSEWHEEL then
       begin
          Rotation := HIWORD( Msg.wParam );
          if Rotation > 0 then
             Inc(Num)
          else
             Dec( Num );
          SetLabelCaption( Num );
          Handled := True;
       end;
    end;end.
    你试试
      

  3.   

    http://hi.baidu.com/hellowzr/blog/item/1ef01901230be98fe850cda8.html
    关于 TApplicationEvents.OnMessage 的
      

  4.   

    procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
      var Handled: Boolean);
    var
      Rotation: ShortInt;
    begin
       if (Msg.message = WM_MOUSEWHEEL) and 
         (Msg.hwnd = self.Handle) then  //只对当前窗口的鼠标滚动消息进行处理
       begin
          Rotation := HIWORD( Msg.wParam );
          if Rotation > 0 then
             Inc( Num )
          else
             Dec( Num );
          SetLabelCaption( Num );
          Handled := True;
       end;
    end;
      

  5.   

    为什么还是不行?ApplicationEvents1: TApplicationEvents;
        procedure ApplicationEvents1Message(var Msg: tagMSG;
          var Handled: Boolean);是不是放错地方了,或者是要加什么单元?