C++ 如何在VS 2013上运行旧的mfc程序?

C++ 如何在VS 2013上运行旧的mfc程序?,c++,mfc,C++,Mfc,我想让这个程序在VS2013上运行。将以下内容放在下面是没有帮助的: #define _CRT_SECURE_NO_DEPRECATE #define _CRT_SECURE_NO_WARNINGS #define USE_STANDARD_FILE_FUNCTIONS 我仍然得到: 1>------ Build started: Project: test, Configuration: Debug Win32 ------ 1> Code3C.cpp 1>c:\prog

我想让这个程序在VS2013上运行。将以下内容放在下面是没有帮助的:

#define _CRT_SECURE_NO_DEPRECATE
#define _CRT_SECURE_NO_WARNINGS
#define USE_STANDARD_FILE_FUNCTIONS
我仍然得到:

1>------ Build started: Project: test, Configuration: Debug Win32 ------
1>  Code3C.cpp
1>c:\program files (x86)\microsoft visual studio 12.0\vc\atlmfc\include\afx.h(38): warning C4996:        'MBCS_Support_Deprecated_In_MFC': MBCS support in MFC is deprecated and may be removed in a future     version of MFC.

1>          c:\program files (x86)\microsoft visual studio 12.0\vc\atlmfc\include\afx.h(33) : see     declaration of 'MBCS_Support_Deprecated_In_MFC'
1>  _WIN32_WINNT not defined. Defaulting to _WIN32_WINNT_MAXVER (see WinSDKVer.h)
1>c:\users\revist\desktop\sallcode\sallcode\code3c\code3c.cpp(76): error C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>          c:\program files (x86)\microsoft visual studio 12.0\vc\include\stdio.h(211) : see declaration of 'fopen'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
该方案:

CCode3.h:

#include <afxwin.h>
#include <afxdlgs.h>    //dialog boxes
#include "resource.h"
#define n 10

class CCode3C : public CFrameWnd
{
private:
CPoint *pt;
public:
CCode3C();
CCode3C::~CCode3C();
afx_msg void OnFileOpen();
afx_msg void OnFileSave();
afx_msg void OnGenerate();
afx_msg void OnClear();
afx_msg void OnExit();
DECLARE_MESSAGE_MAP()
};

class CMyWinApp : public CWinApp
{
public:
virtual BOOL InitInstance();
};
#包括
#包含//对话框
#包括“resource.h”
#定义n10
CCode3C类:公共框架
{
私人:
CPoint*pt;
公众:
CCode3C();
CCode3C::~CCode3C();
afx_msg void OnFileOpen();
afx_msg void onflesave();
afx_msg void OnGenerate();
afx_msg void OnClear();
afx_msg void OnExit();
声明消息映射()
};
CMyWinApp类:公共CWinApp
{
公众:
虚拟BOOL InitInstance();
};
CCode3C.cpp

#include "Code3C.h"

CMyWinApp  MyApplication;

BOOL CMyWinApp::InitInstance()
{
CCode3C* pFrame = new CCode3C;
m_pMainWnd = pFrame;
pFrame->ShowWindow(SW_SHOW);
pFrame->UpdateWindow();
return TRUE;
}

BEGIN_MESSAGE_MAP(CCode3C,CFrameWnd)
ON_COMMAND(ID_FILEOPEN,OnFileOpen)
ON_COMMAND(ID_FILESAVE,OnFileSave)
ON_COMMAND(ID_GENERATE,OnGenerate)
ON_COMMAND(ID_CLEAR,OnClear)
ON_COMMAND(ID_EXIT,OnExit)
END_MESSAGE_MAP()

CCode3C::CCode3C()
{
Create(NULL, "Code3C: File menus",
    WS_OVERLAPPEDWINDOW,CRect(0,0,600,400),
    NULL,MAKEINTRESOURCE(IDR_MENU1));
pt=new CPoint [n+1];
}

CCode3C::~CCode3C()
{
delete pt;
}

void CCode3C::OnClear()
{
CClientDC dc(this);
CRect rc;
GetClientRect(&rc);
CBrush whiteBrush(RGB(255,255,255));
dc.FillRect(&rc,&whiteBrush);
for (int i=1;i<=n;i++)
    pt[i]=CPoint(0,0);
}

void CCode3C::OnGenerate()
{
CClientDC dc(this);
CString str;
time_t seed=time(NULL); 
srand((unsigned)seed);
OnClear();
dc.TextOut(50,50,"Generating Random Numbers");
for (int i=1;i<=n;i++)
{
    pt[i].x=100+rand()%400; pt[i].y=50+rand()%300;
    str.Format("%d   %d",pt[i].x,pt[i].y);
    dc.TextOut(50,80+20*i,str);
}
}

void CCode3C::OnFileOpen()
{
CClientDC dc(this);
CString str;
CRect rc;
FILE *ifp;
char strFilter[] = {"TXT Files (*.txt)|*.txt|All Files (*.*)|*.*||"};
CFileDialog FileDlg(TRUE,".txt",NULL,0,strFilter);
if (FileDlg.DoModal()==IDOK)
{
    str=FileDlg.GetFileName();
    ifp = fopen(str, "r");
    dc.TextOut(350,50,"File Opened: "+str);
    for (int i=1;i<=n;i++)
    {
        fscanf(ifp,"%d %d",&pt[i].x,&pt[i].y);
        rc=CRect(pt[i].x-30,pt[i].y-30,pt[i].x+30,pt[i].y+30);
        dc.Ellipse(rc);
        rc=CRect(pt[i].x-1,pt[i].y-1,pt[i].x+1,pt[i].y+1);
        dc.Rectangle(rc);
    }
    fclose(ifp);
}
}

void CCode3C::OnFileSave()
{
CClientDC dc(this);
CString str;
FILE *ofp;
char strFilter[] = {"TXT Files (*.txt)|*.txt|All Files (*.*)|*.*||"};
CFileDialog FileDlg(FALSE,".txt",NULL,0,strFilter);
if( FileDlg.DoModal()==IDOK)
{
    str=FileDlg.GetFileName();
    ofp=fopen(str,"w");
    dc.TextOut(50,20,"File Saved: "+str);
    str.Format("%d",n);
    dc.TextOut(50,50,"Contents: "+str+" randomly generated numbers");
    for (int i=1;i<=n;i++)
        fprintf(ofp,"%d  %d\n",pt[i].x,pt[i].y);
    fclose(ofp);
}
}

void CCode3C::OnExit()
{
CCode3C::OnExit();
}
#包括“Code3C.h”
CMyWinApp-MyApplication;
boolcmywinapp::InitInstance()
{
CCode3C*pFrame=新的CCode3C;
m_pMainWnd=pFrame;
pFrame->显示窗口(SW_显示);
pFrame->UpdateWindow();
返回TRUE;
}
开始消息映射(CCode3C、CFrameWnd)
ON_命令(ID_FILEOPEN,OnFileOpen)
ON_命令(ID_FILESAVE,OnFileSave)
ON_命令(ID_GENERATE,OnGenerate)
ON_命令(ID_清除,OnClear)
ON_命令(ID_EXIT,OnExit)
结束消息映射()
CCode3C::CCode3C()
{
创建(空,“代码3C:文件菜单”,
WS_重叠窗口,正确(0,0600400),
NULL,MAKEINTRESOURCE(IDR_MENU1));
pt=新的CPoint[n+1];
}
CCode3C::~CCode3C()
{
删除pt;
}
void CCode3C::OnClear()
{
CClientDC dc(本);
正确的rc;
GetClientRect&rc;
CBrush白刷(RGB(255255));
dc.FillRect(&rc,&whiteBrush);

对于(int i=1;i在当前的Visual Studio版本上运行旧的MBCS MFC代码确实是必要的。在这种情况下,在下载VS MBCS MFC加载项时应该可以解决您的问题。

这是一个笑话吗?您的意思是“将?准确地描述问题所在…哦,去掉那些X!
void CCode3C::OnExit(){CCode3C::OnExit();}
你是认真的吗?是的,我是认真的。此外,这段代码来自一本书,所以我更愿意说作者是认真的。如果你使用的是预编译的标题,你需要将这些定义放在
stdafx.h
的顶部,这是默认值。@FrédéricHamidi OP说“这段代码来自一本书”-还有。我也不敢相信。作者将其描述为“退出程序的正式方式”!!!不知怎么回事,我以前安装过这个软件包,但没有重新启动电脑。无论如何,谢谢。