Win32 程序 转换为 MFC 程序

本文介绍了如何在已经创建的Win32控制台应用程序中后期添加MFC支持。通过在项目属性中设置使用MFC共享DLL,修改stdafx.h文件并包含必要的头文件,你的应用就能利用MFC类库了。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

If you have chosen Win32 console based application while using New Project Wizard, and later you realize you need to add MFC support, here is a trick.

Assuming you have Console based application created with MFC support (i.e., you have not chosen MFC support while using New Project Wizard).

In this Tip/Trick, I am not going into detailed steps of how to create a new project and all. I assume you know all these and face a real life problem of adding MFC support to existing applications.

Follow these simple steps and your application will have MFC support.
Here I am using project name as MyApp and IDE is Visual Studio 2008.


  1. Open your project.
  2. In Project Menus --> Select MyApp Properties(MyApp -> name of my project)
  3. In Configuration Properties -> General -> Use of MFC, select Use MFC in a Shared DLL option.
     
  4. Add the following line in your stdafx.h file.
    #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS      // some CString constructors will be explicit
    
    #ifndef VC_EXTRALEAN
    #define VC_EXTRALEAN            // Exclude rarely-used stuff from Windows headers
    #endif
    
    #include <afx.h>
    #include <afxwin.h>         // MFC core and standard components
    #include <afxext.h>         // MFC extensions
    #ifndef _AFX_NO_OLE_SUPPORT
    #include <afxdtctl.h>           // MFC support for Internet Explorer 4 Common Controls
    #endif
    #ifndef _AFX_NO_AFXCMN_SUPPORT
    #include <afxcmn.h>                     // MFC support for Windows Common Controls
    #endif // _AFX_NO_AFXCMN_SUPPORT
    
    #include <iostream>


Now your application has MFC support, now you can use any MFC Class, Function or Structure.

Happy programming!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值