要实现的功能是鼠标滚动的时候,另一个richedit也同步滚动,用下面的代码似乎SendMessag发的一些消息丢掉了,导致来回滚动几次之后两个richedit就不同步了,差了几行,点击一下一边的滚动条就可以跳到同一行
请教一下高手怎么解决这个问题,困惑很久了...
  if (Msg.Msg=WM_MOUSEWHEEL) and RedtBeforeModify.Focused then
    SendMessage(RedtAfterModify.Handle,Msg.Msg,Msg.WParam,Msg.LParam);

解决方案 »

  1.   

    One solution could be to use perform method of wincontrol instead of sending message.
    if (Msg.Msg=WM_MOUSEWHEEL) and RedtBeforeModify.Focused then
    begin
         ActiveControl := RedtAfterModify;
         RedtAfterModify.perform(Msg.Msg,Msg.WParam, Msg.LParam); 
    end;
    PS: I haven't tested this code, but above provided snippet should work.Let me know how it goes.Thanks,Ali
      

  2.   

    首先给TYourRichEdit类加一个响应WM_TIMER的事件,如:OnTimer : TNotifyEvent;
    Type
      TYourRichEdit = Class(TRichEdit)
      private
        fOnTimer : TNotifyEvent;
        procedure DoTimer(var Message: TMessage); message WM_TIMER;
      published
        property fOnTimer : TNotifyEvent read fOnTimer write fOnTimer;
      end;procedure TYourRichEdit.DoTimer(var Message: TMessage);
    begin
      if Assigned(fOnTimer) then fOnTimer(Self);
    end;注册该类,拖到Form上,
    然后在该对象的OnTimer里写上var
      n : integer;
    begin
      n := GetScrollPos(YourRichEdit1.Handle , SB_VERT);
      SetScrollPos(RichEdit2.Handle , SB_VERT , n , True);
    end;其实就是响应 WM_TIMER事件
      

  3.   


    var
      n : integer;
    begin
      n := GetScrollPos(YourRichEdit1.Handle , SB_VERT) SHL 16 + SB_THUMBPOSITION;
      SendMessage(RichEdit2.Handle , WM_VSCROLL , n , 0);
    end;