1、创建的对话框名字是“2”,会有三个类,CAoutDlg类,CMy2App类,CMy2Dlg类;
2、CAoutDlg类是关于对话框,不用多管;
3、CMy2App类
(1)头文件
// 2.h : main header file for the 2 application
//
//这是一中常见的防止头文件被重复包含的格式
#if !defined(AFX_2_H__54191561_7B45_4E73_9CC7_672DCCBFDD4A__INCLUDED_)
#define AFX_2_H__54191561_7B45_4E73_9CC7_672DCCBFDD4A__INCLUDED_
//MSC代表微软c编译器,VER代表版本
//是指如果vc编译器的版本大于1000则这个语句被编译!VC++6.0就是1200
//#pragma once则由编译器提供保证:同一个文件不会被包含多次
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
//如果没有定义__AFXWIN_H__,编译时就报错“error :include 'stdafx.h' before including this file for PCH
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif
#include "resource.h" // main symbols
/
// CMy2App:
// See 2.cpp for the implementation of this class
//
class CMy2App : public CWinApp
{
public:
CMy2App();
// Overrides
// ClassWizard generated virtual function overrides
//{
{AFX_VIRTUAL(CMy2App)
public:
virtual BOOL InitInstance();
//}}AFX_VIRTUAL
// Implementation
//{
{AFX_MSG(CMy2App)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/
//{
{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_2_H__54191561_7B45_4E73_9CC7_672DCCBFDD4A__INCLUDED_)
(2)源文件
// 2.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "2.h"
#include "2Dlg.h"
//当在debug模式下时,我们分配内存时的new被替换成DEBUG_NEW,
//而这个DEBUG_NEW不仅要传入内存块的大小,还要传入源文件名和行号,这就有个好处,即当发生内存泄漏时,
//我们可以在调试模式下定位到该问题代码处。
//若删掉该句,就不能进行定位了。而在release版本下的new就是简单的new,并不会传入文件名和行号。
//因此,我们在开发代码阶段,保留上述代码是值得的。
//当碰到__FILE__时,编译器会把__FILE__替换成一个字符串,这个字符串就是当前在编译的文件的路径名。在DEBUG_NEW的定义中没有直接使用__FILE__,而是用了THIS_FILE,其目的是为了减小目标文件的大小
#ifdef _DEBUG //表示在调试状态下编译,因此相应修改了两个符号的定义
#define new DEBUG_NEW //在MFC中,可以使用 DEBUG_NEW 宏代替 new 运算符来帮助定位内存泄漏
#undef THIS_FILE //取消THIS_FILE的定义
static char THIS_FILE[] = __FILE__; //定义THIS_FILE指向文件名
#endif
/
// CMy2App
BEGIN_MESSAGE_MAP(CMy2App, CWinApp)
//{
{AFX_MSG_MAP(CMy2App)
// NOTE - the ClassWizard will add and remove mapping m