rt

解决方案 »

  1.   

    让MEMO滚动条滚动:
    procedure TForm1.Timer1Timer(Sender: TObject);
    begin
        SendMessage(Memo1.Handle,  { HWND of the Memo Control }
                    WM_VSCROLL,    { Windows Message }
                    SB_PAGEDOWN,   { Scroll Command }
                    0)             
    end;
      

  2.   

    SendMessage(Memo1.Handle,  { HWND of the Memo Control }
                    WM_VSCROLL,    { Windows Message }WM_HSCROLL是水平滚动条,WM_VSCROLL是垂直滚动条
                    SB_PAGEDOWN,   { Scroll Command }消息值,SB_PAGEDOWN是向下滚动的意思
                    0)                                      别的消息值请看WM_VSCROLL的
    end;                                                    有关帮助
      

  3.   

    试试以下代码截获消息:
    procedure wmscroll(var message:tmessage);message WM_VSCROLL;procedure TMEMO.WMScroll(var message:tmessage);message WM_VSCROLL;
    begin
      inherited;
      if assigned(onvscroll) then onvscroll;
    end;
      

  4.   

    谢谢!
    还想问一下:
    如果不是自己写TMemo的子类,如何得到memo1的消息?好像在form里面这样写捕捉不到这个消息啊除了setwindowlong还有别的方法么?
      

  5.   


    我用setwindowlong试了一下:var
    oldproc:pointer=nil;function newproc(handle:cardinal;msg:uint;wparam:integer;lparam:integer):integer;stdcall;
    begin
      result:=callwindowproc(oldproc,Handle,msg,wparam,lparam);
      if msg=WM_VSCROLL then
      begin
        sendmessage(form1.memo2.handle,msg,wparam,lparam);//为了让memo1滚动的同时,memo2与之同步滚动。
      end;
    end;procedure TForm1.FormActivate(Sender: TObject);
    begin
      oldproc:=pointer(getwindowlong(memo1.Handle,GWL_WNDPROC));//纪录原来的wndproc
      setwindowlong(memo1.Handle,GWL_WNDPROC,integer(@newproc));//设置新的wndproc
    end;/////////////////////////////////奇怪的是:只有用鼠标托动滚动条的时候才顶用,对于用鼠标滚轮或者由于键盘输入而造成的内容翻滚都没有效果,是不是memo内容滚动还有别的消息啊?
      

  6.   

    也可以这样unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TMainForm = class(TForm)
        Memo1: TMemo;
        Memo2: TMemo;
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
        FOldWndMethod: TWndMethod;
        procedure MemoProcedure(var Msg: TMessage);
      public
        { Public declarations }  end;var
      MainForm: TMainForm;implementation{$R *.dfm}procedure TMainForm.FormCreate(Sender: TObject);
    begin
      FOldWndMethod := Memo1.WindowProc;
      Memo1.WindowProc := MemoProcedure;
    end;procedure TMainForm.MemoProcedure(var Msg: TMessage);
    begin
      if (Msg.Msg = WM_VSCROLL) or
         (Msg.Msg = WM_MOUSEWHEEL) then
        SendMessage(Memo2.Handle, Msg.Msg, Msg.WParam, Msg.LParam);
      FOldWndMethod(Msg);
    end;end.至于由于键盘输入而造成的内容翻滚都没有效果,
    不清楚
      

  7.   

    响应 OnMouseWheel事件,还有OnMouseWheelDown和OnMouseWheelUp
    Procedure MouseWheel(var Message : TMessage);Message WM_MOUSEWHEEL;
    ......