因爲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