1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
unit synchroScroll;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls; //SHDocVw
type
TForm1 = class(TForm)
Memo1: TMemo;
Label1: TLabel;
Label2: TLabel;
Memo2: TMemo;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
PRichEdWndProc, POldWndProc: Pointer;
procedure RichEdWndProc(var Msg: TMessage);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.RichEdWndProc(var Msg: TMessage);
begin
Msg.Result := CallWindowProc(POldWndProc, Memo2.Handle, Msg.Msg,
Msg.wParam, Msg.lParam);
if (Msg.Msg = WM_VSCROLL) then
if (LOWORD(Msg.wParam) = SB_THUMBTRACK) or
(LOWORD(Msg.wParam) = SB_LINEDOWN) or (LOWORD(Msg.wParam) = SB_LINEUP) or
(LOWORD(Msg.wParam) = SB_PAGEDOWN) or (LOWORD(Msg.wParam) = SB_PAGEUP) then
begin
Label1.Caption := 'Pos is ' + IntToStr(HIWORD(Msg.wParam));
Memo1.Perform(Msg.Msg, Msg.wParam, Msg.lParam);
SetScrollPos(Memo1.Handle, SB_VERT, HIWORD(Msg.wParam), True);
end;
if (Msg.Msg = WM_Mousewheel) then //and (LOWORD(Msg.wParam) = SB_THUMBTRACK)
begin
Label1.Caption := 'Pos is ' + IntToStr(HIWORD(Msg.wParam));
Memo1.Perform(Msg.Msg, Msg.wParam, Msg.lParam);
SetScrollPos(Memo1.Handle, SB_VERT, HIWORD(Msg.wParam), True);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
PRichEdWndProc := MakeObjectInstance(RichEdWndProc);
POldWndProc := Pointer(SetWindowLong(Memo2.Handle, GWL_WNDPROC,
Integer(PRichEdWndProc)));
Memo1.Lines.LoadFromFile('fictest.cvs');
Memo2.Lines.LoadFromFile('fictest.cvs');
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if Assigned(PRichEdWndProc) then
begin
SetWindowLong(Memo2.Handle, GWL_WNDPROC, Integer(POldWndProc));
FreeObjectInstance(PRichEdWndProc);
end;
end;
end. |
Partager