weixin_42162172 2018-05-12 11:45 采纳率: 0%
浏览 742
已结题

编写的绘制曲线的程序怎么输出不了坐标和曲线?哪里出问题了?需要怎样改正?

// MyVC3View.cpp : implementation of the CMyVC3View class
//

#include "stdafx.h"
#include "MyVC3.h"

#include "MyVC3Doc.h"
#include "MyVC3View.h"
#include "math.h"
#ifdef DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE
_;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMyVC3View

IMPLEMENT_DYNCREATE(CMyVC3View, CView)

BEGIN_MESSAGE_MAP(CMyVC3View, CView)
//{{AFX_MSG_MAP(CMyVC3View)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyVC3View construction/destruction
const double PI=3.14159;
COLORREF colb;
double HI,poix[723],poiy[721];
int xm0,xz0;

CMyVC3View::CMyVC3View()
{
int i;
for(i=0;i<722;i++)
{
poix[i]=0;poiy[i]=0;
}
colb=RGB(220,220,220);HI=38;xm0=1;xz0=4;
// TODO: add construction code here

}

CMyVC3View::~CMyVC3View()
{
}

BOOL CMyVC3View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs

return CView::PreCreateWindow(cs);

}

/////////////////////////////////////////////////////////////////////////////
// CMyVC3View drawing

void CMyVC3View::OnDraw(CDC* pDC)
{
CRect rect;
CFont fnBig;
CFont*poldFont;
fnBig.CreatePointFont(int(HI*8.0),"Arial",pDC);
poldFont=pDC->SelectObject(&fnBig);
FillRect0(pDC,colb,(0,0),800,500);
GetClientRect(&rect);
pDC->SetMapMode(MM_LOMETRIC);
pDC->SetViewportOrg(int(rect.right/10),int(rect.bottom/2));
if(xm0==0){}
else{huatu0(pDC);}
pDC->SelectObject(poldFont);
CMyVC3Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CMyVC3View printing

BOOL CMyVC3View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}

void CMyVC3View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}

void CMyVC3View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CMyVC3View diagnostics

#ifdef _DEBUG
void CMyVC3View::AssertValid() const
{
CView::AssertValid();
}

void CMyVC3View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}

CMyVC3Doc* CMyVC3View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyVC3Doc)));
return (CMyVC3Doc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMyVC3View message handlers
void CMyVC3View::FillRect0(CDC*pDC,COLORREF col,CPoint point,int chd,int kd)
{
CBrush newBrush(col);
CBrush*poldBrush;
poldBrush=pDC->SelectObject(&newBrush);
pDC->FillRect(CRect(point.x,point.y,point.x+chd,point.y+kd),&newBrush);
pDC->SelectObject(poldBrush);
newBrush.DeleteObject();
}
void CMyVC3View::Line0(CDC*pDC,double x1,double y1,double x2,double y2,int siw,COLORREF col)
{
CPen siPen;
CPen*pOldPen;
siPen.CreatePen(PS_SOLID,siw,col);
pOldPen=pDC->SelectObject(&siPen);
pDC->MoveTo(int(HI*x1),int(HI*y1));
pDC->LineTo(int(HI*x2),int(HI*y2));
pDC->SelectObject(pOldPen);
siPen.DeleteObject();
}
void CMyVC3View::ASIN0()
{
float L,g,B,hg,R,hr,H,k;
int max,min,i;
printf("\nplease input L,g,B,hg,R,hr");
scanf("%f%f%f%f%f%f%",&L,&g,&B,&hg,&R,&hr);
for(i=min;i {
H=2*hg*(1+R*(1-hr/hg));
k=L*g*B/H;
poix[i]=i;
poiy[i]=asin(k/(poix[i]*poix[i]));
}
}
void CMyVC3View::quxian0(CDC*pDC)
{
int j,ds;
double x1,y1,dsy;
char buf[25];
CString sc;
pDC->SetBkColor(colb);
ds=0;x1=0;y1=0;
wsprintf(buf,"%d",ds);
pDC->TextOut(-40,-10,buf,strlen(buf));
Line0(pDC,-10,0,75,0,4,RGB(0,0,0));
pDC->TextOut(int(HI*72.5),-40,"X(km/h)");
for (j=0;j<24;j++)
{
x1+=3;ds+=15;
Line0(pDC,x1,0,x1,0.5,1,RGB(0,0,0));
wsprintf(buf,"%d",ds);
}

dsy=0;
Line0(pDC,0,-20,0,20,4,RGB(0,0,0));
pDC->TextOut(-60,int(HI*24),"Y");
for(j=0;j<5;j++)
{
    y1+=4;dsy+=1;
    Line0(pDC,0,y1,0.5,y1,1,RGB(0,0,0));
    sc.Format("%3,1f",dsy);
    pDC->TextOut(-70,int(HI*y1)+20,sc,strlen(sc));
}

}
void CMyVC3View::huatu0(CDC*pDC)
{
int max,min,i;
switch(xm0)
{
case 1:
ASIN0();
break;
}
for(i=min;i<max;i++)
{
Line0(pDC,poix[i]/5,poiy[i]/0.25,poix[i+1]/5,poiy[i+1]/0.25,xz0,RGB(255,0,0));
}
}

  • 写回答

2条回答 默认 最新

  • threenewbee 2018-05-12 11:55
    关注

    你的绘图代码都要放在OnDraw里,写在别的地方,只要窗体刷新,就会被擦除了。

    正告楼下抄袭本人回答的无耻之徒,本人坚持投诉到底,直到封号为止!

    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考