一個基本的 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,它將啟動應用程式的訊息迴圈。當你擁有一個更復雜,非基於對話方塊的應用程式時,可以使用此選項。