Posts: 262
Threads: 63
Joined: Nov 2005
Is it possible to detach the scrollbar from the RTF and still make the scrollbar and the RTF work the same way they do when they are attached to each other?
Posts: 12,071
Threads: 140
Joined: Dec 2002
Maybe possible with separate ScrollBar control, but difficult, because you need to track richtext control state and update ScrollBar control, etc.
Posts: 262
Threads: 63
Joined: Nov 2005
What about a subclass control? Scrollbar to RTF.
Subclassing dialog controls to receive messages
Posts: 12,071
Threads: 140
Joined: Dec 2002
It also somehow works, and is easier. But you need to update text in control2 when text (number of lines) in control1 changes. And remove WS_VSCROLL style from control1. And optionally add ES_AUTOHSCROLL style to both controls to prevent word wrapping. And change Edit to RichEdit20A.
To receive EN_CHANGE message from a rich edit control, under case WM_INITDIALOG use
,int h=id(3 hDlg)
,SendMessage h EM_SETEVENTMASK 0 ENM_CHANGE
, and insert this under sel wParam
,case EN_CHANGE<<16|3
,out 1
Posts: 262
Threads: 63
Joined: Nov 2005
I am sorry I gust can not get the scroll bar in control two to update when I use the up/down arrows or the mouse wheel in control one.
Macro
;Shortly about subclassing. More information can be found in the MSDN Library.
;In response to user input events Windows sends various messages to the window
;under the mouse pointer, or to the focused window. Various other messages are
;also sent, for example, when the window is created, destroyed, painted. As you
;probably know, controls are windows too. If the window is a dialog, we can
;intercept these messages in the dialog procedure. But if the window is a control,
;it only notifies the dialog about few events, by sending to the dialog WM_COMMAND
;and some other messages.
;If we want to intercept messages sent to a particular control, we can subclass it.
;If we want to intercept messages sent to all windows of a particular class, we can
;either create new class, or superclass an existing class. The second method is good
;when you want to use features of an existing class and add several new features.
;If we want to intercept certain messages sent to any window, including or not
;including windows of other programs, we can set hooks.
;To subclass a window, at first create a window procedure that will receive messages.
;It is an user-defined function, similar to an usual window procedure or dialog procedure.
;It must call CallWindowProc (not DefWindowProc) to forward messages for default processing.
;To subclass (begin receiving messages) a window, call SetWindowLong with GWL_WNDPROC and
;address of the new window procedure. It returns the address of the default window
;procedure, which must be used as first argument of CallWindowProc.
str controls = "3 4"
str rea3 rea4
rea3="1[]2[]3[]4[]5[]6[]7[]8[]9"
rea4=rea3
if(!ShowDialog("Dialog_with_subclassed_controls" &Dialog_with_subclassed_controls &controls)) ret
Function Dialog_with_subclassed_controls
;\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages
;BEGIN DIALOG
;0 "" 0x10C80A44 0x100 0 0 223 135 "Form"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 RichEdit20A 0x54031044 0x200 0 0 96 34 ""
;4 RichEdit20A 0x54231044 0x200 104 0 96 34 ""
;END DIALOG
;DIALOG EDITOR: "" 0x203000D "" "" ""
ret
;messages
sel message
,case WM_INITDIALOG
,DT_Init(hDlg lParam)
,;Subclasses two Edit controls to receive WM_VSCROLL messages.
,;Purpose - synchronous scrolling.
,int- t_hdlg t_oldwndproc3 t_oldwndproc4 ;;shared variables
,t_hdlg=hDlg
,t_oldwndproc3=SetWindowLong(id(3 hDlg) GWL_WNDPROC &WndProcSubclassedEdit3)
,t_oldwndproc4=SetWindowLong(id(4 hDlg) GWL_WNDPROC &WndProcSubclassedEdit4)
,int h=id(3 hDlg)
,SendMessage h EM_SETEVENTMASK 0 ENM_CHANGE
,
,ret 1
,case WM_DESTROY DT_DeleteData(hDlg)
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case EN_CHANGE<<16|3
,out 1
,case IDOK DT_Ok hDlg
,case IDCANCEL DT_Cancel hDlg
ret 1
Function WndProcSubclassedEdit3
;/
function# hWnd message wParam lParam
int- t_hdlg t_oldwndproc3 t_oldwndproc4
sel message
,case WM_VSCROLL
,CallWindowProc(t_oldwndproc4 id(4 t_hdlg) message wParam lParam)
ret CallWindowProc(t_oldwndproc3 hWnd message wParam lParam)
Function WndProcSubclassedEdit4
;/
function# hWnd message wParam lParam
int- t_hdlg t_oldwndproc3 t_oldwndproc4
sel message
,case WM_VSCROLL
,CallWindowProc(t_oldwndproc3 id(3 t_hdlg) message wParam lParam)
ret CallWindowProc(t_oldwndproc4 hWnd message wParam lParam)
Posts: 12,071
Threads: 140
Joined: Dec 2002
It will not be so easy...
Posts: 262
Threads: 63
Joined: Nov 2005
Wasn’t there an old post about getting the cursor location and can that be made into an array to move the scrollbar?
|