下面是书上的原代码:首先头文件:
#if !defined(_GRAPHTRANSF_H__)
#define _GRAPHTRANSF_H__#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000#include "GraphTest.h"
#include <afxtempl.h>class CGraphTransf:public CGraphTest
{
struct C2DPoint
{
int x,y,h;
C2DPoint(void)
{
x=0;
y=0;
h=1;
} C2DPoint(int xx,int yy,int hh)
{
x=xx;
y=yy;
h=hh;
}
}; typedef CArray<C2DPoint,C2DPoint>C2DPointArray;
C2DPointArray m_ptArray;
double m_fScale; public:
CGraphTransf(CWnd*pWnd);
virtual~CGraphTransf(); virtual void Display(BOOL bAnimateGO=FALSE); virtual void SetOption(void);
private:
void EndScanle(void);
void Show (void);};
#endif 然后:
#include "stdafx.h"
#include "GraphBook.h"
#include "GraphTransf.h"#ifdef _DEBUG#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#define new DEBUG_NEW
#endifCGraphTransf::CGraphTransf(CWnd*pWnd):CGraphTest(pWnd)
{
}
CGraphTransf::~CGraphTransf
{
}void CGraphTransf::Display(BOOL/*bAnimateGO*/)
{
m_canvas.SetWCSOriginType(WINDOW_CENTER);
m_canvas.SetCoordinatesType(COORDINATES_NORMAL,TRUE,FALSE);
m_canvas.StartShowOrAnimate();
m_canvas.SetLinePara(2,PS_SOLID,RGB(255,0,0));
show();
EndScanle();
m_canvas.SetLinePara(2,PS_SOLID,RGB(0,255,0))
show();
m_canvas.EndShowOrAnimate();
} void CGraphTransf::SetOption(void)
{
m_fScale=1.8;
m_ptArray.Add(C2DPoint(0,0,1));
m_ptArray.Add(C2DPoint(100,80,1));
m_ptArray.Add(C2DPoint(120,60,1));
m_ptArray.Add(C2DPoint(30,-40,1));
}void CGraphTransf::EndScanle(void)
{
float Matix[3][3]={{1,0,0},{0,1,0},{0,0,1}};
Matix[0][0]=Matix[1][1]=m_fScale;
int oldx,oldy,oldh;
int nSize=m_ptArray.GetSize();
for(int i=0;i<nSize;i++)
{
C2DPoint& pt=m_ptArray[i];
oldx=pt.x;
oldy=pt.y;
oldh=pt.h;
pt.x=int(oldx * Matrix[0][0]+oldy * Matrix[1][0]+oldh * Matrix[2][0]+0.5);
pt.y=int(oldx * Matrix[0][1]+oldy * Matrix[1][1]+oldh * Matrix[2][1]+0.5);
pt.h=int(oldx * Matrix[0][2]+oldy * Matrix[1][2]+oldh * Matrix[2][2]+0.5);
}
}
void CGraphTransf::Show(void)
{
int nSize=m_ptArray.GetSize(); for(int i=0;i<nSize-1;i++)
{
C2DPoint& pt1=m_ptArry[i];
C2DPoint& pt2=m_ptArry[i+1];
m_canvas.Line(pt1.x,pt1.y,pt2.x,pt2.y);
} if(nSize>2)
{
C2DPoint& pt1=m_ptArry[0];
C2DPoint& pt2=m_ptArry[nSize-1];
m_canvas.Line(pt1.x,pt1.y,pt2.x,pt2.y);
}
}我又新建了个名字是GraphBook的单文档工程,把上面两个程序 添加进去,结果运行时,说找不到"GrapBook"这个头文件。请问书上的这个 图形转换的源代码怎么用啊?
请高手百忙中指点一二,小弟不胜感激!
#if !defined(_GRAPHTRANSF_H__)
#define _GRAPHTRANSF_H__#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000#include "GraphTest.h"
#include <afxtempl.h>class CGraphTransf:public CGraphTest
{
struct C2DPoint
{
int x,y,h;
C2DPoint(void)
{
x=0;
y=0;
h=1;
} C2DPoint(int xx,int yy,int hh)
{
x=xx;
y=yy;
h=hh;
}
}; typedef CArray<C2DPoint,C2DPoint>C2DPointArray;
C2DPointArray m_ptArray;
double m_fScale; public:
CGraphTransf(CWnd*pWnd);
virtual~CGraphTransf(); virtual void Display(BOOL bAnimateGO=FALSE); virtual void SetOption(void);
private:
void EndScanle(void);
void Show (void);};
#endif 然后:
#include "stdafx.h"
#include "GraphBook.h"
#include "GraphTransf.h"#ifdef _DEBUG#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#define new DEBUG_NEW
#endifCGraphTransf::CGraphTransf(CWnd*pWnd):CGraphTest(pWnd)
{
}
CGraphTransf::~CGraphTransf
{
}void CGraphTransf::Display(BOOL/*bAnimateGO*/)
{
m_canvas.SetWCSOriginType(WINDOW_CENTER);
m_canvas.SetCoordinatesType(COORDINATES_NORMAL,TRUE,FALSE);
m_canvas.StartShowOrAnimate();
m_canvas.SetLinePara(2,PS_SOLID,RGB(255,0,0));
show();
EndScanle();
m_canvas.SetLinePara(2,PS_SOLID,RGB(0,255,0))
show();
m_canvas.EndShowOrAnimate();
} void CGraphTransf::SetOption(void)
{
m_fScale=1.8;
m_ptArray.Add(C2DPoint(0,0,1));
m_ptArray.Add(C2DPoint(100,80,1));
m_ptArray.Add(C2DPoint(120,60,1));
m_ptArray.Add(C2DPoint(30,-40,1));
}void CGraphTransf::EndScanle(void)
{
float Matix[3][3]={{1,0,0},{0,1,0},{0,0,1}};
Matix[0][0]=Matix[1][1]=m_fScale;
int oldx,oldy,oldh;
int nSize=m_ptArray.GetSize();
for(int i=0;i<nSize;i++)
{
C2DPoint& pt=m_ptArray[i];
oldx=pt.x;
oldy=pt.y;
oldh=pt.h;
pt.x=int(oldx * Matrix[0][0]+oldy * Matrix[1][0]+oldh * Matrix[2][0]+0.5);
pt.y=int(oldx * Matrix[0][1]+oldy * Matrix[1][1]+oldh * Matrix[2][1]+0.5);
pt.h=int(oldx * Matrix[0][2]+oldy * Matrix[1][2]+oldh * Matrix[2][2]+0.5);
}
}
void CGraphTransf::Show(void)
{
int nSize=m_ptArray.GetSize(); for(int i=0;i<nSize-1;i++)
{
C2DPoint& pt1=m_ptArry[i];
C2DPoint& pt2=m_ptArry[i+1];
m_canvas.Line(pt1.x,pt1.y,pt2.x,pt2.y);
} if(nSize>2)
{
C2DPoint& pt1=m_ptArry[0];
C2DPoint& pt2=m_ptArry[nSize-1];
m_canvas.Line(pt1.x,pt1.y,pt2.x,pt2.y);
}
}我又新建了个名字是GraphBook的单文档工程,把上面两个程序 添加进去,结果运行时,说找不到"GrapBook"这个头文件。请问书上的这个 图形转换的源代码怎么用啊?
请高手百忙中指点一二,小弟不胜感激!
解决方案 »
- 转领域郁闷啊
- **********在新公司上班不到2个月,头说我不合适,把我辞了,特生气,走之前我把主板上CPU附近的一个大电容给拔下来了,大家说不会出事吧
- 请教大虾,关于FindWindowEx 的用法
- 有无XSL、DOM使用的帮助下载
- 怎样制作一个(含32x32的大图标和16X16小图标)图标资源
- 用PacketRecievePacket时总得不到包,怎么回事?
- 立即给分哦!!!窗口为什么只是闪一下后消失了?
- 我有一个文本文件,每行只一个字符和它对应的内码。请问:怎么样把它导入到Access表中去?
- COM高手请进!!!CoCreateInstance用在多线成中为什么会失败?
- 如何使用mfc 编程将jpg,bmp等图片转换成PDF
- vc 如何动态的创建一个全局队列
- 现在学MFC还行么
自己顶一下!