May 09, 2024, 05:10:25 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Scroll to top in richtext

Started by Jerry Muelver, March 01, 2008, 06:21:39 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Jerry Muelver

I can scroll down the file in a richtext control with @RTSCROLL. But how do I scroll up to show the top line at the top of the control? Getting the index of the top line currently showing doesn't do much good, because @RTSCROLL seems not to deal with negative numbers, so I can't subtract to back up to the top of the file.

LarryMc

I think your answer lies somewhere in this:
QuoteWM_VSCROLL     

The WM_VSCROLL message is sent to a window when a scroll event occurs in the window's standard vertical scroll bar. This message is also sent to the owner of a vertical scroll bar control when a scroll event occurs in the control.

WM_VSCROLL 
nScrollCode = (int) LOWORD(wParam); // scroll bar value
nPos = (short int) HIWORD(wParam);  // scroll box position
hwndScrollBar = (HWND) lParam;      // handle of scroll bar


Parameters

nScrollCode

Value of the low-order word of wParam. Specifies a scroll bar value that indicates the user's scrolling request. This parameter can be one of the following values:

Value   Meaning
SB_BOTTOM   Scrolls to the lower right.
SB_ENDSCROLL   Ends scroll.
SB_LINEDOWN   Scrolls one line down.
SB_LINEUP   Scrolls one line up.
SB_PAGEDOWN   Scrolls one page down.
SB_PAGEUP   Scrolls one page up.
SB_THUMBPOSITION   Scrolls to the absolute position. The current position is specified by the nPos parameter.
SB_THUMBTRACK   Drags scroll box to the specified position. The current position is specified by the nPos parameter.
SB_TOP   Scrolls to the upper left.


nPos

Value of the high-order word of wParam. Specifies the current position of the scroll box if the nScrollCode parameter is SB_THUMBPOSITION or SB_THUMBTRACK; otherwise, nPos is not used.

hwndScrollBar

Value of lParam. Identifies the control if WM_VSCROLL is sent by a scroll bar control. If WM_VSCROLL is sent by a window's standard scroll bar, hwndScrollBar is not used.



Return Values

If an application processes this message, it should return zero.

Remarks

The SB_THUMBTRACK notification message is typically used by applications that provide feedback as the user drags the scroll box.
If an application scrolls the content of the window, it must also reset the position of the scroll box by using the SetScrollPos function.
Note that the WM_VSCROLL message carries only 16 bits of scroll box position data. Thus, applications that rely solely on WM_VSCROLL (and WM_HSCROLL) for scroll position data have a practical maximum position value of 65,535.

However, because the SetScrollPos, SetScrollRange, GetScrollPos, and GetScrollRange functions support 32-bit scroll bar position data, there is a way to circumvent the 16-bit barrier of the WM_HSCROLL and WM_VSCROLL messages. See GetScrollPos for a description of the technique and its limits.

See Also

GetScrollPos, GetScrollRange, SetScrollPos, SetScrollRange, WM_HSCROLL


Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Jerry Muelver

Of course -- juggle the scrollbar. RTSCROLL may only be playing with content instead of display widgets. I'll go off and chew on this a bit. All I have to do is learn about SENDMESSAGE and LOWORD and HIWORD and MSDN-stuff like that there....

Sheesh.... All I wanted to do was take a little walk around on the moon. Who knew it would be so hard getting there?  ::)

Jerry Muelver

windows.inc tells me:
CONST SB_TOP = 6

Okay. So I have to send a "6" to something, somehow. No problem.  ::)

Jerry Muelver

Okay, this does the trick:

   ret = CONTROLCMD(win,1,@RTLOAD,ptext,0)
   controlcmd win,1,@RTSETMODIFIED,0
   ret = CONTROLCMD(win,1, @RTGETFIRSTLINE)
   CONTROLCMD win,1, @RTSCROLL, 0, 0 - ret

Using RETGETFIRSTLINE with the "0 - ret" business is what I was missing in my experiments. Thanks, again, to Alyce for the clue.

pistol350

Hi all!

I post here about my problem as i can't manage to get it solved with the help provided above.
It's been a while that i'm strugling with that example of code to get it do what i need, but i don't have any success.

What i want to do is :

Type my text and press ENTER in a richedit control and have my text displayed in another Richedit control then have my second richedit scroll to Top.
I am very close but i still miss something   ???



CONST RICHEDIT_1 = 1
CONST RICHEDIT_2 = 2
CONST STATIC_4 = 4
DIALOG d1
INT run

'*******************************************************************************************
CREATEDIALOG d1,0,0,452,341,0x80C80080,0,"Richedit + autoVscroll",&d1_handler
CONTROL d1,@RICHEDIT,"",15,15,424,231,0x50B10844,RICHEDIT_1
CONTROL d1,@RICHEDIT,"",15,276,424,47,0x50810044,RICHEDIT_2
CONTROL d1,@STATIC,"Type your text here and press RETURN ",17,255,217,19,0x5000010B,STATIC_4
'*******************************************************************************************
SETCONTROLNOTIFY(d1,RICHEDIT_2, 0, 1)
run=1
SHOWDIALOG d1

WAITUNTIL run = 0
CLOSEDIALOG d1
END

SUB d1_handler
string inputtext$, text$
int length
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW d1
/* Initialize any controls here */
setcontroltext d1,RICHEDIT_1,"Hello!"
CASE @IDCLOSEWINDOW
run = 0
CASE @IDCONTROL
SELECT @CONTROLID
CASE RICHEDIT_1
/* respond to control notifications here */
CASE RICHEDIT_2
/* respond to control notifications here */
IF @NOTIFYCODE = @ENENTERKEY
inputtext$ = GETCONTROLTEXT(d1, RICHEDIT_2)
text$="hi!"
length = CONTROLCMD (d1, RICHEDIT_1, @RTGETTEXTLENGTH)
CONTROLCMD d1, RICHEDIT_1, @RTHIDESEL, TRUE
SETFOCUS d1, RICHEDIT_1 :'so the RICHEDIT_1 will automaticly scroll down
'CONTROLCMD d1,RICHEDIT_1, @RTSCROLL, 0,1
CONTROLCMD d1, RICHEDIT_1, @RTSETSELECTION, length, length
CONTROLCMD d1, RICHEDIT_1, @RTREPLACESEL, text$
CONTROLCMD d1, RICHEDIT_1, @RTHIDESEL, FALSE
'clear the inputbox
SETCONTROLTEXT d1,RICHEDIT_2,""
SETFOCUS d1,RICHEDIT_2
ENDIF

ENDSELECT
ENDSELECT
RETURN
ENDSUB


Regards,

Peter B.

sapero

May 02, 2008, 05:11:53 AM #6 Last Edit: May 02, 2008, 05:26:17 AM by sapero
type MSGFILTER
    NMHDR nmhdr
    UINT msg
    UINT wParam
    UINT lParam
endtype
CONST ENM_KEYEVENTS = 0x10000
CONST EN_MSGFILTER = 0x700

SUB d1_handler

[...]
CASE @IDINITDIALOG
CONTROLCMD d1, RICHEDIT_2, @RTSETEVENTMASK, ENM_KEYEVENTS

CASE @IDCONTROL
SELECT @CONTROLID
CASE RICHEDIT_2
IF (@NOTIFYCODE = EN_MSGFILTER) and (*<MSGFILTER>@LPARAM.msg = @IDKEYDOWN) and (*<MSGFILTER>@LPARAM.wParam = 13)
' enter pressed


Problem: the first richedit always gets the focus, SetFocus is ignored :/

pistol350

Thanks for your help.
I'll try to put these pieces of code together.
Regards,

Peter B.