void CTestView::OnDraw(CDC* pDC){
CTestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CPen aPen;
if(!aPen.CreatePen(PS_SOLID,m_Pen,m_Color))
{
AfxMessageBox(_T("Pen creation failed drawing a Coordinate"),MB_OK);
AfxAbort();
}
else
{
CPen* pOldPen = pDC->SelectObject(&aPen); //Select the pen
// 绘制坐标轴
pDC->MoveTo(m_EnclosingRect.left,m_EnclosingRect.top);
// 垂直轴
pDC->LineTo(m_EnclosingRect.left,m_EnclosingRect.bottom);
// 水平轴
pDC->LineTo(m_EnclosingRect.right,m_EnclosingRect.bottom);
pDC->SelectObject(pOldPen); //Restore the old pen
}
CFont myFont;
CFont* pOldFont;
myFont.CreateFont( -14 , 0, 0 , 0 , FW_THIN , false , false , false , DEFAULT_CHARSET ,
OUT_DEFAULT_PRECIS , CLIP_DEFAULT_PRECIS , DEFAULT_QUALITY , VARIABLE_PITCH , _TEXT( "Times New Roman" ) ) ;
pOldFont=pDC->SelectObject(&myFont);
CPen aPen2;
if(!aPen2.CreatePen(PS_SOLID,1,RGB(0,0,0)))
{
//Pen create failed
AfxMessageBox("画笔创建失败!请重试!");
}
else
{
CPen* pOldPen2 = pDC->SelectObject(&aPen2);
int xStart=static_cast<int>(x_start);
int xEnd=static_cast<int>(x_end);
int StepX=static_cast<int>(x_interM/5);
for(int i=xStart;i<=xEnd;i++)
{ if((i%(int)x_interM)==0 && i!=xStart)
{
int x=static_cast<int>((m_EnclosingRect.right-10-m_EnclosingRect.left)*(i-xStart)*1.0/(xEnd-xStart));
pDC->MoveTo(x+60,m_EnclosingRect.bottom);
pDC->LineTo(x+60,m_EnclosingRect.bottom+6);
CString numberX;
pDC->TextOut(x+60-numberX.GetLength()*3,m_EnclosingRect.bottom+12,numberX);
}
if ((i%(int)x_interM)!=0 && i!=xStart && (i%(int)StepX)==0)//画细刻度
{
int x=static_cast<int>((m_EnclosingRect.right-10-m_EnclosingRect.left)*(i-xStart)*1.0/(xEnd-xStart));
pDC->MoveTo(x+60,m_EnclosingRect.bottom);
pDC->LineTo(x+60,m_EnclosingRect.bottom+3);
}
}
int yStart=static_cast<int>(y_start);
int yEnd=static_cast<int>(y_end);
int StepY=static_cast<int>(y_interM/5);
for(int j=yStart;j<=yEnd;j++)
{
if((j%(int)y_interM)==0 && j!=yStart)//画Y轴大刻度
{
int y=static_cast<int>(((m_EnclosingRect.bottom-10-m_EnclosingRect.top)*(yEnd-j)*1.0/(yEnd-yStart)));
pDC->MoveTo(m_EnclosingRect.left,(y+30+10));
pDC->LineTo(m_EnclosingRect.left-7,(y+30+10));
}
if((j%(int)y_interM)!=0 && j!=yStart && j%StepY==0)//画Y轴细刻度
{
int y=static_cast<int>(((m_EnclosingRect.bottom-10-m_EnclosingRect.top)*(yEnd-j)*1.0/(yEnd-yStart)));
pDC->MoveTo(m_EnclosingRect.left,(y+30+10));
pDC->LineTo(m_EnclosingRect.left-4,(y+30+10));
}
}
} double x_1rand,y_1rand,x_2rand,y_2rand;
for( double i=x_start;i<x_end;i++)
for( double j=y_start;j<y_end;j++)
{
x_1rand=x_start+rand()/(double)(RAND_MAX/x_end);
y_1rand=y_start+rand()/(double)(RAND_MAX/y_end);
x_2rand=x_start+rand()/(double)(RAND_MAX/x_end);
y_2rand=y_start+rand()/(double)(RAND_MAX/y_end);
}
pDC->MoveTo(x_1rand,y_1rand);
pDC->LineTo(x_2rand,y_2rand);
CTestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CPen aPen;
if(!aPen.CreatePen(PS_SOLID,m_Pen,m_Color))
{
AfxMessageBox(_T("Pen creation failed drawing a Coordinate"),MB_OK);
AfxAbort();
}
else
{
CPen* pOldPen = pDC->SelectObject(&aPen); //Select the pen
// 绘制坐标轴
pDC->MoveTo(m_EnclosingRect.left,m_EnclosingRect.top);
// 垂直轴
pDC->LineTo(m_EnclosingRect.left,m_EnclosingRect.bottom);
// 水平轴
pDC->LineTo(m_EnclosingRect.right,m_EnclosingRect.bottom);
pDC->SelectObject(pOldPen); //Restore the old pen
}
CFont myFont;
CFont* pOldFont;
myFont.CreateFont( -14 , 0, 0 , 0 , FW_THIN , false , false , false , DEFAULT_CHARSET ,
OUT_DEFAULT_PRECIS , CLIP_DEFAULT_PRECIS , DEFAULT_QUALITY , VARIABLE_PITCH , _TEXT( "Times New Roman" ) ) ;
pOldFont=pDC->SelectObject(&myFont);
CPen aPen2;
if(!aPen2.CreatePen(PS_SOLID,1,RGB(0,0,0)))
{
//Pen create failed
AfxMessageBox("画笔创建失败!请重试!");
}
else
{
CPen* pOldPen2 = pDC->SelectObject(&aPen2);
int xStart=static_cast<int>(x_start);
int xEnd=static_cast<int>(x_end);
int StepX=static_cast<int>(x_interM/5);
for(int i=xStart;i<=xEnd;i++)
{ if((i%(int)x_interM)==0 && i!=xStart)
{
int x=static_cast<int>((m_EnclosingRect.right-10-m_EnclosingRect.left)*(i-xStart)*1.0/(xEnd-xStart));
pDC->MoveTo(x+60,m_EnclosingRect.bottom);
pDC->LineTo(x+60,m_EnclosingRect.bottom+6);
CString numberX;
pDC->TextOut(x+60-numberX.GetLength()*3,m_EnclosingRect.bottom+12,numberX);
}
if ((i%(int)x_interM)!=0 && i!=xStart && (i%(int)StepX)==0)//画细刻度
{
int x=static_cast<int>((m_EnclosingRect.right-10-m_EnclosingRect.left)*(i-xStart)*1.0/(xEnd-xStart));
pDC->MoveTo(x+60,m_EnclosingRect.bottom);
pDC->LineTo(x+60,m_EnclosingRect.bottom+3);
}
}
int yStart=static_cast<int>(y_start);
int yEnd=static_cast<int>(y_end);
int StepY=static_cast<int>(y_interM/5);
for(int j=yStart;j<=yEnd;j++)
{
if((j%(int)y_interM)==0 && j!=yStart)//画Y轴大刻度
{
int y=static_cast<int>(((m_EnclosingRect.bottom-10-m_EnclosingRect.top)*(yEnd-j)*1.0/(yEnd-yStart)));
pDC->MoveTo(m_EnclosingRect.left,(y+30+10));
pDC->LineTo(m_EnclosingRect.left-7,(y+30+10));
}
if((j%(int)y_interM)!=0 && j!=yStart && j%StepY==0)//画Y轴细刻度
{
int y=static_cast<int>(((m_EnclosingRect.bottom-10-m_EnclosingRect.top)*(yEnd-j)*1.0/(yEnd-yStart)));
pDC->MoveTo(m_EnclosingRect.left,(y+30+10));
pDC->LineTo(m_EnclosingRect.left-4,(y+30+10));
}
}
} double x_1rand,y_1rand,x_2rand,y_2rand;
for( double i=x_start;i<x_end;i++)
for( double j=y_start;j<y_end;j++)
{
x_1rand=x_start+rand()/(double)(RAND_MAX/x_end);
y_1rand=y_start+rand()/(double)(RAND_MAX/y_end);
x_2rand=x_start+rand()/(double)(RAND_MAX/x_end);
y_2rand=y_start+rand()/(double)(RAND_MAX/y_end);
}
pDC->MoveTo(x_1rand,y_1rand);
pDC->LineTo(x_2rand,y_2rand);
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货