在窗体的Pirvate处
声明一个消息处理函数:procedure MsgHandle(var Msg:TMsg;var handled:boolean);
然后实现它:procedure TForm1.MsgHandle(var Msg:TMsg;var handled:boolean);begin
  handled:=false;
  if Msg.message=EN_VSCROLL then 
  begin
    ...//做你想做的事。
    handled:=true;
  end;
end;然后,在窗体的Create事件里指定:
  application.OnMessage:=Form1.MsgHandle;

解决方案 »

  1.   


    不同意楼上的。
    不应当截获Application的消息,而是应当截获RichEdit的消息,因为截获Application
    的消息,使得很多不相干的消息也经过过滤,大大降低了效率。WindowProc是TWinControl的处理消息的过程,你将其替换为自己的处理过程
    就可以了。参考以下代码:
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ComCtrls;type
      TForm1 = class(TForm)
        RichEdit1: TRichEdit;
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
        FOldProc: TWndMethod;
        procedure DealRicheditMessage(var Message: TMessage);
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.DealRicheditMessage(var Message: TMessage);
    begin
      case Message.Msg of
        EN_VSCROLL:
        begin
          // do something or inherited;
        end;
        EN_HSCROLL:
        begin
          // do something or inherited.
        end;
        else
          FOldProc(Message);
      end;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      FOldProc := Richedit1.WindowProc;
      Richedit1.WindowProc := DealRicheditMessage;
    end;end.
      

  2.   

    我爱听党的话,可是也不成。你看看我哪里和你不一样,可是就是不成。
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ComCtrls;type
      TForm1 = class(TForm)
        RichEdit1: TRichEdit;
        procedure MsgHandle(var Msg:TMsg;var handled:boolean);
        procedure FormCreate(Sender: TObject);
      private                                                   public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}
    procedure TForm1.MsgHandle(var Msg:TMsg;var handled:boolean);
    begin
      handled:=false;
      if Msg.message=EN_VSCROLL then
      begin
        showmessage('a');
        handled:=true;
      end;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      application.OnMessage:=Form1.MsgHandle;
    end;end.
      

  3.   


    错误修正:
        Msg.Message = EN_VSCROLL 这个是错的,因为 EN_VSCROLL 是个通知代码,不是消息代码。EN 是Edit Notify,表示Edit类型的Windows控件的通知代码;而查看Windows Help,发现
    该通知代码伴随着WM_COMMAND消息的发生而产生,具体应当为:
        if Msg.Message = WM_COMMAND then
        begin
          Case Msg.WParamHi of
            EN_VSCROLL:
              // do something
            EN_HSCROLL:
              // do something
          end;
        end;
      

  4.   

    Musicwind(吾爱是Yaya!)大哥试过了吗?我试了,不行呀。
      

  5.   

    EN_VSCROLL的消息的确捕捉不到,而WM_VSCROLL消息又是直接发给了RichEdit,不经过Windows   ,所以外面的办法捕捉不到,可以解决的办法是:继承它重做一个控件,重载它的WndProc在那里捕捉它的wm_vscroll,捕捉到后再公布出来。
      

  6.   

    Notify消息是发给它的Parent的,
    所以应在它的Parent的窗口过程中处理.