创建一个成员变量
private:
CPoint m_ptOrigin;
鼠标左键点击消息
void CDrawView::OnLButtonDown(UINT nFlags, CPoint point)
{
m_ptOrigin=point;
CView::OnLButtonDown(nFlags, point);
}
鼠标左键松开消息
划线
void CDrawView::OnLButtonUp(UINT nFlags, CPoint point)
{
CDC* pDC = GetDC();
pDC->MoveTo(m_ptOrigin);
pDC->LineTo(point);
ReleaseDC(pDC);
CView::OnLButtonUp(nFlags, point);
}
画笔??????? CPen
void CDrawView::OnLButtonUp(UINT nFlags, CPoint point)
{
CPen pen(PS_SOLID,2,RGB(255,0,0));
CClientDC dc(this);
CPen* pOldPen =dc.SelectObject(&pen);
dc.MoveTo(m_ptOrigin);
dc.LineTo(point);
dc.SelectObject(pOldPen);
CView::OnLButtonUp(nFlags, point);
}
画刷??????? CBrush
void CDrawView::OnLButtonUp(UINT nFlags, CPoint point)
{
//创建一个红色画刷
CBrush brush(RGB(255,0,0));
//创建并获得设备描述表
CClientDC dc(this);
//利用红色画刷填充鼠标拖拽过程中形成的矩形区域
dc.FillRect(CRect(m_ptOrigin,point),&brush);
CView::OnLButtonUp(nFlags, point);
}
位图资源??????? CBitmap
引入资源
图片只支持.bmp格式的
?
void CDarwView::OnLButtonUp(UINT nFlags, CPoint point)
{
CClientDC dc(this);
CPen pen(PS_SOLID,5,RGB(255,255,0));//线的类型,粗度,
dc.SelectObject(&pen);//安装画笔
CBitmap bitmap;
bitmap.LoadBitmap(IDB_BITMAP1);
CBrush brush(&bitmap);
dc.SelectObject(&brush);
dc.Rectangle(m_ptOrigin.x,m_ptOrigin.y,point.x,point.y);
CView::OnLButtonUp(nFlags, point);
}
|