我正在用 MFC 做一个小型绘图工具。
我定义了五种形状:矩形、直线、圆形、椭圆和点。intm_drawType
用于在五种形状之间切换。
代码如下:
void CDrawToolView::OnLButtonDown(UINT nFlags, CPoint point)
{
m_startRect=TRUE;
m_startPoint=point;
m_OldPoint=point;
::SetCursor(m_HCross);
CView::OnLButtonDown(nFlags, point);
}
void CDrawToolView::OnMouseMove(UINT nFlags, CPoint point)
{
CClientDC dc(this);
dc.SetROP2(R2_NOT);
dc.SetROP2(R2_NOT);
dc.SelectStockObject(NULL_BRUSH);
if(TRUE==m_startRect)
{
switch(m_drawType)
{
case 1://Rectangle
::SetCursor(m_HCross);
dc.Rectangle(CRect(m_startPoint,m_OldPoint));
dc.Rectangle(CRect(m_startPoint,point));
m_OldPoint=point;
break;
case 2: //Line
::SetCursor(m_HCross);
dc.MoveTo(m_startPoint);
dc.LineTo(m_OldPoint);
dc.MoveTo(m_startPoint);
dc.LineTo(point);
m_OldPoint=point;
break;
.
.
.
}
}
CView::OnMouseMove(nFlags, point);
}
void CDrawToolView::OnLButtonUp(UINT nFlags, CPoint point)
{
m_startRect=FALSE;
::ClipCursor(NULL);
CClientDC dc(this);
dc.SelectStockObject(NULL_BRUSH);
switch(m_drawType)
{
case 1: //Retangle
dc.Rectangle(CRect(m_startPoint,m_OldPoint));
dc.Rectangle(CRect(m_startPoint,point));
break;
case 2: //Line
dc.MoveTo(m_startPoint);
dc.LineTo(m_OldPoint);
dc.MoveTo(m_startPoint);
dc.LineTo(point);
break;
.
.
.
}
CView::OnLButtonUp(nFlags, point);
}
void CDrawToolView::OnEditShape() // when click menu-edit-shape a dialog is pop up
{
CShapeDlg dlg;
dlg.DoModal();
}
弹出对话框如下:
我创建了一个包含五个按钮的对话框。我的问题是我不知道如何在按钮和这五个形状之间建立联系。有人可以帮我吗?