Click to See Complete Forum and Search --> : My view stops displaying after 17 CStrings


Chris MacDougall
October 6th, 1999, 03:48 PM
I have an SDI "hyperterm" like app. I read data in a com port and save it to a CString and CStringList object in the DOC. I display the data in the OnDraw() call in VIEW. The OnDraw() has a loop and the code is shown below to better describe what the heck it is (becuase I think I have narrowed it down to a display problem in OnDraw()). Here it is:

if(pDoc->GetDataTest())
{
CStringList* pLineList = pDoc->GetLineList();//get ptr to list of strings in doc
m_tempData = pDoc->GetString(); //get current/1st string from DOC
CSize cplength = pDC->GetTextExtent(m_tempData); //calculate size of text box
m_clHeight = cplength.cy; //get y offset

int iLine;
int cLastLine;
int cyLine = 0;

iLine = m_iTopLine;
cLastLine = m_iTopLine + m_clHeight + 1;
cLastLine = min(cLastLine, pLineList->GetCount());

CString strLine;
POSITION pos;

while(iLine < cLastLine) //loop for line feed, and display
{
//Draw a line of text
if((pos = pLineList->FindIndex(iLine)) != NULL)
{
strLine = pLineList->GetAt(pos);

pDC->TextOut(0,cyLine,strLine);
cyLine += m_clHeight;
iLine++;
}
}
m_tempData.Empty(); //clear temp string
strLine.Empty(); //clear drawn string
}

//////////////END loop OnDraw()/////////////
Problem: Works great until it tries to display more than 17 strLine's.
Do you see anything that would cause my view to stop displaying after 17 strLine calls are displayed?
Also it is a CSrollView class and by the way my scrolls don't view. Why? or another problem for later. Please feel free to critique the rest of the code while your at it and if you feel so inclined. Any suggestions are welcomed - thanks.

ChrisD
October 6th, 1999, 09:42 PM
Your formula for cLastLine is wrong
Try
cLastLine = = ((rc.Height() - m_iTopLine) / m_clHeight) + 1;

HTH,
Chris

Jason Teagle
October 7th, 1999, 06:14 AM
Unless I am misreading the code, you are attempting to tell which is the last line on the display by using the variable cLastLine. The problem is, you are setting it to the result of the height returned by GetTextExtent() - which holds the number of PIXELS in a line of text. Therefore, your font is about 16 pixels high and hence you only get 16 or 17 lines of text.

If you are trying to tell when to stop printing text because it won't show on the screen, ignore cLastLine - use the number of lines of text in the document's lists (i.e. ALL lines), and when you have calculated its top, create a CRect using that top value, 0 for the left edge, GetClientRect()'s (to get the window size) 'right' member for the far right edge, and the top value + font height for the bottom. Then call CDC::RectVisible() with the rect to find out if the line will be drawn - if not, simply stop printing then.

As for the scrollbars not showing, it is because you need to keep calling SetScrollSizes() every time you add new data (or remove data, if necessary) to tell the view how big it is SUPPOSED to be - it defaults to 100 x 100 pixels.