August 22, 2019, 12:15:45 pm

News:

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


Rich edit scroll

Started by Andy, November 07, 2018, 07:08:19 am

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

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.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

fasecero

This works for a window

Code Select


SendMessage(hwnd, WM_VSCROLL, SB_BOTTOM, 0)


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

Code Select

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


Andy

Thanks Fasecero,

tried this....

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


but can't make it work.

Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

try this

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

CONTROLCMD (window | dialog, ID, @RTSCROLL, lines, 0)
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

fasecero

November 07, 2018, 10:08:43 am #4 Last Edit: November 07, 2018, 10:10:23 am by fasecero
Tricky one. Didn't test Larry's method but here's another alternative I as trying to get working... :P

Code Select
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.

Egil

Support Amateur Radio  -  Have a ham  for dinner!

Andy

November 08, 2018, 12:00:09 am #6 Last Edit: November 08, 2018, 12:31:11 am by Andy
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.

Code Select
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.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

h3kt0r

November 10, 2018, 12:47:25 pm #7 Last Edit: November 10, 2018, 02:37:04 pm by h3kt0r
From Microsoft Win32 Programmer's Reference wich you can get here 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 :

Code Select
$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

Andy

Hektor,

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

Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.