一个基本的 MFC 程序

// Include the MFC header:
// (you do not need to and should not include the standard Windows headers, e.g. 
// Windows.h)
#include <AfxWin.h>               // MFC core and standard components
// The following header defines resource constants, such as dialog and control IDs:
#include "resource.h"

// The basic element of an MFC application is a class that inherits from CWinApp.
class CMyApp : public CWinApp
{
    // This gets called as the application gets initialized.
    virtual BOOL InitInstance()
    {
        // Initialize a CDialog object to show in a moment.
        CDialog dlg(IDD_DIALOG1);
        // Display the dialog box as a modal dialog box.
        dlg.DoModal();

        // Return FALSE from this method to exit the application.
        return FALSE;
    }
};

// The one and only application object.
CMyWinApp theApp;

摘要:

IDD_DIALOG1 应该是由资源编辑器(例如 Visual Studio 内置的资源编辑器)创建的项目资源文件中定义的对话框的 ID。 (资源文件通常具有 .rc 扩展名。)要自定义对话框的行为,可以从 CDialog 派生新类。

模式对话框运行自己的消息循环。调用“dlg.DoModal();” 在用户关闭对话框之前不会返回。

如果我们从 InitInstance() 返回 TRUE,它将启动应用程序的消息循环。当你拥有一个更复杂,非基于对话框的应用程序时,可以使用此选项。