|
- void CGraphicView::OnLButtonDown(UINT nFlags, CPoint point)
- {
- //鼠标按下,设置坐标.
- m_ptOrigin = point;
- CView::OnLButtonDown(nFlags, point);
- }
-
- void CGraphicView::OnLButtonUp(UINT nFlags, CPoint point)
- {
- //构造一个DC,传入当前对象.表示在当前对象使用.
- CClientDC dc(this);
- //创建一个画笔.(线的类型, 宽度, 颜色);
- CPen pen(PS_SOLID, 1, RGB(255, 0, 0));
- //把画笔选到设置描述表当中.覆盖默认画笔.
- dc.SelectObject(&pen);
- //创建一个透明的画刷,来填充矩形的内部.
- CBrush *pBrush = CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
- //把画刷加入设置描述表.
- dc.SelectObject(pBrush);
-
- switch(m_nDraeType) {
- case 1:
- //画点,传入一个坐标,设置画出的颜色.
- dc.SetPixel(point, RGB(255, 0, 0));
- break;
- case 2:
- //画直线.
- dc.MoveTo(m_ptOrigin); //光标移动到按下鼠标的位置.
- dc.LineTo(point); //画线画到鼠标抬起的位置.
- break;
- case 3:
- //画矩行.传入一个矩行对象.
- dc.Rectangle(CRect(m_ptOrigin, point));
- break;
- case 4:
- //画椭圆.传入一个矩行对象.
- dc.Ellipse(CRect(m_ptOrigin, point));
- break;
- }
-
- CView::OnLButtonUp(nFlags, point);
- }
复制代码
|
|