IonicWind Software

IWBasic => General Questions => Topic started by: Andy on November 07, 2018, 07:08:19 AM

Title: Rich edit scroll
Post by: Andy on November 07, 2018, 07:08:19 AM
Hi,

Just thought of an idea, not sure if you can do it, or what constants / messages to use.

In the constants search program, when you add a fifth item to the builder (Rich edit control), I get the vertical scroll bar so I can scroll to the fifth / or sixth etc entry - but it would be nice to get the program to automatically scroll to the last line so it's visable without scrolling.

Is it possible, and if so, how do I do it?, I very rarely use rich edit controls.

Thanks,
Andy.
:)
Title: Re: Rich edit scroll
Post by: fasecero on November 07, 2018, 07:37:48 AM
This works for a window



SendMessage(hwnd, WM_VSCROLL, SB_BOTTOM, 0)


no sure but probably will work for a richedit too...


HWND handle = GetDlgItem(win.hwnd, RICHEDIT_ID)
SendMessage(handle, WM_VSCROLL, SB_BOTTOM, 0)

Title: Re: Rich edit scroll
Post by: Andy on November 07, 2018, 07:49:30 AM
Thanks Fasecero,

tried this....

HWND handle = GetDlgItem(win.hwnd, SelectedConstants)
SendMessage(handle, WM_VSCROLL, SB_BOTTOM, 0,SelectedConstants)


but can't make it work.

Andy.
Title: Re: Rich edit scroll
Post by: LarryMc on November 07, 2018, 08:03:21 AM
try this

lines = CONTROLCMD ( window | dialog, ID, @RTGETLINECOUNT)

CONTROLCMD (window | dialog, ID, @RTSCROLL, lines, 0)
Title: Re: Rich edit scroll
Post by: fasecero on November 07, 2018, 10:08:43 AM
Tricky one. Didn't test Larry's method but here's another alternative I as trying to get working... :P

HWND handle = GetDlgItem(win.hwnd, SelectedConstants)
_SendMessage(handle, EM_SETSEL, 0, -1)
_SendMessage(handle, EM_SETSEL, -1, -1)
_SendMessage(handle, EM_SCROLLCARET, 0, 0)


Use this after adding the text.
Title: Re: Rich edit scroll
Post by: Egil on November 07, 2018, 12:47:08 PM
Here is how can be done using an Edit Control:

http://www.ionicwind.com/forums/index.php?topic=3174.msg25946#msg25946 (http://www.ionicwind.com/forums/index.php?topic=3174.msg25946#msg25946)


Good luck!

Egil
Title: Re: Rich edit scroll
Post by: Andy on November 08, 2018, 12:00:09 AM
Thanks everyone!

I've tried them all and Fasecero's code was the one that worked.

I noticed that if the last line added was a long one, the horizontal scroll bar was moved across i.e. not at the left hand side, so I added another SendMessage command to set it back.

So now the program scrolls vertically to the bottom line and remains horizontally left - just what I wanted the program to do.

HWND handle = GetDlgItem(win.hwnd, SelectedConstants)
_SendMessage(handle, EM_SETSEL, 0, -1)
_SendMessage(handle, EM_SETSEL, -1, -1)
_SendMessage(handle, EM_SCROLLCARET, 0, 0)
SendMessage(handle, WM_HSCROLL, SB_PAGELEFT, 0)


Thanks,
Andy.
:)
Title: Re: Rich edit scroll
Post by: h3kt0r on November 10, 2018, 12:47:25 PM
From Microsoft Win32 Programmer's Reference wich you can get here (http://idquodnescis.we.bs/public/Win32.chm) in CHM format :

Quote
EM_LINESCROLL

An application sends an EM_LINESCROLL message to scroll the text vertically or horizontally in a multiline edit control.

EM_LINESCROLL

wParam = (WPARAM) cxScroll; // characters to scroll horizontally

lParam = (LPARAM) cyScroll; // lines to scroll vertically


Parameters

cxScroll

Value of wParam. Specifies the number of characters to scroll horizontally.

cyScroll

Value of lParam. Specifies the number of lines to scroll vertically.


Return Values

If the message is sent to a multiline edit control, the return value is TRUE; if the message is sent to a single-line edit control, the return value is FALSE.

Remarks

The edit control does not scroll vertically past the last line of text in the edit control. If the current line plus the number of lines specified by the cyScroll parameter exceeds the total number of lines in the edit control, the value is adjusted so that the last line of the edit control is scrolled to the top of the edit-control window.

The EM_LINESCROLL message can be used to scroll horizontally past the last character of any line.

Working snippet :

$INCLUDE "windowssdk.inc"

Int lcount, stringcount
String somestring$ : somestring$ = "This is string #"
Istring _Log$[50000]
CONST EDIT_1 = 1
CONST BUTTON_1 = 2
CONST BUTTON_2 = 3
DIALOG MyDlg
CREATEDIALOG MyDlg,0,0,300,222,0x80CA0080,0,"Edit Control Scroll Test",&MyDlg_handler
CONTROL MyDlg,@EDIT,"",10,10,280,180,0x50A00804|@BORDER|@TABSTOP,EDIT_1
CONTROL MyDlg,@BUTTON,"Scroll To Bottom",60,195,80,20,0x50008000|@TABSTOP,BUTTON_1
CONTROL MyDlg,@BUTTON,"Scroll To Top",160,195,80,20,0x50008000|@TABSTOP,BUTTON_2
' main loop
DOMODAL MyDlg
END

SUB MyDlg_handler
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW MyDlg
/* Initialize any controls here */
SETCONTROLCOLOR MyDlg,BUTTON_1,0,RGB(0,255,255)
SETCONTROLCOLOR MyDlg,BUTTON_2,RGB(255,0,255),0
For stringcount = 1 to 1000
_Log$ = _Log$ + "\n" + somestring$ + space$(1) + str$(stringcount)
Next stringcount

SetControlText (MyDlg, EDIT_1, _Log$)

CASE @IDCLOSEWINDOW
CLOSEDIALOG MyDlg,@IDOK
CASE @IDCONTROL
SELECT @CONTROLID
CASE EDIT_1
/* respond to edit notifications here */

CASE BUTTON_1
IF @NOTIFYCODE = 0
/*button clicked*/
Edit_Scroll_2bottom()
ENDIF

CASE BUTTON_2
IF @NOTIFYCODE = 0
/*button clicked*/
Edit_Scroll_2Top()
ENDIF

ENDSELECT
ENDSELECT
RETURN 0
ENDSUB


Sub Edit_Scroll_2bottom()

  lcount = CONTROLCMD ( MyDlg, EDIT_1, @EDGETLINECOUNT)
  SendMessage(MyDlg, EM_LINESCROLL, 0, lcount, EDIT_1)

return
EndSub

Sub Edit_Scroll_2Top()

Int top
  lcount = CONTROLCMD ( MyDlg, EDIT_1, @EDGETLINECOUNT)
  top = lcount - 1
  SendMessage(MyDlg, EM_LINESCROLL, 0, -top, EDIT_1)

return
EndSub
Title: Re: Rich edit scroll
Post by: Andy on November 11, 2018, 02:54:38 AM
Hektor,

I like the code you've posted, think I'll add it in to my program - thanks!

Andy.
:)