From:http://jxcn.bokee.com/viewdiary.14529444.html
能用, #include <afx.h>
在SDK程序中使用MFC中的輔助類(lèi)
由于MFC中的輔助類(lèi),如CFileDialog,CFileFind,CString等使用起來(lái)非常的方便
如果用API來(lái)完成相應(yīng)的工作,則需要自己完成大量的重復(fù)工作,使用MFC的輔助類(lèi)
可以節(jié)省大量的開(kāi)發(fā)時(shí)間,具體方法如下:
1.加入相應(yīng)的頭文件
由于在SDK程序中一定要包含windows.h頭文件,所以在使用MFC中的類(lèi)時(shí),
如加入afx.h一類(lèi)的頭文件會(huì)有一個(gè)提示與windows.h相沖突,解決的辦法是,
去掉windows.h,然后在所有的.h文件前加入
#include "stdafx.h"
#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
#include <afxcmn.h>
注意一定要在所有的頭文件之前加入這幾行,而且順序最好不要改變,否則會(huì)有大量的錯(cuò)誤提示
2。 更改編譯設(shè)置
在Project->Setting->General 中選Use MFC in a Shared DLL或者 Use MFC in static Library
并把project->Setting->C/C++ 中的Use runing-time library 由Single-Threaded改為相應(yīng)的
Multithreaded
簡(jiǎn)單配置----增加工程選項(xiàng) USING MFC