之前一直为windows编程烦恼,系统api堆砌一些功能比较复杂,但MFC封装了许多有用的功能,于是想了解一下如何在win32项目中使用mfc的一些类呢,于是在百度文库上找到了一篇文章,把它记录起来,以免遗忘:
原文网址:http://wenku.baidu.com/link?url=GZhvhRhESpMOk8wpjMQy0rtpKJc46QjoEHEABMfrqGcmy4wypBXDeP7lB7pQU2qTUJRZflUXBPxdtOr8FtQchs8Zt4CT7oauTHjMTDSJyjO
内容:
由于
MFC
中的辅助类,如
CFileDialog,CFileFind,CString
等使用起来非常的方便如果用
API
来完成相应
的工作,则需要自己完成大量的重复工作,使用
MFC
的辅助类可以节省大量的开发时间,具体方法如下
:
1.
加入相应的头文件
由于在
SDK
程序中一定要包含
windows.h
头文件,
所以
在使用
MFC
中的类时,
如加入
afx.h
一类的头文
件会有一个提示与
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_SUPPORT
注意一定要在所有的头文件之前加入这几行,而起顺序最好不要改
变,否则会有大量的错误提示。
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
。
\
由于MFC中的辅助类,如 CFileDialog,CFileFind,CString等使用起来非常的方便如果用API来完成相应的工作,则需要自己完成大量的重复工作,使用 MFC的辅助类可以节省大量的开发时间,具体方法如下:1.加入相应的头文件 由于在SDK程序中一定要包含windows.h头文件,所以 在使用MFC中的类时,如加入afx.h一类的头文件会有一个提示与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_SUPPORT
注意一定要在所有的头文件之前加入这几行,而起顺序最好不要改 变,否则会有大量的错误提示。
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。 \