计算机图形学实验,VC6.0的MFC

对酒当歌笑俗人 2018-03-23 09:41:30
各位大佬你们好。我是一名本科在读大学生。之前只学过一点基础的C++,没学过什么MFC之类的。可是计算机图形学这门课要求我们做实验··也只能硬着头皮做了。可是现在总有错误,错误代码如下:
c:\program files\microsoft visual studio\myprojects\test2\test2view.cpp(108) : error C2653: 'CTestView' : is not a class or namespace name
c:\program files\microsoft visual studio\myprojects\test2\test2view.cpp(112) : error C2660: 'GetClientRect' : function does not take 1 parameters
c:\program files\microsoft visual studio\myprojects\test2\test2view.cpp(113) : error C2065: 'p0' : undeclared identifier
c:\program files\microsoft visual studio\myprojects\test2\test2view.cpp(113) : error C2228: left of '.x' must have class/struct/union type
c:\program files\microsoft visual studio\myprojects\test2\test2view.cpp(114) : error C2228: left of '.y' must have class/struct/union type
c:\program files\microsoft visual studio\myprojects\test2\test2view.cpp(115) : error C2228: left of '.x' must have class/struct/union type
c:\program files\microsoft visual studio\myprojects\test2\test2view.cpp(115) : error C2228: left of '.x' must have class/struct/union type
c:\program files\microsoft visual studio\myprojects\test2\test2view.cpp(116) : error C2228: left of '.y' must have class/struct/union type
c:\program files\microsoft visual studio\myprojects\test2\test2view.cpp(116) : error C2228: left of '.y' must have class/struct/union type
c:\program files\microsoft visual studio\myprojects\test2\test2view.cpp(117) : error C2248: 'OnLButtonDown' : cannot access protected member declared in class 'CWnd'
c:\program files\microsoft visual studio\vc98\mfc\include\afxwin.h(2352) : see declaration of 'OnLButtonDown'
c:\program files\microsoft visual studio\myprojects\test2\test2view.cpp(117) : error C2352: 'CWnd::OnLButtonDown' : illegal call of non-static member function
c:\program files\microsoft visual studio\vc98\mfc\include\afxwin.h(2352) : see declaration of 'OnLButtonDown'
c:\program files\microsoft visual studio\myprojects\test2\test2view.cpp(120) : error C2653: 'CTestView' : is not a class or namespace name
c:\program files\microsoft visual studio\myprojects\test2\test2view.cpp(124) : error C2660: 'GetClientRect' : function does not take 1 parameters
c:\program files\microsoft visual studio\myprojects\test2\test2view.cpp(125) : error C2065: 'p1' : undeclared identifier
c:\program files\microsoft visual studio\myprojects\test2\test2view.cpp(125) : error C2228: left of '.x' must have class/struct/union type
: error C2228: left of '.y' must have class/struct/union type
: error C2660: 'GetDC' : function does not take 0 parameters
error C2228: left of '.x' must have class/struct/union type
: error C2228: left of '.x' must have class/struct/union type
error C2228: left of '.y' must have class/struct/union type
: error C2228: left of '.y' must have class/struct/union type
error C2228: left of '.x' must have class/struct/union type
error C2228: left of '.x' must have class/struct/union type
: error C2228: left of '.x' must have class/struct/union type
error C2228: left of '.x' must have class/struct/union type
: error C2228: left of '.y' must have class/struct/union type
error C2228: left of '.y' must have class/struct/union type
error C2228: left of '.y' must have class/struct/union type
error C2228: left of '.y' must have class/struct/union type
error C2065: 'MBCircle' : undeclared identifier
error C2660: 'ReleaseDC' : function does not take 1 parameters
error C2248: 'OnLButtonUp' : cannot access protected member declared in class 'CWnd'
see declaration of 'OnLButtonUp'
: error C2352: 'CWnd::OnLButtonUp' : illegal call of non-static member function
: see declaration of 'OnLButtonUp'
error C2653: 'CTestView' : is not a class or namespace name
error C2373: 'MBCircle' : redefinition; different type modifiers
error C2065: 'CirclePoint' : undeclared identifier
: error C2653: 'CTestView' : is not a class or namespace name
: error C2373: 'CirclePoint' : redefinition; different type modifiers
error C2228: left of '.x' must have class/struct/union type
error C2228: left of '.x' must have class/struct/union type
: error C2228: left of '.y' must have class/struct/union type
: error C2228: left of '.y' must have class/struct/union type
: error C2065: 'Round' : undeclared identifier


这是代码··我也不知道我贴的全不全··不全的话请大家留言我马上补充
// test2View.cpp : implementation of the CTest2View class
//

#include "stdafx.h"
#include "math.h"
#include "P2.h"
#include "test2.h"

#include "test2Doc.h"
#include "test2View.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTest2View

IMPLEMENT_DYNCREATE(CTest2View, CView)

BEGIN_MESSAGE_MAP(CTest2View, CView)
//{{AFX_MSG_MAP(CTest2View)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
//}}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()

/////////////////////////////////////////////////////////////////////////////
// CTest2View construction/destruction

CTest2View::CTest2View()
{
// TODO: add construction code here

}

CTest2View::~CTest2View()
{
}

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

return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CTest2View drawing

void CTest2View::OnDraw(CDC* pDC)
{
CTest2Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CTest2View printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CTest2View diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CTest2View message handlers

void CTestView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CRect rect;
GetClientRect(&rect);
p0.x=point.x;
p0.y=point.y;
p0.x=p0.x-rect.Width()/2; //设备坐标系向自定义坐标系系转换
p0.y=rect.Height()/2-p0.y;
CView::OnLButtonDown(nFlags, point);
}

void CTestView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CRect rect;
GetClientRect(&rect);
p1.x=point.x;
p1.y=point.y;
CDC *pDC=GetDC(); //定义设备上下文指针
pDC->SetMapMode(MM_ANISOTROPIC); //自定义坐标系
pDC->SetWindowExt(rect.Width(),rect.Height()); //设置窗口比例
pDC->SetViewportExt(rect.Width(),-rect.Height()); //设置视区比例,且x轴水平向右,y轴垂直向上
pDC->SetViewportOrg(rect.Width()/2,rect.Height()/2);//设置客户区中心为坐标系原点
rect.OffsetRect(-rect.Width()/2,-rect.Height()/2); //矩形与客户区重合
p1.x=p1.x-rect.Width()/2;
p1.y=rect.Height()/2-p1.y;
double r=sqrt((p1.x-p0.x)*(p1.x-p0.x)+(p1.y-p0.y)*(p1.y-p0.y))/2.0;//计算圆的半径
MBCircle(r,pDC);//调用圆中点Bresenham算法
ReleaseDC(pDC);
CView::OnLButtonUp(nFlags, point);
}

void CTestView::MBCircle(double R,CDC *pDC)//圆中点Bresenham算法
{
double x,y,d;
d=1.25-R;x=0;y=R;
for(x=0;x<=y;x++)
{
CirclePoint(x,y,pDC);//调用八分法画圆子函数
if (d<0)
d+=2*x+3;
else
{
d+=2*(x-y)+5;
y--;
}
}
}

void CTestView::CirclePoint(double x, double y,CDC *pDC)//八分法画圆子函数
{
CP2 pc=CP2((p0.x+p1.x)/2.0,(p0.y+p1.y)/2.0); //圆心坐标
COLORREF clr=RGB(0,0,255); //定义圆的边界颜色
pDC->SetPixelV(Round(x+pc.x),Round(y+pc.y),clr); //x,y
pDC->SetPixelV(Round(y+pc.x),Round(x+pc.y),clr); //y,x
pDC->SetPixelV(Round(y+pc.x),Round(-x+pc.y),clr); //y,-x
pDC->SetPixelV(Round(x+pc.x),Round(-y+pc.y),clr); //x,-y
pDC->SetPixelV(Round(-x+pc.x),Round(-y+pc.y),clr); //-x,-y
pDC->SetPixelV(Round(-y+pc.x),Round(-x+pc.y),clr); //-y,-x
pDC->SetPixelV(Round(-y+pc.x),Round(x+pc.y),clr); //-y,x
pDC->SetPixelV(Round(-x+pc.x),Round(y+pc.y),clr); //-x,y
//pDC->MoveTo(Round(p0.x),Round(p0.y));
//pDC->LineTo(Round(p1.x),Round(p1.y));
}
...全文
677 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
吴瀚 2018-03-30
  • 打赏
  • 举报
回复
错误代码写得挺清楚的啊,有重定义的 有未定义的 楼主耐心一点 一句句改
schlafenhamster 2018-03-24
  • 打赏
  • 举报
回复
void CTestView::OnLButtonDown(UINT nFlags, CPoint point) 改 void CTest2View::OnLButtonDown(UINT nFlags, CPoint point)
zgl7903 2018-03-24
  • 打赏
  • 举报
回复
P2.h 怎么写的? 是否类后 缺了 ; class cxxx {} ;

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧