Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
RTF SCROLLBAR
#1
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?
   
#2
Maybe possible with separate ScrollBar control, but difficult, because you need to track richtext control state and update ScrollBar control, etc.
#3
What about a subclass control? Scrollbar to RTF.

Subclassing dialog controls to receive messages
#4
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
Code:
Copy      Help
,int h=id(3 hDlg)
,SendMessage h EM_SETEVENTMASK 0 ENM_CHANGE

, and insert this under sel wParam
Code:
Copy      Help
,case EN_CHANGE<<16|3
,out 1
#5
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
Code:
Copy      Help
;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
Code:
Copy      Help
;\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
Code:
Copy      Help
;/
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
Code:
Copy      Help
;/
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)
#6
It will not be so easy...
#7
Wasn’t there an old post about getting the cursor location and can that be made into an array to move the scrollbar?


Forum Jump:


Users browsing this thread: 1 Guest(s)