MFC中進行與繪圖相關的控制,首先先爲VIEW類添加一個成員變量 m_nDrawType,用來指定要畫的圖形 ,增長相應的菜單項用來繪製 點 直線 矩形 和 橢圓 在菜單項的響應函數中寫下面的代碼:函數
view plainthis
void CGraphicView::OnDot() url
{ spa
// TODO: Add your command handler code here .net
m_nDrawType = 1; code
} blog
void CGraphicView::OnLine() ip
{ get
// TODO: Add your command handler code here it
m_nDrawType = 2;
}
void CGraphicView::OnRectangle()
{
// TODO: Add your command handler code here
m_nDrawType = 3;
}
void CGraphicView::OnEllipse()
{
// TODO: Add your command handler code here
m_nDrawType = 4;
}
知道每種圖形相應的序號,而後就要繪圖,先是相應LBUTTONDOWM消息,記錄下當前點,而後再響應 LBUTTONUP消息 進行繪圖操做,代碼以下:
void CGraphicView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_ptOrigin = point;
CView::OnLButtonDown(nFlags, point);
}
void CGraphicView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
CPen pen(m_nLineStyle,m_nLineWidth,m_clr);
dc.SelectObject(&pen);
CBrush *pBrush=CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
dc.SelectObject(pBrush);
switch(m_nDrawType)
{
case
更多詳細介紹:http://url7.me/lvwE1