mfc中点画线 画不出来
voidCMFCApplication3View::OnLButtonDown(UINTnFlags,CPointpoint){//TODO:在此添加消息处理程序代码和/...
void CMFCApplication3View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
if (m_yuan == 1)
{
m_Centerp = m_Aroundp = point;
}
CView::OnLButtonDown(nFlags, point);
}
void CMFCApplication3View::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CDC* pDC = GetDC();
if (m_yuan == 1)
{
m_Aroundp = point;
DrawCircle(pDC, m_Centerp, m_Aroundp);
}
ReleaseDC(pDC);
CView::OnLButtonUp(nFlags, point);
}
void CMFCApplication3View::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CDC* pDC = GetDC();
int nDrawmode = pDC->SetROP2(R2_NOT);
if (m_yuan == 1 & nFlags & MK_LBUTTON)
{
CPoint prePnt, curPnt;
prePnt = m_Aroundp;
curPnt = point;
DrawCircle(pDC, m_Centerp, prePnt);
DrawCircle(pDC, m_Centerp, curPnt);
m_Aroundp = point;
}
pDC->SetROP2(nDrawmode);
ReleaseDC(pDC);
CView::OnMouseMove(nFlags, point);
}
void CMFCApplication3View::MidpointCircle(CDC *pDC, int radius, CPoint cenp, COLORREF crColor)
{
int x = 0;
int y = radius;
int d = 1 - radius;
CirclePoints(pDC, x, y, cenp, crColor);
while (y >= x)
{
if (d<0)
d += 2 * x + 3;
else {
d += 2 * (x - y) + 5;
y--;
}
x++;
CirclePoints(pDC, x, y, cenp, crColor);
}
}
void CMFCApplication3View::CirclePoints(CDC *pDC, int x, int y, CPoint cenp, COLORREF br)
{
pDC->SetPixel(x + cenp.x, y + cenp.y, br);
pDC->SetPixel(y + cenp.x, x + cenp.y, br);
pDC->SetPixel(y + cenp.x, -x + cenp.y, br);
pDC->SetPixel(x + cenp.x, -y + cenp.y, br);
pDC->SetPixel(-x + cenp.x, -y + cenp.y, br);
pDC->SetPixel(-y + cenp.x, -x + cenp.y, br);
pDC->SetPixel(-y + cenp.x, x + cenp.y, br);
pDC->SetPixel(-x + cenp.x, y + cenp.y, br);
}
void CMFCApplication3View::Onyuan()
{
// TODO: Add your command handler code here
m_yuan = 1;
}
void CMFCApplication3View::DrawCircle(CDC *pDC, CPoint cenp, CPoint ardp)
{
int ra, a, b;
a = (ardp.x - cenp.x)*(ardp.x - cenp.x);
b = (ardp.y - cenp.y)*(ardp.y - cenp.y);
ra = (int)(sqrt(a + b));
pDC->Ellipse(cenp.x-ra,cenp.y-ra,cenp.x+ra,cenp.y+ra);
MidpointCircle(pDC, ra, cenp, cl);
}
void CMFCApplication3View::OnColor()
{
// TODO: 在此添加命令处理程序代码
CColorDialog dlg;
dlg.DoModal();
cl = dlg.GetColor();
} 展开
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
if (m_yuan == 1)
{
m_Centerp = m_Aroundp = point;
}
CView::OnLButtonDown(nFlags, point);
}
void CMFCApplication3View::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CDC* pDC = GetDC();
if (m_yuan == 1)
{
m_Aroundp = point;
DrawCircle(pDC, m_Centerp, m_Aroundp);
}
ReleaseDC(pDC);
CView::OnLButtonUp(nFlags, point);
}
void CMFCApplication3View::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CDC* pDC = GetDC();
int nDrawmode = pDC->SetROP2(R2_NOT);
if (m_yuan == 1 & nFlags & MK_LBUTTON)
{
CPoint prePnt, curPnt;
prePnt = m_Aroundp;
curPnt = point;
DrawCircle(pDC, m_Centerp, prePnt);
DrawCircle(pDC, m_Centerp, curPnt);
m_Aroundp = point;
}
pDC->SetROP2(nDrawmode);
ReleaseDC(pDC);
CView::OnMouseMove(nFlags, point);
}
void CMFCApplication3View::MidpointCircle(CDC *pDC, int radius, CPoint cenp, COLORREF crColor)
{
int x = 0;
int y = radius;
int d = 1 - radius;
CirclePoints(pDC, x, y, cenp, crColor);
while (y >= x)
{
if (d<0)
d += 2 * x + 3;
else {
d += 2 * (x - y) + 5;
y--;
}
x++;
CirclePoints(pDC, x, y, cenp, crColor);
}
}
void CMFCApplication3View::CirclePoints(CDC *pDC, int x, int y, CPoint cenp, COLORREF br)
{
pDC->SetPixel(x + cenp.x, y + cenp.y, br);
pDC->SetPixel(y + cenp.x, x + cenp.y, br);
pDC->SetPixel(y + cenp.x, -x + cenp.y, br);
pDC->SetPixel(x + cenp.x, -y + cenp.y, br);
pDC->SetPixel(-x + cenp.x, -y + cenp.y, br);
pDC->SetPixel(-y + cenp.x, -x + cenp.y, br);
pDC->SetPixel(-y + cenp.x, x + cenp.y, br);
pDC->SetPixel(-x + cenp.x, y + cenp.y, br);
}
void CMFCApplication3View::Onyuan()
{
// TODO: Add your command handler code here
m_yuan = 1;
}
void CMFCApplication3View::DrawCircle(CDC *pDC, CPoint cenp, CPoint ardp)
{
int ra, a, b;
a = (ardp.x - cenp.x)*(ardp.x - cenp.x);
b = (ardp.y - cenp.y)*(ardp.y - cenp.y);
ra = (int)(sqrt(a + b));
pDC->Ellipse(cenp.x-ra,cenp.y-ra,cenp.x+ra,cenp.y+ra);
MidpointCircle(pDC, ra, cenp, cl);
}
void CMFCApplication3View::OnColor()
{
// TODO: 在此添加命令处理程序代码
CColorDialog dlg;
dlg.DoModal();
cl = dlg.GetColor();
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询