Link to home
Start Free TrialLog in
Avatar of amv
amv

asked on

How to replace WM_HSCROLL handler for TRxRichEdit?

Hi,

My problem is as follows:
I have 2 TRxRichEdit controls on my form and I need to link them so that if user scrolls contents of one of them (using scrollbar) horizintally then contents of another TRxRichEdit gets scrolled too.

May be someone have some sample code which solves this or similar problem?..

Thanks in advance, amv.
Avatar of inthe
inthe

hi,
this is example syncronizing component for  memos ,it should be same for richedit also just need to change the instances of memo to richedit the install and use a ne richedit.:

unit SyncMemo;
 
interface
 
uses
  Windows, Messages, Classes, SysUtils, Graphics, Controls, Forms, Dialogs,   StdCtrls;
 
const
  {User messages to use if buddy is TSyncMemo }
  UM_BUDDYHSCROLL = WM_USER + 1111;
  UM_BUDDYVSCROLL = WM_USER + 1112;
type
 
  TSyncMemo = class(TMemo)
  private
    { Private declarations }
    { Handlers for windows messages }
    procedure WMVScroll( Var msg: TMessage );
      message WM_VSCROLL;
    procedure WMHScroll( Var msg: TMessage );
      message WM_HSCROLL;
    procedure UMBuddyHScroll( Var msg: TMessage );
      message UM_BUDDYHSCROLL;
    procedure UMBuddyVScroll( Var msg: TMessage );
      message UM_BUDDYVSCROLL;
 
    Procedure SetScrollControl( aScrollControl: TCustomMemo );
  protected
    { Protected declarations }
    FInBuddyScroll: Boolean;
    FBuddy: TCustomMemo;
    FSyncStyle: TScrollStyle;
  public
    { Public declarations }
  published
    { Published declarations }
 
    property SyncStyle: TScrollStyle read FSyncStyle write FSyncStyle;     property ScrollControl: TCustomMemo read FBuddy write SetScrollControl;   end;
 
procedure Register;
 
implementation
 
procedure Register;
begin
  RegisterComponents('Test', [TSyncMemo]);
end;
 
{ TSyncMemo }
 
procedure TSyncMemo.UMBuddyHScroll(var msg: TMessage);
begin
  FInBuddyScroll:= True;
  try
    msg.result := Perform( WM_HSCROLL, msg.wparam, msg.lparam );   finally
    FInBuddyScroll := False;
  end;
end;
 
procedure TSyncMemo.UMBuddyVScroll(var msg: TMessage);
begin
  FInBuddyScroll:= True;
  try
    msg.result := Perform( WM_VSCROLL, msg.wparam, msg.lparam );   finally
    FInBuddyScroll := False;
  end;
end;
 
procedure TSyncMemo.WMHScroll(var msg: TMessage);
begin
  If not FInBuddyScroll and
    (FSyncStyle In [ssBoth, ssHorizontal]) and
    Assigned( FBuddy )
  Then Begin
    If FBuddy Is TsyncMemo Then
      FBuddy.Perform( UM_BUDDYHSCROLL, msg.wparam, msg.lparam )
    Else
      FBuddy.Perform( WM_HSCROLL, msg.wparam, msg.lparam );
  End;
  inherited;
end;
 
procedure TSyncMemo.WMVScroll(var msg: TMessage);
begin
  If not FInBuddyScroll and
    (FSyncStyle In [ssBoth, ssVertical]) and
    Assigned( FBuddy )
  Then Begin
    If FBuddy Is TsyncMemo Then
      FBuddy.Perform( UM_BUDDYVSCROLL, msg.wparam, msg.lparam )
    Else
      FBuddy.Perform( WM_VSCROLL, msg.wparam, msg.lparam );
  End;
  inherited;
end;
 
Procedure TSyncMemo.SetScrollControl( aScrollControl: TCustomMemo ); Begin
  If (aScrollControl <> FBuddy) and (aScrollControl <> Self) Then     FBuddy := aScrollControl;
End;
 
end.

Hope it helps

Regards Barry
This one also by Inthe
..
..
var
Oldpos :Integer;

procedure TForm1.ScrollBar1Scroll(Sender: TObject; ScrollCode:
                                          TScrollCode;
var ScrollPos: Integer);
begin

      if scrollpos > oldpos then begin
         sendmessage(memo1.handle,wm_vscroll,sb_linedown,scrollpos);
         sendmessage(memo2.handle,wm_vscroll,sb_linedown,scrollpos);
      end
      else if  scrollpos < oldpos then begin
         sendmessage(memo1.handle,wm_vscroll,sb_lineup,scrollpos);
         sendmessage(memo2.handle,wm_vscroll,sb_lineup,scrollpos);
      end;
      oldpos := scrollpos;
end;

or from: AttarSoftware
unit Unit1;

interface
uses
   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
                        StdCtrls;

 type
                        TForm1 = class(TForm)
                          ScrollBox1: TScrollBox;
                          Label1: TLabel;
                          ScrollBox2: TScrollBox;
                          Label2: TLabel;
                          procedure FormShow(Sender: TObject);
                        private
                          { Private declarations }
                          oldWndMethod : tWndMethod ;
                          procedure MyWndProc( var msg : tMessage ) ;
                        public
                          { Public declarations }
                        end;

                      var
                        Form1: TForm1;

                      implementation

                      {$R *.DFM}

procedure tForm1.MyWndProc( var msg : tMessage ) ;
begin
       if( msg.Msg = WM_VSCROLL ) then
                          PostMessage( ScrollBox2.Handle, WM_VSCROLL,                           msg.WParam, msg.LParam ) ;
                        oldWndMethod( msg ) ;
end ;

procedure TForm1.FormShow(Sender: TObject);
begin
              oldWndMethod := ScrollBox1.WindowProc ;
              ScrollBox1.WindowProc := MyWndProc ;
end;

end.

                      -------------------------------------
Indi
ASKER CERTIFIED SOLUTION
Avatar of inthe
inthe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of amv

ASKER

Great thanks guys!! I got it worked with your help!!
great
In the end you allways beat yourself, barry
cheers
Indi
hey im no "sado masacist"  <-- sp  ;-))