3.4.2 具体实现(10)
- {
- cText[col][bufferLines-1] = ' ';
- }
- CurrentYYCurrentYY = CurrentYY - 1;
- DoDraw(pDC);
- }
- }
- loop++;
- break;
- default: //输出数据
- {
- cText[CurrentXX][CurrentYY] = pText[loop];
- m_strline.Empty();
- for (int i=0; i<80; i++)
- {
- if (cText[i][CurrentYY] != 27)
- m_strline += cText[i][CurrentYY];
- else
- break;
- }
- pDC->TextOut(0, CurrentYY*dtY, m_strline);
- CurrentXX++;
- }
- tempStr2.Empty();
- loop++;
- break;
- }
- }
- DrawCursor(pDC, TRUE);
- ReleaseDC(pDC);
- }
⑯定义函数OnChar(),用于实现按键处理,具体代码如下:- //按键处理
- void CTelnetView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
- {
- //发出回车键
- if (nChar == VK_RETURN)
- {
- DispatchMessage("\r\n");
- }
- else
- {
- DispatchMessage(nChar);
- }
- }
⑰定义函数DrawCursor(),用于在屏幕上绘制光标,具体代码如下:- //画光标
- void CTelnetView::DrawCursor(CDC *pDC, BOOL pDraw)
- {
- COLORREF color;
- CMainFrame *frm = (CMainFrame*)GetTopLevelFrame();
- if(pDraw) //draw
- {
- color = cTextColor;
- }
- else //erase
- {
- color = cBackgroundColor;
- }
- CRect rect(CurrentXX * dtX + 2, CurrentYY * dtY + 1,
- CurrentXX * dtX + dtX - 2, CurrentYY * dtY + dtY -1);
- pDC->FillSolidRect(rect, color);
- }
-
- void CTelnetView::OnSize(UINT nType, int cx, int cy)
- {
- CScrollView::OnSize(nType, cx, cy);
- if(IsWindow(m_hWnd))
- {
- if(IsWindowVisible())
- {
- //ScrollToPosition(
- CPoint(0, bufferLines * 1000)); //go way past the end
- }
- }
- }