因为MFC中的辅助类,如 CFileDialog,CFileFind,CString等使用起来很是的方便,若是用API来完成相应的工做,则须要本身完成大量的重复工做,使用 MFC的辅助类能够节省大量的开发时间,具体方法以下:windows
1.加入相应的头文件app
因为在SDK程序中必定要包含windows.h头文件,因此在使用MFC中的类的时候,如加入afx.h一类的头文件会有一个提示:spa
fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include <windows.h>component
与windows.h相冲突,解决的办法是,去掉windows.h。而后在全部的.h 文件前加入#include "stdafx.h"开发
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include <afxdisp.h> // MFC Automation classes
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORTit
注意必定要在全部的头文件以前加入这几行,而起顺序最好不要改 变,不然会有大量的错误提示。io
2.更改编译设置编译
在Project->Setting->General中选Use MFC in a Shared DLL或者Use MFC in static Library;并把project->Setting->C/C++ 中的Use runing-time library 由Single-Threaded改成相应的Multithreaded。class