16,472
社区成员
发帖
与我相关
我的任务
分享
CDC*pDC=GetDC();
CRect rect;
GetClientRect(&rect);
PBYTE pBuffer;
pBuffer = new BYTE[rect.Width()*rect.Height()*3];
CBitmap Bmp,*pBmp;
Bmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
CDC memDC;
memDC.CreateCompatibleDC(pDC);
pBmp=memDC.SelectObject(&Bmp);
memDC.BitBlt(rect.left, rect.top, rect.right, rect.bottom, pDC,0,0,SRCCOPY);
pBmp=memDC.SelectObject(pBmp);
pBmp->GetBitmapBits(rect.Width()*rect.Height()*3,pBuffer);
if(m_DrawType==1) //画直线
{
pDC->MoveTo(m_StartPoint);
pDC->LineTo(m_EndPoint);
}
void CXXXView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_StartPoint=point; //起始点为鼠标按下的点
CView::OnLButtonDown(nFlags, point);
}
void CXXXView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_EndPoint=point; //终止点为鼠标当前位置
Invalidate();
CView::OnMouseMove(nFlags, point);
}
void CXXXView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_EndPoint=point; //终止点为鼠标当前位置
Invalidate(); //刷新界面
CView::OnLButtonUp(nFlags, point);
}