Ver Mensaje Individual
  #4  
Antiguo 04-11-2007
serrano serrano is offline
Registrado
 
Registrado: nov 2007
Posts: 2
Reputación: 0
serrano Va por buen camino
La solución de roman, con una pequeña modificación, para que también funcione al arrastrar el botón central de la barra de desplazamiento:


Código Delphi [-]
 

unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, StdCtrls;
 
type
  TForm1 = class(TForm)
    Memo1: TMemo;
    RichEdit1: TRichEdit;

    procedure FormCreate(Sender: TObject);
  private
    { Bandera para controlar el desplazamiento }
    Scrolling: Boolean;

    { Manejadores de mensajes originales }
    MemoOldWndProc: TWndMethod;
    RichEditOldWndProc: TWndMethod;

    { Manejadores de mensajes de reemplazo }
    procedure MemoWndProc(Var Msg: TMessage);
    procedure RichEditWndProc(Var Msg: TMessage);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Scrolling := false;

  { Guardar referencias a los manejadores de mensajes originales }
  MemoOldWndProc := Memo1.WindowProc;
  RichEditOldWndProc := RichEdit1.WindowProc;

  { Reemplazar los manejadores de mensajes }
  Memo1.WindowProc := MemoWndProc;
  RichEdit1.WindowProc := RichEditWndProc;
end;

{ Manejador de mensajes del memo }
procedure TForm1.MemoWndProc(var Msg: TMessage);
begin
  { Enviar mensaje al rich edit }
  if (Msg.Msg = WM_VSCROLL) and not Scrolling then
  begin
    Scrolling := true;
    if Msg.WParam < 9 then
      RichEdit1.Perform(WM_VSCROLL, Msg.WParam, Msg.LParam)
    else
      RichEdit1.Perform(WM_VSCROLL, (Msg.WParam-5)*13+5, Msg.LParam);
    Scrolling := false;
  end;

  { Llamar al manejador original }
  MemoOldWndProc(Msg);
end;

{ Manejador de mensajes del rich edit }
procedure TForm1.RichEditWndProc(var Msg: TMessage);
begin
  { Enviar mensaje al memo }
  if (Msg.Msg = WM_VSCROLL) and not Scrolling then
  begin
    Scrolling := true;
    if Msg.WParam < 9 then
      Memo1.Perform(WM_VSCROLL, Msg.WParam, Msg.LParam)
    else
      Memo1.Perform(WM_VSCROLL, Round((Msg.WParam-5)/13/65536)*65536+5, Msg.LParam);
    Scrolling := false;
  end;

  { Llamar al manejador original }
  RichEditOldWndProc(Msg);
end;

end.

Última edición por serrano fecha: 04-11-2007 a las 09:01:41.
Responder Con Cita