MFC程序引导过程(二)

<pre name="code" class="cpp"><pre name="code" class="cpp">// 333.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "333.h"
#include "333Dlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/
// CMy333App

BEGIN_MESSAGE_MAP(CMy333App, CWinApp)
	//{{AFX_MSG_MAP(CMy333App)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG
	ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()

/
// CMy333App construction

CMy333App::CMy333App()
{
	// TODO: add construction code here,											
	// Place all significant initialization in InitInstance
}

/
// The one and only CMy333App object
											CWinApp?

CMy333App theApp;	第一步:实例化应用程序类的对象(CWinApp),
					在当前程序的333.h文件中有:class CMy333App : public CWinApp	
						1.一个MFC程序,有且只有一个从WinApp派生出的类(应用程序类)-》CMy333App?,
						也只有一个从应用程序对象所实例化的对象表示应用程序本身,theApp;
						2.在MFC应用程序中,是通过产生一个应用程序对象,用它来唯一表示了应用程序;
						3.构造应用程序对象时,调用基类CWinApp的构造函数
/
// CMy333App initialization

BOOL CMy333App::InitInstance()	第二步:调用应用程序类中的InitInstance()函数,该函数在基类中定义为虚函数
{
	if (!AfxSocketInit())
	{
		AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
		return FALSE;
	}

	AfxEnableControlContainer();

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	CMy333Dlg dlg;				第三步:定义主对话框类的对象dlg;
								并且调用对话框类的构造函数CMy333Dlg(CWnd *pParent=Null);
								注:333Dlg.h的头文件中有class CMy333Dlg : public CDialog
	m_pMainWnd = &dlg;
	int nResponse = dlg.DoModal();	第四步:调用主对话框对象的DoModal()函数,??
					|		
					|—>a.调用主对话框对象中的OnInitDialog()函数初始化对话框
					|	  OnInitDialog()是CDialog类的一个虚函数,可以由子类重载。
					|	  当CDiaog子类调用DoModal()函数时,就会触发一系列函数调用,
					|	  最终调用OnInitDialog()。可以在VC6中创建一个基于对话框的MFC应用程序,
					|	  在OnInitDialog里面打上断点,当程序运行进入断点是,打开调用堆栈窗口,
					|	  就可以跟踪得到调用OnInitDialog()的函数。
					|
					|—>b.调用OnPaint()函数,绘制窗口
					第五步:对话框退出后,返回DoModel()函数状态给nResponse
										

									
	if (nResponse == IDOK)						
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with OK
	}
	else if (nResponse == IDCANCEL)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with Cancel
	}

	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.
	return FALSE;
}


 
</pre>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值