3.4.2 具体实现(5)
⑥ 定义函数OnInitialUpdate(),用于计算当前视图的初始化位置,具体代码如下:
- void CTelnetView::OnInitialUpdate()
- {
- CSize sizeTotal;
-
- // TODO: calculate the total size of this view
- sizeTotal.cx = dtX * 80 + 3;
- sizeTotal.cy = dtY * bufferLines + 3;
- SetScrollSizes(MM_TEXT, sizeTotal);
- //SetWindowPos(NULL, 0,0, sizeTotal.cx, sizeTotal.cy, SWP_NOMOVE);
-
- CScrollView::OnInitialUpdate();
- }
⑦ 定义函数OnPreparePrinting ()等,用于实现打印功能,具体代码如下: - BOOL CTelnetView::OnPreparePrinting(CPrintInfo *pInfo)
- {
- // 默认打印准备
- return DoPreparePrinting(pInfo);
- }
-
- void CTelnetView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
-
- void CTelnetView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
-
- // CTelnetView diagnostics
-
- #ifdef _DEBUG
- void CTelnetView::AssertValid() const
- {
- CScrollView::AssertValid();
- }
-
- void CTelnetView::Dump(CDumpContext &dc) const
- {
- CScrollView::Dump(dc);
- }
⑧ 定义函数GetDocument(),用于在非调试环境下运行此函数,具体代码如下: - CTelnetDoc* CTelnetView::GetDocument()
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTelnetDoc)));
- return (CTelnetDoc*)m_pDocument;
- }
- #endif //_DEBUG
⑨ 定义函数ProcessMessage(),用于接受并分析数据,具体代码如下: - //接收分析数据
- void CTelnetView::ProcessMessage(CClientSocket *pSock)
- {
- if(!IsWindow(m_hWnd)) return;
- if(!IsWindowVisible()) return;
- //保存数据到m_bBuf
- int nBytes = pSock->Receive(m_bBuf, ioBuffSize);
- if(nBytes != SOCKET_ERROR)
- {
- int ndx = 0;
- //每次读入一行数据
- while(GetLine(m_bBuf, nBytes, ndx) != TRUE);
- //进行协商
- ProcessOptions();
- MessageReceived(m_strNormalText);
- }
- m_strLine.Empty();
- m_strResp.Empty();
- }