Board index » cppbuilder » Knowing first/last line/column numbers in TRichEdit

Knowing first/last line/column numbers in TRichEdit


2004-09-24 05:59:43 PM
cppbuilder63
Cracow, 24.09.2004
Hi,
I want to display (on the status bar) the numbers of the
first and last text lines and columns currently visible in the
TRichEdit control. I have managed to figure out how to
determine the first visible line, but I have not succeeded
with the last line and with the first and last text columns.
I also do not know where to put the commands which display
this information on the status bar. I guess the info should be
updated every time whan the control text is scrolled, either by
using keybord keys (cursors, PgUp/PgDn) or by using scrollers
attached to the TRichEdit control. Where would be the
relevant event handler? This is in contrast to displaying the
current cursor positions, which can be easily done.
I have Builder 4.0.
L.B.
 
 

Re:Knowing first/last line/column numbers in TRichEdit

Hi L.B.,
You can determine when to update your text by using a combination of
the EN_VSCROLL/EN_HSCROLL notification messages (for notification of
scrolling via the keyboard) and the WM_VSCROLL/WM_HSCROLL notification
messages (scrolling via the scroll bars). See the following example...
cppbuilderdevjournal.com/bcbcaq/CAQs/caq29.htm
Also, you can determine the first and last visible line numbers via the
following approach...
HWND hRichEdit = RichEdit->Handle;
// find the index of the top visible line
POINTL POrg = {0, 0};
int char_index = SNDMSG(
hRichEdit, EM_CHARFROMPOS, 0,
reinterpret_cast<LPARAM>(&POrg)
);
int start_line = SNDMSG(
hRichEdit, EM_EXLINEFROMCHAR, 0, char_index
);
// find the index of the last visible line
POINTL PEnd = {0, RichEdit->ClientHeight};
char_index = SNDMSG(
hRichEdit, EM_CHARFROMPOS, 0,
reinterpret_cast<LPARAM>(&PEnd)
);
int stop_line = SNDMSG(
hRichEdit, EM_EXLINEFROMCHAR, 0, char_index
);
// results stored in start_line and stop line
HTH,
Leslaw Bieniasz wrote:
Quote
Cracow, 24.09.2004
Hi,
I want to display (on the status bar) the numbers of the
first and last text lines and columns currently visible in the
TRichEdit control. [...] Where would be the
relevant event handler? This is in contrast to displaying the
current cursor positions, which can be easily done.