Visual C++ 时尚编程百例002(MFC窗口)

打开vc2005

新建Win32项目,选择空项目。

CWinApp包括启动,初始化,运行和关闭应用程序所需的一切代码。

项目->属性,或者右击项目->属性(注意不是右击解决方案)
Visual C++ 时尚编程百例002(MFC窗口)

项目->添加新项->添加Application.cpp

代码一:

Visual C++ 时尚编程百例002(MFC窗口)
#include <afxwin.h>
class CMyApp: public CWinApp
{
public:
    
virtual BOOL InitInstance();
};

class CMainFrame:public CFrameWnd
{
public:
    CMainFrame()
    {
        Create(
0,_T("hi"));
    }
};
BOOL CMyApp::InitInstance(
void)//这个函数由WinMain()调用
{
    m_pMainWnd
=new CMainFrame;
    
//((CMainFrame*)m_pMainWnd)->Create(NULL,_T("the MFC app"));
    m_pMainWnd->ShowWindow(m_nCmdShow);
    
return TRUE;
}

//缺少这个全局变量就会提示如下错误信息:
//vc10023.exe 中的 0x7831d2a0 处未处理的异常: 0xC0000005: 读取位置 0x00000000 时发生访问冲突
CMyApp anApp;
Visual C++ 时尚编程百例002(MFC窗口)


代码二:

Visual C++ 时尚编程百例002(MFC窗口)
#include <afxwin.h>
class CMyApp: public CWinApp
{
public:
    
virtual BOOL InitInstance();
};

class CMainFrame:public CFrameWnd
{
//public:
//    CMainFrame()
//    {
//        Create(0,_T("hi"));
//    }
};
BOOL CMyApp::InitInstance(
void)//这个函数由WinMain()调用
{
    m_pMainWnd
=new CMainFrame;
    ((CMainFrame
*)m_pMainWnd)->Create(NULL,_T("the MFC app"));
    m_pMainWnd
->ShowWindow(m_nCmdShow);
    
return TRUE;
}

//缺少这个全局变量就会提示如下错误信息:
//vc10023.exe 中的 0x7831d2a0 处未处理的异常: 0xC0000005: 读取位置 0x00000000 时发生访问冲突
CMyApp anApp;
Visual C++ 时尚编程百例002(MFC窗口)

文档:http://files.cnblogs.com/greatverve/mfc-window.rar




    本文转自wenglabs博客园博客,原文链接:http://www.cnblogs.com/greatverve/archive/2011/03/04/vc100-2.html,如需转载请自行联系原作者