我在EVC下创建了一个基于担文档的工程,工程目的是对串口数据缓冲区的读写操作,在读取时读取数据比较多,一个屏幕显示不了,因为我的视类是继承CScrollView
[复制链接]
void CSuper_TerminalView::OnDraw(CDC* pDC)
{
CSuper_TerminalDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CRect rect;
GetClientRect(rect);
TEXTMETRIC tm;
pDC->GetTextMetrics(&tm);
CreateSolidCaret(tm.tmAveCharWidth/8,tm.tmHeight);
ShowCaret();
pDC->DrawText(m_strbuf,rect,NULL);
CSize sz = pDC->GetTextExtent(m_strbuf);
CPoint pt;
pt.x = m_ptOrigin.x + sz.cx;
pt.y = m_ptOrigin.y + sz.cy;
SetCaretPos(pt);
}
/////////////////////////////////////////////////////////////////////////////
// CSuper_TerminalView diagnostics
#ifdef _DEBUG
void CSuper_TerminalView::AssertValid() const
{
CScrollView::AssertValid();
}
void CSuper_TerminalView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CSuper_TerminalDoc* CSuper_TerminalView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSuper_TerminalDoc)));
return (CSuper_TerminalDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CSuper_TerminalView message handlers
void CSuper_TerminalView::OnSetting()
{
// TODO: Add your command handler code here
CSetPortDlg dlg;
dlg.DoModal();
}
int CSuper_TerminalView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CScrollView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
return 0;
}
void CSuper_TerminalView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
SetCaretPos(point);
m_strbuf.IsEmpty();
m_ptOrigin = point;
CScrollView::OnLButtonDown(nFlags, point);
CClientDC dc(this);
OnPrepareDC(&dc); //调整设备上下文的属性,设置了视口原点
dc.DPtoLP(&m_ptOrigin); //设备坐标转换为逻辑坐标
}
void CSuper_TerminalView::OnSent()
{
// TODO: Add your command handler code here
CSendDataDlg dlg;
dlg.DoModal();
}
void CSuper_TerminalView::OnReceive()
{
if (g_hComm == INVALID_HANDLE_VALUE) return;
BYTE buffer[1025];
memset(buffer,'\0',1025);
DWORD wCount = 0;
CMainFrame* pMain = (CMainFrame*)AfxGetMainWnd();
wCount=pMain->ReadComm(buffer, 1024); //读取的字节数,
buffer[wCount] = '\0';
m_strbuf=buffer;
Invalidate(TRUE);
}
void CSuper_TerminalView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
int nMin,nMax,nCurpos;
pScrollBar->GetScrollRange(&nMin,&nMax); //取得滚动条范围
nCurpos=pScrollBar->GetScrollPos(); //取得当前值
switch(nSBCode) //处理滚动信息
{
case SB_LINEUP: //向左的箭头被按下
nCurpos=nCurpos-5;
break;
case SB_LINEDOWN:
nCurpos++;
break; //向右的箭头被按下
case SB_THUMBTRACK: //鼠标拖动
nCurpos=nPos;
break;
}
if(nCurpos >nMax) nCurpos=nMax;
pScrollBar->SetScrollPos(nCurpos); //更新信息
//处理你想处理的东西
CScrollView::OnVScroll(nSBCode, nPos, pScrollBar);
}
void CSuper_TerminalView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
CClientDC dc(this);
CRect rect;
GetClientRect(rect);
dc.DrawText(m_strbuf,rect,NULL);
CSize sizeTotal = dc.GetTextExtent(m_strbuf);;
// sizeTotal.cx = 200;
// sizeTotal.cy = 820;
SetScrollSizes(MM_TEXT, sizeTotal);
}
void CSuper_TerminalView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
// TODO: Add your specialized code here and/or call the base class
CScrollView::OnPrepareDC(pDC, pInfo);
}