// CPrtintView message handlers
void CPrtintView::OnLButtonDown(UINT nFlags, CPoint point) //起点{
m_oriagl=m_pold=point;//确定起始点
draw=true;//判断鼠标左键是否弹起的变量
CView::OnLButtonDown(nFlags, point);
}
void CPrtintView::OnLButtonUp(UINT nFlags, CPoint point) //终点
{
// TODO: Add your message handler code here and/or call default
draw=false;
/*HDC hdc;
hdc=::GetDC(m_hWnd);
MoveToEx(hdc,m_oriagl.x,m_oriagl.y,NULL);//将点移动到原点,线是从原点开始画的
LineTo(hdc,point.x,point.y);
::ReleaseDC(m_hWnd,hdc);*/
//使用CDC类来操作
/* CDC *pdc=GetDC();
pdc->MoveTo(m_oriagl);
pdc->LineTo(point);
ReleaseDC(pdc);*/
//使用CClientDC类自动调用GetDC()和ReleseDC()函数
/*CClientDC dc(this);---view类窗口的指针
//CClientDC dc(GetParent());//调用父窗口即CWND的指针
dc.MoveTo(m_oriagl);
dc.LineTo(point);*/
//使用CWindowDC类,可以访问整个屏幕区域,包括客户区和非客户区
/*//CWindowDC dc(this);//可画在VIEW区
//CWindowDC dc(GetParent());//可画在客户区和非客户区
CWindowDC dc(GetDesktopWindow());//桌面窗口
dc.MoveTo(m_oriagl);
dc.LineTo(point);*/
//画不同颜色的线--创建其他颜色的画笔并选到设备标识表中,使用结束后要选回
/* CPen pen(PS_SOLID,1,RGB(255,0,0));//创建笔
CClientDC dc(this);
CPen *oldpen=dc.SelectObject(&pen);
dc.MoveTo(m_oriagl);
dc.LineTo(point);
dc.SelectObject(oldpen);*/
//创建画刷
//CBrush brush(RGB(255,0,0));//创建颜色的画刷
//创建位图的画刷
/*CBitmap bitmap;
bitmap.LoadBitmap(IDB_BITMAP2);加载位图
CBrush brush(&bitmap);
CClientDC dc(this);
dc.FillRect(CRect(m_oriagl,point),&brush);*/
//创建透明画刷
/* CClientDC dc(this);
CBrush *pBrush=CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
CBrush *oldbrush=dc.SelectObject(pBrush);
dc.Rectangle(CRect(m_oriagl,point));
dc.SelectObject(oldbrush);*/
//画图形
CView::OnLButtonUp(nFlags, point);
}
void CPrtintView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
/*CClientDC dc(this);
CPen pen(PS_SOLID,1,RGB(255,0,0));
CPen *oldpen=dc.SelectObject(&pen);
if(draw==true)
{
dc.MoveTo(m_oriagl);
dc.LineTo(point);
m_oriagl=point;
}
dc.SelectObject(oldpen);*/
//画扇形
CClientDC dc(this);
if(draw==true)
{dc.MoveTo(m_oriagl);
dc.LineTo(m_pold);
dc.MoveTo(m_oriagl);
dc.LineTo(point);
m_pold=point;
}
CView::OnMouseMove(nFlags, point);
}