读书人

一直未解答: 。为什么出现 :Cannot

发布时间: 2012-03-19 22:03:05 作者: rapoo

一直未解答:在线等 。为什么出现 :Cannot open include file: 'CDCDEMO.h'
代码:
#include <afxwin.h>
#include <afxext.h>
#define SeedRand() srand((UINT)::GetTickCount())
class CMyApp:public CWinApp
{public: virtual BOOL InitInstance();
};
class CMainWnd:public CFrameWnd
{protected:
int m_nCurScreen;
CPoint rec_E;
int R_rec;
int C_rec;
COLORREF GetRandomColor();
UINT MapRand(UINT nMax);
void Growing_Ellipse(CClientDC*pDC);
public:
CMainWnd();
afx_msg void OnTimer(UINT IDtimer);
DECLARE_MESSAGE_MAP();

};
#include "CDCDEMO.h "
BEGIN_MESSAGE_MAP(CMainWnd,CFrameWnd)
ON_WM_TIMER()
END_MESSAGE_MAP()
CMainWnd::CMainWnd()
{rec_E.x=320;
rec_E.y=240;
R_rec=30;
C_rec=10;
SeedRand();
}
COLORREF CMainWnd::GetRandomColor()
{return RGB(MapRand(255),MapRand(255),MapRand(255));}
UINT CMainWnd::MapRand(UINT nMax)
{int nRand=rand();
float fMap=(float)nMax/RAND_MAX;
float fRetVal=(float)nRand*fMap+0.5F;
return (UINT)fRetVal;}
void CMainWnd::OnTimer(UINT IDtimer)
{CClientDC dc(this);
Growing_Ellipse(&dc);
void CMainWnd::Growing_Ellipse(CClientDC*pDC)
{CBrush ColorBrush(GetRandomColor());
pDC-> SelectObject(&ColorBrush);
pDC-> Ellipse(rec_E.x-R_rec,rec_E.y-R_rec*480/640,rec_E.x+R_rec_E.y+R_rec*480/640);
R_rec=R_rec+C_rec;
if(rec_E.x-R_rec <=10&rec_E.x-R_rec> =300)C_rec=-C_rec;}
BOOL CMyApp::InitInstance()
{CMainWnd*pFrame=new CMainWnd;
pFrame-> Create(0, "Graphics Demo ",WS_POPUPWINDOW|WS_DLGFRAME,
CRect(0,0,640,480));
this-> m_pMainWnd=pFrame;
pFrame-> ShowWindow(m_nCmdShow);
pFrame-> UpdateWindow();
pFrame-> SetTimer(10,50,NULL);
return TRUE;
}
CMyApp MyApp;


请问高手怎样将上述代码建成工程,
说明,在我的电脑里没有CDCDEMO.h文件 ,
是不是要根据代码自己建?

还是该怎么弄,请高手解答,苦等。。。。

[解决办法]
得自己创建
[解决办法]
要自己创建,重搞个工程吧,这个代码不全你也用不了
[解决办法]
CDCDEMO.h
确定没的话,应该是要自己写的吧。
[解决办法]
先把这行去掉再编译一下试试
[解决办法]
#include "CDCDEMO.h "

你的CDCDEMO.h和你这个cpp文件是在同一目录吗?
确定名字没有拼写错误?

确定名字不是写成了:CDCDEMO.h.h? windows没有隐藏扩展名?


[解决办法]
这个属于vc,按照代码创建
[解决办法]
#include <afxwin.h>
#include <afxext.h>
#define SeedRand() srand((UINT)::GetTickCount())
class CMyApp:public CWinApp
{public: virtual BOOL InitInstance();
};
class CMainWnd:public CFrameWnd
{protected:
int m_nCurScreen;
CPoint rec_E;
int R_rec;
int C_rec;
COLORREF GetRandomColor();
UINT MapRand(UINT nMax);
void Growing_Ellipse(CClientDC*pDC);
public:
CMainWnd();
afx_msg void OnTimer(UINT IDtimer);
DECLARE_MESSAGE_MAP();

};

这段代码就是你的CDCDEMO.h代码,把它分离出来,在这个文件的同一目录下创建一个CDCDEMO.h的文件,然后把上面的内容拷贝进去就ok了。建议你先看看C++文件组织方面的东西。。。。


[解决办法]
hehe
照出抄的啊> ?
那书没说明白

#include <afxwin.h>
#include <afxext.h>
#define SeedRand() srand((UINT)::GetTickCount())
class CMyApp:public CWinApp
{public: virtual BOOL InitInstance();
};
class CMainWnd:public CFrameWnd
{protected:
int m_nCurScreen;
CPoint rec_E;
int R_rec;
int C_rec;
COLORREF GetRandomColor();
UINT MapRand(UINT nMax);
void Growing_Ellipse(CClientDC*pDC);
public:
CMainWnd();
afx_msg void OnTimer(UINT IDtimer);
DECLARE_MESSAGE_MAP();

};
保存为CDCDEMO.h


#include "CDCDEMO.h "
BEGIN_MESSAGE_MAP(CMainWnd,CFrameWnd)
ON_WM_TIMER()
END_MESSAGE_MAP()
CMainWnd::CMainWnd()
{rec_E.x=320;
rec_E.y=240;
R_rec=30;
C_rec=10;
SeedRand();
}
COLORREF CMainWnd::GetRandomColor()
{return RGB(MapRand(255),MapRand(255),MapRand(255));}
UINT CMainWnd::MapRand(UINT nMax)
{int nRand=rand();
float fMap=(float)nMax/RAND_MAX;
float fRetVal=(float)nRand*fMap+0.5F;
return (UINT)fRetVal;}
void CMainWnd::OnTimer(UINT IDtimer)
{CClientDC dc(this);
Growing_Ellipse(&dc);
void CMainWnd::Growing_Ellipse(CClientDC*pDC)
{CBrush ColorBrush(GetRandomColor());
pDC-> SelectObject(&ColorBrush);
pDC-> Ellipse(rec_E.x-R_rec,rec_E.y-R_rec*480/640,rec_E.x+R_rec_E.y+R_rec*480/640);
R_rec=R_rec+C_rec;
if(rec_E.x-R_rec <=10&rec_E.x-R_rec> =300)C_rec=-C_rec;}
BOOL CMyApp::InitInstance()
{CMainWnd*pFrame=new CMainWnd;
pFrame-> Create(0, "Graphics Demo ",WS_POPUPWINDOW|WS_DLGFRAME,
CRect(0,0,640,480));
this-> m_pMainWnd=pFrame;
pFrame-> ShowWindow(m_nCmdShow);
pFrame-> UpdateWindow();
pFrame-> SetTimer(10,50,NULL);
return TRUE;
}
CMyApp MyApp;

保存为CDCDEMO.cpp

读书人网 >C++

热点推荐