您的位置: 旅游网 > 影视 >> 喜剧

中利用设计绘图程序初步呢

发布时间:2021-10-28 05:37:43

首先我们说下通过鼠标的移动来绘制直线。

这里要捕获到鼠标的两个消息:WM_LBUTTONDOWN, WM_LBUTTONUP。响应WM_LBUTTONDOWN消息记录直线的起始点,响应WM_LBUTTONUP消息记录直线的终点并绘制直线。

好了,我们看看怎么响应。

void CDrawView::OnLButtonDown(UINT nFlags, CPoint point)

{

//MessageBox(\"Left Button Clicks DrawView\");

m_ptOrigin = point ; //这里先定义了一个内部变量保存直线的起始点

CView::OnLButtonDown(nFlags, point);

}

下面看看响应WM_LBUTTONUP消息记录直线的终点并绘制直线。

//方法一

void CDrawView::OnLButtonUp(UINT nFlags, CPoint point)

{

HDC hdc;

hdc = ::GetDC(m_hWnd); //调用全局函数

MoveToEx(hdc,m_ptOrigin.x,m_ptOrigin.y,0);

LineTo(hdc,point.x,point.y);

::ReleaseDC(m_hWnd,hdc);

CView::OnLButtonUp(nFlags, point);

}

//方法二

void CDrawView::OnLButtonUp(UINT nFlags, CPoint point)

{

CDC *pDC = GetDC();

pDC-MoveTo(m_ptOrigin);

pDC-LineTo(point);

ReleaseDC(pDC);

}

//方法三

void CDrawView::OnLButtonUp(UINT nFlags, CPoint point)

{

CClientDC dc(this) ; //CClientDC对象构造的时候就调用了GetDC,析构的时候调用

ReleaseDC ,只能访问客户区

CClientDC dc(GetParent());

veTo(m_ptOrigin);

neTo(point);

}

//方法四

void CDrawView::OnLButtonUp(UINT nFlags, CPoint point)

{

CWindowDC dc(this) ; //CWindowDC可以访问客户区和非客户区

veTo(m_ptOrigin);

neTo(point);

}

void CDrawView::OnLButtonUp(UINT nFlags, CPoint point)

{

CWindowDC dc(GetDesktopWindow()) ; //现在可以访问桌面

veTo(m_ptOrigin);

neTo(point);

}

连续线绘图:

思路:鼠标移动的信号被捕捉到,然后随时响应该信号,绘制图线。

这里要设置一个BOOL变量 m_bDraw 来判断是否鼠标左键按下了。

//画连续的线条

void CDrawView::OnMouseMove(UINT nFlags, CPoint point)

{

if ( m_bDraw )

{

CClientDC dc(this) ;

veTo(m_ptOrigin); //移动到原来的点

neTo(point); //绘制直线

m_ptOrigin = point ; //将现在的点赋值给原来的坐标,以便下次调用

}

CView::OnMouseMove(nFlags, point);

}

//改变画笔的颜色

void CDrawView::OnMouseMove(UINT nFlags, CPoint point)

{

if ( m_bDraw )

{

CClientDC dc(this) ;

CPen pen( PS_SOLID , 1 , RGB(255,128,128) );

CPen *pOldPen = lectObject(pen);

veTo(m_ptOrigin);

neTo(point);

m_ptOrigin = point ;

lectObject(pOldPen);

}

CView::OnMouseMove(nFlags, point);

}

//画扇型

void CDrawView::OnMouseMove(UINT nFlags, CPoint point)

{

if ( m_bDraw )

{

CClientDC dc(this) ;

CPen pen( PS_SOLID , 1 , RGB(255,128,128) );

CPen *pOldPen = lectObject(pen);

但由于F-86过于笨重 veTo(m_ptOrigin);

neTo(m_ptOld);

veTo(m_ptOrigin);

neTo(point);

m_ptOld = point ;

lectObject(pOldPen);

}

CView::OnMouseMove(nFlags, point);

}

//画带边线的扇型

void CDrawView::OnMouseMove(UINT nFlags, CPoint point)

{

if ( m_bDraw )

{

CClientDC dc(this) ;

CPen pen( PS_SOLID , 1 , RGB(255,128,128) );

CPen *pOldPen = lectObject(pen);

veTo(m_ptOrigin);

neTo(m_ptOld);

veTo(m_ptOrigin);

neTo(point);

veTo(m_ptOld);

neTo(point);

m_ptOld = point ;

lectObject(pOldPen);

}

CView::OnMouseMove(nFlags, point);

}

//看看绘图的模式设置方法

void CDrawView::OnMouseMove(UINT nFlags, CPoint point)

{

if ( m_bDraw )

{

CClientDC dc(this) ;

tROP2(R2_BLACK); //绘图的模式设置,始终绘制黑色图形

CPen pen( PS_SOLID , 1 , RGB(255,128,128) );

CPen *pOldPen = lectObject(pen);

veTo(m_ptOrigin);

neTo(m_ptOld);

veTo(m_ptOrigin);

neTo(point);

veTo(m_ptOld);

neTo(point);

m_ptOld = point ;

lectObject(pOldPen);

}

CView::OnMouseMove(nFlags, point);

}

到此,我们知道了一般地绘图方法了。查看本文来源

永州白癜风医院哪家好
重庆治疗白癜风医院哪好
西安哪家医院做人流好
猜你会喜欢的
猜你会喜欢的