如何将win32程序转成支持MFC的程序呢?
比如用vc6新建一个win32,"hello word" 后,然后修改某个地方,使的这个项目能够直接支持MFC,使用时就和新建一个MFC的应用程序的使用一样。可不可以呢?

解决方案 »

  1.   

    Project/Settings/General/Microsoft Foundation Classes
      

  2.   

    别忘了左上方的“Setting For”下拉框选择“All Configurations”。
      

  3.   

    不行呀,直接定义一个CString都过不去
      

  4.   

    直接去包含windows.h就可以了
    包含的头文件不就都可以用了啊,有什么支持不支持的。
      

  5.   

    不对呀,我包含了几个头文件后,可以添加类了
    编译也可以通过,但一运行就出错了,不知为什么?比如我新建一个dialog,定为Cdlg,但在主程序里一domodal()就出错了,为何?
      

  6.   

    #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
      

  7.   

    是啊,我加了这些了,编译也过了,
    如下:LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    int wmId, wmEvent;
    PAINTSTRUCT ps;
    HDC hdc;
    TCHAR szHello[MAX_LOADSTRING];
    LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING); switch (message) 
    {
    case WM_COMMAND:
    wmId    = LOWORD(wParam); 
    wmEvent = HIWORD(wParam); 
    // Parse the menu selections:
    case WM_PAINT:
    hdc = BeginPaint(hWnd, &ps);
    // TODO: Add any drawing code here...
    RECT rt;
    GetClientRect(hWnd, &rt);
    DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
    EndPaint(hWnd, &ps);
    break;
    case WM_CREATE:
    {
    Cdia   asd;
    asd.DoModal();
    }
                 break;
    case WM_DESTROY:
    PostQuitMessage(0);
    break;
    default:
    return DefWindowProc(hWnd, message, wParam, lParam);
       }
       return 0;
    }主要是case wm_create 里,我加了一个cdia的类,在这里执行了一下,结果报错,为什么?
      

  8.   

    上面的win32程序是我用vc的向导,win32 app, hello world.然后在里面做修改,让他支持MFC。
      

  9.   

    伙计,这样问问题,有你的时间哈!
    “主要是case wm_create 里,我加了一个cdia的类,在这里执行了一下,结果报错,为什么?

    报什么错要所有的人去猜测是不是?@!@
      

  10.   

    debug assertion failde!program :E:\vc++\win32test\debug\win32test.exe
    file:afxwin1.inl
    line:22for information on how you program can cause an assertion
    failure ,see the viasual c++ documentation on asserts.(press retry to debug the applition)    终止     重试     忽略就这些!
      

  11.   

    一点重试就说:
    应用程序发生异常 unknow software exception(0x80000003),位置0x5f47b0b3.要终止,按确定。
    要调试,按取消
      

  12.   


    Cdia   asd;
    asd.DoModal();
    再试
      

  13.   

    错了!

    Cdia   asd;
    asd.DoModal();
    注释一下
    再试
      

  14.   

    只把 asd.DoModal();
     注释都不出错了。
      

  15.   

    Cdia类 就是在资源里新建一个dialog,然后按 ctrl+w  用向导生成的。
    里面什么都没做。
      

  16.   


    Cdia   asd;
    改为
    asd.DoModal();DialogBox(hInst, (LPCTSTR)IDD_DIALOG1, hWnd, (DLGPROC)NewDialog);
      

  17.   


    Cdia   asd;
    asd.DoModal();
    改为
    DialogBox(hInst, (LPCTSTR)IDD_DIALOG1, hWnd, (DLGPROC)NewDialog);
      

  18.   

    那样应该可以,但是我想要跟新建的MFC应用程序一样的效果,因为我还有其他的很多东西要用类的,所以想找出这样做不可以的原因来。
      

  19.   

    MFC Exe 工种文件中。
    MFC 在WinMain里做了很多MFC其它类初始化工作,而你的 Win32 API工程中没有做这些初始化工作。在使用MFC类的时候当然会出错了。你可以看一下 MFC scr WinMain.cpp文件做了多少初始化工作。你的出错原因可以是:你的类中使用了MFC中没有被初始化的类。