Premiers pas avec mfc
Sur cette page
Un programme MFC de base
// 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;
Sommaire:
IDD_DIALOG1 doit être l’ID d’une boîte de dialogue définie dans un fichier de ressources de projet créé par un éditeur de ressources, tel que celui intégré à Visual Studio. (Un fichier de ressources porte généralement l’extension .rc.) Pour personnaliser le comportement d’une boîte de dialogue, vous pouvez dériver une nouvelle classe de CDialog.
Une boîte de dialogue modale exécute sa propre boucle de message. L’appel “dlg.DoModal();” ne revient pas tant que la boîte de dialogue n’a pas été fermée par l’utilisateur.
Si nous avions renvoyé TRUE à partir de InitInstance(), cela aurait démarré la boucle de messages de l’application. Ceci est utilisé lorsque vous avez une application plus complexe, non basée sur des boîtes de dialogue.