3.4.2 具体实现(4)
② 定义CTelnetView类的构造函数CTelnetView(),用于实现初始化工作。具体实现代码如下:
- CTelnetView::CTelnetView()
- {
- cTextColor = RGB(0, 200, 000); //设置字体颜色,此处是绿色
- cBackgroundColor = RGB(000, 000, 000); //设置背景颜色,此处是黑色
- cSock = NULL;
- bOptionsSent = FALSE;
- TempCounter = 0;
- cCursX = 0;
- CurrentXX = 0; //初始窗口的位置
- CurrentYY = 0;
-
- IfOutput = false;
- // OffsetNum = 0;
- for(int x=0; x<80; x++)
- {
- for(int y=0; y<bufferLines; y++)
- {
- cText[x][y] = ' ';
- }
- }
- }
③ 定义CTelnetView类的构造函数CTelnetView(),如果cSock为空则释放。具体代码如下: - CTelnetView::~CTelnetView()
- {
- if(cSock != NULL)
- delete cSock;
- cSock = NULL;
- }
④ 定义函数PreCreateWindow(),设定窗口的风格,CREATESTRUCT是窗口的风格数据结构。具体代码如下: - BOOL CTelnetView::PreCreateWindow(CREATESTRUCT &cs)
- {
- return CScrollView::PreCreateWindow(cs);
- }
⑤ 定义函数OnDraw(CDC *pDC)以及DoDraw(CDC *pDC),实现窗口绘制,具体代码如下: - void CTelnetView::OnDraw(CDC *pDC)
- {
- CTelnetDoc *pDoc = GetDocument();
- ASSERT_VALID(pDoc);
-
- pDC->SelectObject(GetStockObject(ANSI_FIXED_FONT));
-
- DrawCursor(pDC, FALSE);
- DoDraw(pDC);
- DrawCursor(pDC, TRUE);
- }
-
- void CTelnetView::DoDraw(CDC *pDC)
- {
- CString strLine;
- BOOL bSkip = FALSE;
- CRect clip;
- pDC->GetClipBox(clip);
- clip.top -= dtY;
-
- pDC->SetTextColor(cTextColor);
- // pDC->SetBkColor(cBackgroundColor);
-
- // CurrentXX = 0;
- char text[2] = {0x00, 0x00};
-
- for(int y=0; y<bufferLines; y++)
- {
- //if(y*dtY >= clip.top)
- //{
- for(int x=0; x<80; x++)
- {
- text[0] = cText[x][y];
- if(text[0] == 27)
- bSkip = TRUE;
- if(!bSkip)
- strLine += text[0];
- if(text[0]=='m' && bSkip)
- bSkip = FALSE;
- }
- pDC->TextOut(0, y*dtY, strLine);
- strLine.Empty();
- //}
- }
- }