在Win32中使用MFC库

来源:互联网 发布:西游记知乎 编辑:程序博客网 时间:2024/05/21 20:06

在SDK程序中使用MFC中的辅助类
由于MFC中的辅助类,如CFileDialog,CFileFind,CString等使用起来非常的方便
如果用API来完成相应的工作,则需要自己完成大量的重复工作,使用MFC的辅助类
可以节省大量的开发时间,具体方法如下:

1.加入相应的头文件
去掉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>

注意一定要在你用到mfc的地方之前加入这几行(可以仅加载cpp文件中),而且顺序最好不要改变,否则会有大量的错误提示。

2。 更改编译设置

在Project->Setting->General 中选UseMFC in a Shared DLL或者 Use MFC in static Library
在project->Setting->C/C++ ->Useruning-time library中由Single-Threaded改为相应的Multithreaded

简单配置----增加工程选项 USING MFC

3。初始化MFC(可选)

在exe程序的InitInstance中最开头,增加
afxCurrentInstanceHandle = hInstance;
AfxWinInit(::GetModuleHandle(NULL),NULL,::GetCommandLine(),0);

原文地址:http://blog.sina.com.cn/s/blog_6c8dc2110101fefv.html
0 0