求助,问题一堆,我用的vs2012

cang1994cang 2016-06-27 04:28:38
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 个 ==========
...全文
183 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
牧童吃五谷 2016-06-29
  • 打赏
  • 举报
回复
Hi,又是害人的书本。 建议不看书本,然后采用建立项目向导自己建立一个简单对话框项目试试。
赵4老师 2016-06-29
  • 打赏
  • 举报
回复
偶遇到类似问题都是用 “每次用/*...*/注释掉不同部分再重新编译,直到定位到具体语法出错的位置。” 的方法解决的。
cang1994cang 2016-06-29
  • 打赏
  • 举报
回复
不行,还是解决不了
lx624909677 2016-06-28
  • 打赏
  • 举报
回复
语法错误: 缺少“;”(在标识符“theApp”的前面) 这个错误就是说,theApp变量对应类,编译器找不到他的声明的地方,比如A theApp,编译器不认识A这个类型时就会报这个错
cang1994cang 2016-06-28
  • 打赏
  • 举报
回复
引用 2 楼 zgl7903 的回复:
.cpp 最先加上 #include "stdafx.h"
我加了啊,仔细看看程序,有这句话啊,两个.cpp都有
zgl7903 2016-06-27
  • 打赏
  • 举报
回复
.cpp 最先加上 #include "stdafx.h"
cang1994cang 2016-06-27
  • 打赏
  • 举报
回复
程序基本是按照侯捷的《深入浅出MFC》打的,知道版本不对,也针对的改了一点东西,但是改不下去了,我还在学习中..

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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