求助,问题一堆,我用的vs2012
MFC.h:
// MFC.h : PROJECT_NAME 应用程序的主头文件
//
#pragma once
#define BOOL int
#define TRUE 1
#define FALSE 0
#include <iostream>
using namespace std;
class CObject
{
public:
CObject::CObject(){}
CObject::~CObject(){}
};
class CCmdTarget : public CObject
{
public:
CCmdTarget::CCmdTarget(){}
CCmdTarget::~CCmdTarget(){}
};
class CWinThread : public CCmdTarget
{
public:
CWinThread::CWinThread(){}
CWinThread::~CWinThread(){}
virtual BOOL InitInstance(){
cout << "CWinThread::InitInstance\n";
return TRUE;
}
virtual int Run(){
cout << "CWinThread::Run\n";
return 1;
}
};
class CWnd;
class CWinApp : public CWinThread
{
public:
CWinApp* m_pCurrentWinApp;
CWnd* m_pMainWnd;
public:
CWinApp::CWinApp() {m_pCurrentWinApp = this;}
CWinApp::~CWinApp() { }
virtual BOOL InitApplication(){
cout << "CWinApp::InitApplication\n";
return TRUE;
}
virtual BOOL InitInstance(){
cout << "CWinApp::InitInstance\n";
return TRUE;
}
virtual int Run(){
cout << "CWinApp::Run\n";
return CWinThread::Run();
}
};
class CDocument : public CCmdTarget
{
public:
CDocument::CDocument(){}
CDocument::~CDocument(){}
};
class CWnd : public CCmdTarget
{
public:
CWnd::CWnd(){}
CWnd::~CWnd(){}
virtual BOOL Create();
BOOL CreateEx();
virtual BOOL PreCreateWindow();
};
class CFrameWnd : public CWnd
{
public:
CFrameWnd::CFrameWnd(){}
CFrameWnd::~CFrameWnd(){}
BOOL Create();
virtual BOOL PreCreateWindow();
};
class CView : public CWnd
{
public:
CView::CView(){}
CView::~CView(){}
};
//global function
CWinApp* AfxGetApp();
MFC.cpp:
#include "MY.h"
#include "stdafx.h"
extern CMyWinApp theApp; //external global object
BOOL CWnd::Create()
{
cout << "CWnd::Create\n";
return TRUE;
}
BOOL CWnd::CreateEx()
{
cout << "CWnd::CreateEx\n";
PreCreateWindow();
return TRUE;
}
BOOL CWnd::PreCreateWindow()
{
cout << "CWnd::PreCreateWindow\n";
return TRUE;
}
BOOL CFrameWnd::Create()
{
cout << "CFrameWnd::Create\n";
CreateEx();
return TRUE;
}
BOOL CFrameWnd::PreCreateWindow()
{
cout << "CFrameWnd::PreCreateWindow\n";
return TRUE;
}
CWinApp* AfxGetApp()
{
return theApp.m_pCurrentWinApp;
}
MY.h:
#include <iostream>
#include "MFC.h"
class CMyWinApp : public CWinApp
{
public:
CMyWinApp::CMyWinApp(){}
CMyWinApp::~CMyWinApp(){}
virtual BOOL InitInstance();
};
class CMyFrameWnd : public CFrameWnd
{
public:
CMyFrameWnd();
~CMyFrameWnd(){}
};
MY.cpp:
#include "MY.h"
#include "stdafx.h"
extern CMyWinApp theApp; // global object
BOOL CMyWinApp::InitInstance()
{
cout << "CMyWinApp::InitInstance\n";
m_pMainWnd = new CMyFrameWnd;
return TRUE;
}
CMyFrameWnd::CMyFrameWnd()
{
cout << "CMyFrameWnd::CMyFrameWnd\n";
Create();
}
//-----------------------------------
//main
//-----------------------------------
void main()
{
CWinApp* pApp = AfxGetApp();
pApp->InitApplication();
pApp->InitInstance();
pApp->Run();
}
下面是报错的内容:
1>------ 已启动生成: 项目: MFC, 配置: Debug Win32 ------
1> MY.cpp
1>c:\users\dl049\documents\visual studio 2012\projects\mfc\mfc\my.cpp(1): warning C4627: “#include "MY.h"”: 在查找预编译头使用时跳过
1> 将指令添加到“stdafx.h”或重新生成预编译头
1>c:\users\dl049\documents\visual studio 2012\projects\mfc\mfc\my.cpp(4): error C2146: 语法错误: 缺少“;”(在标识符“theApp”的前面)
1>c:\users\dl049\documents\visual studio 2012\projects\mfc\mfc\my.cpp(4): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>c:\users\dl049\documents\visual studio 2012\projects\mfc\mfc\my.cpp(6): error C2825: 'CMyWinApp': 当后面跟“::”时必须为类或命名空间
1>c:\users\dl049\documents\visual studio 2012\projects\mfc\mfc\my.cpp(6): error C2039: “InitInstance”: 不是“`global namespace'”的成员
1>c:\users\dl049\documents\visual studio 2012\projects\mfc\mfc\my.cpp(6): error C2146: 语法错误: 缺少“;”(在标识符“InitInstance”的前面)
1>c:\users\dl049\documents\visual studio 2012\projects\mfc\mfc\my.cpp(7): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>c:\users\dl049\documents\visual studio 2012\projects\mfc\mfc\my.cpp(8): error C2065: “cout”: 未声明的标识符
1>c:\users\dl049\documents\visual studio 2012\projects\mfc\mfc\my.cpp(9): error C2065: “m_pMainWnd”: 未声明的标识符
1>c:\users\dl049\documents\visual studio 2012\projects\mfc\mfc\my.cpp(9): error C2061: 语法错误: 标识符“CMyFrameWnd”
1>c:\users\dl049\documents\visual studio 2012\projects\mfc\mfc\my.cpp(13): error C2653: “CMyFrameWnd”: 不是类或命名空间名称
1>c:\users\dl049\documents\visual studio 2012\projects\mfc\mfc\my.cpp(14): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>c:\users\dl049\documents\visual studio 2012\projects\mfc\mfc\my.cpp(15): error C2065: “cout”: 未声明的标识符
1>c:\users\dl049\documents\visual studio 2012\projects\mfc\mfc\my.cpp(16): error C3861: “Create”: 找不到标识符
1>c:\users\dl049\documents\visual studio 2012\projects\mfc\mfc\my.cpp(17): warning C4508: “CMyFrameWnd”: 函数应返回一个值;假定“void”返回类型
1> MFC.cpp
1>c:\users\dl049\documents\visual studio 2012\projects\mfc\mfc\mfc.cpp(1): warning C4627: “#include "MY.h"”: 在查找预编译头使用时跳过
1> 将指令添加到“stdafx.h”或重新生成预编译头
1>c:\users\dl049\documents\visual studio 2012\projects\mfc\mfc\mfc.cpp(4): error C2146: 语法错误: 缺少“;”(在标识符“theApp”的前面)
1>c:\users\dl049\documents\visual studio 2012\projects\mfc\mfc\mfc.cpp(4): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>c:\users\dl049\documents\visual studio 2012\projects\mfc\mfc\mfc.cpp(7): error C2511: “BOOL CWnd::Create(void)”:“CWnd”中没有找到重载的成员函数
1> c:\program files\microsoft visual studio 11.0\vc\atlmfc\include\afxwin.h(2273) : 参见“CWnd”的声明
1>c:\users\dl049\documents\visual studio 2012\projects\mfc\mfc\mfc.cpp(13): error C2511: “BOOL CWnd::CreateEx(void)”:“CWnd”中没有找到重载的成员函数
1> c:\program files\microsoft visual studio 11.0\vc\atlmfc\include\afxwin.h(2273) : 参见“CWnd”的声明
1>c:\users\dl049\documents\visual studio 2012\projects\mfc\mfc\mfc.cpp(20): error C2511: “BOOL CWnd::PreCreateWindow(void)”:“CWnd”中没有找到重载的成员函数
1> c:\program files\microsoft visual studio 11.0\vc\atlmfc\include\afxwin.h(2273) : 参见“CWnd”的声明
1>c:\users\dl049\documents\visual studio 2012\projects\mfc\mfc\mfc.cpp(26): error C2511: “BOOL CFrameWnd::Create(void)”:“CFrameWnd”中没有找到重载的成员函数
1> c:\program files\microsoft visual studio 11.0\vc\atlmfc\include\afxwin.h(4196) : 参见“CFrameWnd”的声明
1>c:\users\dl049\documents\visual studio 2012\projects\mfc\mfc\mfc.cpp(33): error C2511: “BOOL CFrameWnd::PreCreateWindow(void)”:“CFrameWnd”中没有找到重载的成员函数
1> c:\program files\microsoft visual studio 11.0\vc\atlmfc\include\afxwin.h(4196) : 参见“CFrameWnd”的声明
1>c:\users\dl049\documents\visual studio 2012\projects\mfc\mfc\mfc.cpp(40): error C2373: “AfxGetApp”: 重定义;不同的类型修饰符
1> c:\program files\microsoft visual studio 11.0\vc\atlmfc\include\afxwin.h(5094) : 参见“AfxGetApp”的声明
1>c:\users\dl049\documents\visual studio 2012\projects\mfc\mfc\mfc.cpp(41): error C2228: “.m_pCurrentWinApp”的左边必须有类/结构/联合
1> 类型是“int”
1> 正在生成代码...
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========