如何在VS 2013上运行旧的mfc程序
How to run old mfc program on VS 2013?
我想让这个程序在VS 2013上运行。放置以下内容无济于事:
#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.0vcatlmfcincludeafx.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.0vcatlmfcincludeafx.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:usersrevistdesktopsallcodesallcodecode3ccode3c.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.0vcincludestdio.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();
};
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 %dn",pt[i].x,pt[i].y);
fclose(ofp);
}
}
void CCode3C::OnExit()
{
CCode3C::OnExit();
}
请记住,我是编程新手(大约 4 周前开始(,因此请回答以下问题之一:是的,我是认真的。
有时确实需要在当前的Visual Studio版本上运行旧的MBCS MFC代码。在这种情况下,在 http://msdn.microsoft.com/en-us/library/dn251007.aspx 下载 VS MBCS MFC 加载项应该可以解决您的问题。
相关文章:
- 在 1 个服务器 n 客户端套接字 C++ MFC 应用程序中更新数据的客户端
- 如何在 MFC 应用程序中启动 ZeroMQ 线程?
- 视窗 10 :笔(手写笔)在 MFC 应用程序上不起作用
- 从 MFC C++ 6.0 应用程序迁移到 VS 2005
- C++ - 从 MFC 应用程序启动记事本,并将其默认标题从 "Untitled - Notepad" 更改为其他内容
- 如何创建一个可以在GUI对话模式下或通过命令行启动的C MFC程序
- 发送和将消息从一个类发送到另一堂课的问题.MFC程序
- DLL中的CImage析构函数会阻塞整个MFC程序
- 字体在Windows 8上变小 - 在C++/MFC程序中.如何避免这种情况
- MyTest1.exe 在 C++ / MFC 程序中触发了删除命令的断点
- MFC 程序崩溃时调整窗口大小并出现错误"A required resource was not found."
- OnPaint() 和 MouseMove 事件同时在 MFC C++程序中
- 如何在VS 2013上运行旧的mfc程序
- 检测控制台mfc程序中的转义键
- 从MFC程序卸载dll文件
- 在MFC程序中创建挂钩窗口
- 如何从c++ /MFC程序中获得控制台窗口
- 用vs2012在windows xp上编译MFC程序
- 在Linux上运行MFC程序
- MFC 程序挂起:在 Vista 上更新KB3059317后损坏的 Comctl32.dll