|
coordString---坐标字符串
drawPt--绘制起点坐标 void CDrawMouseView::DrawCoord(CDC* pDC,CString& coordString,CPoint drawPt) { if(m_StoreBmp.GetSafeHandle())//有位图才画 { drawPt.Offset(OFF_X,OFF_Y); CRect rect(drawPt,CSize(m_nCoordStrLen,WORD_HEIGHT)); pDC->SetBkMode(TRANSPARENT);//设置透明背景 COLORREF crf = pDC->SetTextColor(TEXT_COLOR); pDC->DrawText(coordString,rect,DT_CENTER); pDC->SetTextColor(crf); } }
//擦除上次的坐标 void CDrawMouseView::DoRubberCoord(CDC* pDC,CPoint showPt) { if(m_StoreBmp.GetSafeHandle()) { m_StoreDC.SelectObject(&m_StoreBmp); pDC->BitBlt(showPt.x+OFF_X,showPt.y+OFF_Y,m_nCoordStrLen,WORD_HEIGHT,&m_StoreDC,0,0,SRCCOPY); m_StoreDC.DeleteDC(); m_StoreBmp.DeleteObject(); } } //鼠标移动事件 void CDrawMouseView::OnMouseMove(UINT nFlags, CPoint point) { CDC* pDC = GetDC(); if(!m_bStart) m_bStart = true; else DoRubberCoord(pDC,m_OldPt);//当不是第一次移动鼠标时才需要先擦除上次的坐标 CString str; str.Format("[%d,%d]",point.x,point.y); m_nCoordStrLen=str.GetLength()*WORD_WIDTH; m_OldPt = point; CopyBitmap(pDC,point); DrawCoord(pDC,str,point); ReleaseDC(pDC); } |