Click to See Complete Forum and Search --> : CRichEditCtrl - How to Scroll to a line


Eli Vingot
March 29th, 1999, 06:10 AM
Hi,


I am sure I'm missing something.


I implemented a "find" on a Rich Edit control and I want to verify that the "found" word is visible.


I see how to get the current line and the first visible line, but how can I get the LAST VISIBLE LINE to know if the control needs scrolling.


I tried to get it using the EM_CHARFROMPOS (with LPARAM being the bottom left corner of the control) but it crashed the application. (in Win98)


Any help will be appreciated.


Thanks,


Eli

indika
March 29th, 1999, 09:36 AM
What I did to do this was:

I got the client rectangle, and the character height and determined how many lines could fit in the control. them I

went to the topLine + HowManyLines and got the line length of that line. that is my last pos

//this code is old and I forget what I was doing, basikally the algorithm is as above. Good luck.

CRichEditCtrl &Ctrl = GetRichEditCtrl();

CRect clientRect;

GetClientRect(&clientRect);

CPaintDC dc(this);

TEXTMETRIC tm;

dc.GetTextMetrics(&tm);

ReleaseDC((CDC *) &dc);

CSize m_cellSize;

m_cellSize.cx = tm.tmAveCharWidth;

m_cellSize.cy = tm.tmHeight + tm.tmExternalLeading;

LPCSTR str = (LPCSTR) malloc(3000);

LRESULT p = ::SendMessage( GetSafeHwnd(), // handle of destination window

EM_GETFIRSTVISIBLELINE, // message to send

(WPARAM) 0, // first message parameter

(LPARAM) 0 );

// Determine first and last visible lines

// (first and last may be partial)

int i = p;

int last = clientRect.Height()/m_cellSize.cy + 2 + i;