PDA

View Full Version : TRichEdit Sync Scrolling



Gadget
22-04-2005, 07:00 PM
This has been asked before on other forums, but only partly answered.

Using this code:- I can sync the scroll bar messages between 2 TRichEdit components, but what I cannot work out is how to 'completely' sync the actual scrolling of the controls. So if you use the cursor keys to go down, it should also scroll the other window.

I have tried forwarding WM_KEYDOWN, WM_KEYUP, and various other messages to no avail, is this due to the the sequence of messages that have component specific info?

If I send ALL messages to the other TRichEdit, it works, but it gets EVERY message, ie. text population messages etc, so it's no good =(


///
PRichEdWndProc, POldWndProc: Pointer;
procedure RichEdWndProc(var Msg: TMessage);
///

procedure TfrmScriptTool.RichEdWndProc(var Msg: TMessage);
begin
Msg.Result := CallWindowProc(POldWndProc, redtCode.Handle, Msg.Msg, Msg.wParam, Msg.lParam);

if (Msg.Msg = WM_VSCROLL) then
begin
redtLineNumbers.Perform(Msg.Msg, Msg.wParam, Msg.lParam);
SetScrollPos(redtLineNumbers.Handle, SB_VERT, HIWORD(Msg.wParam), True);
end;

end;

procedure TfrmScriptTool.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
if Assigned(PRichEdWndProc) then
begin
SetWindowLong(redtCode.Handle, GWL_WNDPROC, Integer(POldWndProc));
FreeObjectInstance(PRichEdWndProc);
end;
end;


procedure TfrmScriptTool.FormCreate(Sender: TObject);
begin
PRichEdWndProc := MakeObjectInstance(RichEdWndProc);
POldWndProc := Pointer(SetWindowLong(redtCode.Handle, GWL_WNDPROC, Integer(PRichEdWndProc)));
end;