各位大虾,我是用c++ builder开发的一个程序,应当和Delphi差不多吧!我如何拦截一个scrollbox控件的滚动消息呢?求救呀!

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Memo1: TMemo;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;  TMyScrollBar = class(TScrollBar)
      private
        i : Integer;
        procedure CNHScroll(var Message: TWMHScroll); message CN_HSCROLL;
      public
        constructor Create(AOwner: TComponent); override;
      end;var
      Form1: TForm1;implementation{$R *.DFM}{ TMyScrollBar }procedure TMyScrollBar.CNHScroll(var Message: TWMHScroll);
    begin
      TForm1(parent).Memo1.Lines.Append(IntToStr(i));
      i := i + 1;
      inherited;
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
      myScrollBar :TMyScrollBar;
    begin
      myScrollBar := TMyScrollBar.Create(Self);
      myScrollBar.Parent := Self;
      myScrollBar.Show;
    end;constructor TMyScrollBar.Create(AOwner: TComponent);
    begin
      inherited;
      i := 1;
      Max := 10;
    end;end.