// [!output APP_IMPL] : Définit les comportements de classe pour l'application. // #include "stdafx.h" #include "[!output APP_HEADER]" #include "[!output MAIN_FRAME_HEADER]" [!if APP_TYPE_MDI] #include "[!output CHILD_FRAME_HEADER]" [!endif] [!if MINI_SERVER || FULL_SERVER || CONTAINER_SERVER] #include "[!output INPLACE_FRAME_HEADER]" [!endif] [!if OLEDB_RECORD_VIEW || ODBC_RECORD_VIEW] #include "[!output ROWSET_HEADER]" [!endif] [!if DOCVIEW] #include "[!output DOC_HEADER]" [!if PROJECT_STYLE_EXPLORER] #include "[!output TREE_VIEW_HEADER]" [!else] #include "[!output VIEW_HEADER]" [!endif] [!endif] #ifdef _DEBUG #define new DEBUG_NEW #endif // [!output APP_CLASS] BEGIN_MESSAGE_MAP([!output APP_CLASS], [!output APP_BASE_CLASS]) ON_COMMAND(ID_APP_ABOUT, &[!output APP_CLASS]::OnAppAbout) [!if APP_TYPE_MTLD] ON_COMMAND(ID_FILE_NEW_FRAME, &[!output APP_CLASS]::OnFileNewFrame) [!if DOCVIEW] ON_COMMAND(ID_FILE_NEW, &[!output APP_CLASS]::OnFileNew) [!endif] [!endif] [!if !DOCVIEW] [!if APP_TYPE_MDI] ON_COMMAND(ID_FILE_NEW, &[!output APP_CLASS]::OnFileNew) [!endif] [!endif] [!if DOCVIEW] [!if !DB_VIEW_NO_FILE] // Commandes de fichier standard [!if !APP_TYPE_MTLD] ON_COMMAND(ID_FILE_NEW, &[!output APP_BASE_CLASS]::OnFileNew) [!endif] ON_COMMAND(ID_FILE_OPEN, &[!output APP_BASE_CLASS]::OnFileOpen) [!endif] [!endif] [!if PRINTING && DOCVIEW] // Commande standard de configuration de l'impression ON_COMMAND(ID_FILE_PRINT_SETUP, &[!output APP_BASE_CLASS]::OnFilePrintSetup) [!endif] END_MESSAGE_MAP() // construction [!output APP_CLASS] [!output APP_CLASS]::[!output APP_CLASS]() { [!if CONTEXT_HELP && HELPSTYLE_HTML] EnableHtmlHelp(); [!endif] // TODO : ajoutez ici du code de construction, // Placez toutes les initialisations significatives dans InitInstance } [!if ATL_SUPPORT] // objet ATL Module CComModule _Module; [!endif] // Seul et unique objet [!output APP_CLASS] [!output APP_CLASS] theApp; [!if MINI_SERVER || FULL_SERVER || CONTAINER_SERVER || AUTOMATION] // Cet identificateur a été généré de sorte qu'il soit unique pour votre application // Vous pouvez le changer par un autre identificateur de votre choix // {[!output APP_CLSID_REGISTRY_FORMAT]} static const CLSID clsid = [!output APP_CLSID_STATIC_CONST_GUID_FORMAT]; [!endif] [!if AUTOMATION] const GUID CDECL BASED_CODE _tlid = [!output LIBID_STATIC_CONST_GUID_FORMAT]; const WORD _wVerMajor = 1; const WORD _wVerMinor = 0; [!endif] // initialisation de [!output APP_CLASS] BOOL [!output APP_CLASS]::InitInstance() { [!if MANIFEST] // InitCommonControlsEx() est requis sur Windows XP si le manifeste de l'application // spécifie l'utilisation de ComCtl32.dll version 6 ou ultérieure pour activer les // styles visuels. Dans le cas contraire, la création de fenêtres échouera. INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); // À définir pour inclure toutes les classes de contrôles communs à utiliser // dans votre application. InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); [!endif] [!output APP_BASE_CLASS]::InitInstance(); [!if OLEDB] CoInitialize(NULL); [!endif] [!if SOCKETS] if (!AfxSocketInit()) { AfxMessageBox(IDP_SOCKETS_INIT_FAILED); return FALSE; } [!endif] [!if CONTAINER || MINI_SERVER || FULL_SERVER || CONTAINER_SERVER || AUTOMATION || OLEDB || ACTIVEX_CONTROLS || ACCESSIBILITY] // Initialiser les bibliothèques OLE if (!AfxOleInit()) { AfxMessageBox(IDP_OLE_INIT_FAILED); return FALSE; } [!endif] [!if ACTIVEX_CONTROLS] AfxEnableControlContainer(); [!endif] // Initialisation standard // Si vous n'utilisez pas ces fonctionnalités et que vous souhaitez réduire la taille // de votre exécutable final, vous devez supprimer ci-dessous // les routines d'initialisation spécifiques dont vous n'avez pas besoin. // Changez la clé de Registre sous laquelle nos paramètres sont enregistrés // TODO : modifiez cette chaîne avec des informations appropriées, // telles que le nom de votre société ou organisation SetRegistryKey(_T("Applications locales générées par AppWizard")); [!if DOCVIEW] LoadStdProfileSettings([!output MRU_SIZE]); // Charge les options de fichier INI standard (y compris les derniers fichiers utilisés) [!endif] [!if !DOCVIEW] // Pour créer la fenêtre principale, ce code crée un nouvel objet fenêtre frame // qu'il définit ensuite en tant qu'objet fenêtre principale de l'application [!if APP_TYPE_MDI] CMDIFrameWnd* pFrame = new [!output MAIN_FRAME_CLASS]; [!else] [!if !DOCVIEW] CMainFrame* pFrame = new [!output MAIN_FRAME_CLASS]; [!else] CRuntimeClass* pClass = RUNTIME_CLASS(CMainFrame); CFrameWnd* pFrame = (CFrameWnd*) pClass->CreateObject(); ASSERT_KINDOF(CFrameWnd, pFrame); [!endif] [!endif] if (!pFrame) return FALSE; m_pMainWnd = pFrame; [!if APP_TYPE_SDI] [!if DOCVIEW] // charge le frame par rapport à un contexte vide CCreateContext context; [!else] // crée et charge le frame avec ses ressources [!endif] pFrame->LoadFrame(IDR_MAINFRAME, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, [!if DOCVIEW] &context); [!else] NULL); [!endif] [!else] // crée la fenêtre frame MDI principale if (!pFrame->LoadFrame(IDR_MAINFRAME)) return FALSE; // Essaie de charger les menus MDI partagés et la table d'accélérateurs //TODO : ajoutez des variables membres supplémentaires et chargez des appels pour // d'autres types de menus requis par votre application HINSTANCE hInst = AfxGetResourceHandle(); m_hMDIMenu = ::LoadMenu(hInst, MAKEINTRESOURCE(IDR_[!output SAFE_DOC_TYPE_NAME]TYPE)); m_hMDIAccel = ::LoadAccelerators(hInst, MAKEINTRESOURCE(IDR_[!output SAFE_DOC_TYPE_NAME]TYPE)); [!endif] [!else] // Inscrire les modèles de document de l'application. Ces modèles // lient les documents, fenêtres frame et vues entre eux [!if APP_TYPE_MDI] CMultiDocTemplate* pDocTemplate; pDocTemplate = new CMultiDocTemplate(IDR_[!output SAFE_DOC_TYPE_NAME]TYPE, [!else] [!if APP_TYPE_MTLD] CMultiDocTemplate* pDocTemplate; pDocTemplate = new CMultiDocTemplate( IDR_MAINFRAME, [!else] CSingleDocTemplate* pDocTemplate; pDocTemplate = new CSingleDocTemplate( IDR_MAINFRAME, [!endif] [!endif] RUNTIME_CLASS([!output DOC_CLASS]), [!if APP_TYPE_MDI] RUNTIME_CLASS([!output CHILD_FRAME_CLASS]), // frame enfant MDI personnalisé [!else] RUNTIME_CLASS([!output MAIN_FRAME_CLASS]), // fenêtre frame SDI principale [!endif] [!if PROJECT_STYLE_EXPLORER] RUNTIME_CLASS([!output TREE_VIEW_CLASS])); [!else] RUNTIME_CLASS([!output VIEW_CLASS])); [!endif] if (!pDocTemplate) return FALSE; [!if CONTAINER || CONTAINER_SERVER] [!if APP_TYPE_MDI] pDocTemplate->SetContainerInfo(IDR_[!output SAFE_DOC_TYPE_NAME]TYPE_CNTR_IP); [!else] pDocTemplate->SetContainerInfo(IDR_CNTR_INPLACE); [!endif] [!endif] [!if MINI_SERVER || FULL_SERVER || CONTAINER_SERVER] pDocTemplate->SetServerInfo( [!if APP_TYPE_MDI] IDR_[!output SAFE_DOC_TYPE_NAME]TYPE_SRVR_EMB, IDR_[!output SAFE_DOC_TYPE_NAME]TYPE_SRVR_IP, [!else] IDR_SRVR_EMBEDDED, IDR_SRVR_INPLACE, [!endif] RUNTIME_CLASS([!output INPLACE_FRAME_CLASS])); [!endif] [!if APP_TYPE_MTLD] m_pDocTemplate = pDocTemplate; [!endif] AddDocTemplate(pDocTemplate); [!if MINI_SERVER || FULL_SERVER || CONTAINER_SERVER || AUTOMATION] // Lier COleTemplateServer au modèle de document // COleTemplateServer crée de nouveaux documents, à la demande // de conteneurs OLE, en utilisant les informations // spécifiées dans le modèle de document [!if APP_TYPE_MDI || APP_TYPE_MTLD] m_server.ConnectTemplate(clsid, pDocTemplate, FALSE); // Inscrivez toutes les fabriques de serveur OLE comme étant en cours d'exécution. Cela permet aux bibliothèques // OLE de créer des objets à partir d'autres applications. COleTemplateServer::RegisterAll(); // Remarque : Les applications MDI inscrivent tous les objets serveur sans tenir compte // de la présence ou non des commutateurs /Embedding ou /Automation dans la ligne de commande [!else] m_server.ConnectTemplate(clsid, pDocTemplate, TRUE); // Remarque : Les applications SDI inscrivent les objets serveur uniquement si le commutateur /Embedding // ou /Automation figure dans la ligne de commande [!endif] [!endif] [!endif] [!if APP_TYPE_MDI && DOCVIEW] // crée la fenêtre frame MDI principale [!output MAIN_FRAME_CLASS]* pMainFrame = new [!output MAIN_FRAME_CLASS]; if (!pMainFrame || !pMainFrame->LoadFrame(IDR_MAINFRAME)) { delete pMainFrame; return FALSE; } m_pMainWnd = pMainFrame; [!if !MINI_SERVER] // appelle DragAcceptFiles uniquement s'il y a un suffixe // Dans une application MDI, cet appel doit avoir lieu juste après la définition de m_pMainWnd [!if HAS_SUFFIX && !HTML_EDITVIEW] // Activer les ouvertures via glisser-déplacer m_pMainWnd->DragAcceptFiles(); [!endif] [!endif] [!endif] [!if !MINI_SERVER] [!if HAS_SUFFIX && !HTML_EDITVIEW] // Activer les ouvertures d'exécution DDE EnableShellOpen(); RegisterShellFileTypes(TRUE); [!endif] [!endif] [!if DOCVIEW] // Analyser la ligne de commande pour les commandes shell standard, DDE, ouverture de fichiers CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); [!endif] [!if MINI_SERVER || FULL_SERVER || CONTAINER_SERVER || AUTOMATION] // L'application a été lancée avec le commutateur /Embedding ou /Automation. // Exécutez-la en tant que serveur Automation. if (cmdInfo.m_bRunEmbedded || cmdInfo.m_bRunAutomated) { [!if !APP_TYPE_MDI && !APP_TYPE_MTLD] // Inscrivez toutes les fabriques de serveur OLE comme étant en cours d'exécution. Cela permet aux bibliothèques // OLE de créer des objets à partir d'autres applications. COleTemplateServer::RegisterAll(); [!endif] // Ne pas afficher la fenêtre principale return TRUE; } // L'application a été lancée avec le commutateur /Unregserver ou /Unregister. Annulez l'inscription // de la bibliothèque de types. Une autre annulation d'inscription est effectuée dans ProcessShellCommand(). else if (cmdInfo.m_nShellCommand == CCommandLineInfo::AppUnregister) { [!if !MINI_SERVER] [!if HAS_SUFFIX && !HTML_EDITVIEW] UnregisterShellFileTypes(); [!endif] [!endif] [!if MINI_SERVER || FULL_SERVER || CONTAINER_SERVER] [!if ACTIVE_DOC_SERVER] m_server.UpdateRegistry(OAT_DOC_OBJECT_SERVER, NULL, NULL, FALSE); [!else] m_server.UpdateRegistry(OAT_INPLACE_SERVER, NULL, NULL, FALSE); [!endif] [!else] [!if AUTOMATION] m_server.UpdateRegistry(OAT_DISPATCH_OBJECT, NULL, NULL, FALSE); [!endif] [!endif] [!if AUTOMATION] AfxOleUnregisterTypeLib(_tlid, _wVerMajor, _wVerMinor); [!endif] [!if MINI_SERVER] return FALSE; [!endif] } // L'application a été lancée en mode autonome ou avec d'autres commutateurs (par exemple, /Register // ou /Regserver). Mettez à jour les entrées du Registre, y compris typelibrary. else { [!if MINI_SERVER || FULL_SERVER || CONTAINER_SERVER] [!if ACTIVE_DOC_SERVER] m_server.UpdateRegistry(OAT_DOC_OBJECT_SERVER); [!else] m_server.UpdateRegistry(OAT_INPLACE_SERVER); [!endif] [!else] [!if AUTOMATION] m_server.UpdateRegistry(OAT_DISPATCH_OBJECT); [!endif] [!endif] [!if AUTOMATION] COleObjectFactory::UpdateRegistryAll(); AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid); [!endif] [!if MINI_SERVER] if (cmdInfo.m_nShellCommand == CCommandLineInfo::AppRegister) return FALSE; [!endif] } [!endif] [!if MINI_SERVER] // Lorsqu'un mini-serveur est exécuté en mode autonome, la base de registres est mise à jour, // et un message avertit l'utilisateur qu'il doit utiliser la boîte de dialogue Insérer un objet d'un conteneur // pour pouvoir utiliser le serveur. Les mini-serveurs ne comportent pas d'interfaces utilisateur autonomes AfxMessageBox(IDP_USE_INSERT_OBJECT); return FALSE; [!else] [!if DOCVIEW] // Commandes de dispatch spécifiées sur la ligne de commande. Retournent FALSE si // l'application a été lancée avec /RegServer, /Register, /Unregserver ou /Unregister. if (!ProcessShellCommand(cmdInfo)) return FALSE; [!endif] [!if APP_TYPE_MDI] // La fenêtre principale a été initialisée et peut donc être affichée et mise à jour [!if DOCVIEW] [!if MAIN_FRAME_MAXIMIZED] pMainFrame->ShowWindow(SW_SHOWMAXIMIZED); [!else] [!if MAIN_FRAME_MINIMIZED] pMainFrame->ShowWindow(SW_SHOWMINIMIZED); [!else] [!if APP_TYPE_SDI || APP_TYPE_MTLD] pMainFrame->ShowWindow(SW_SHOW); [!else] pMainFrame->ShowWindow(m_nCmdShow); [!endif] [!endif] [!endif] pMainFrame->UpdateWindow(); [!else] [!if MAIN_FRAME_MAXIMIZED] pFrame->ShowWindow(SW_SHOWMAXIMIZED); [!else] [!if MAIN_FRAME_MINIMIZED] pFrame->ShowWindow(SW_SHOWMINIMIZED); [!else] [!if APP_TYPE_SDI || APP_TYPE_MTLD] pFrame->ShowWindow(SW_SHOW); [!else] pFrame->ShowWindow(m_nCmdShow); [!endif] [!endif] [!endif] pFrame->UpdateWindow(); [!endif] [!endif] [!if APP_TYPE_SDI || APP_TYPE_MTLD] // La seule fenêtre a été initialisée et peut donc être affichée et mise à jour [!if DOCVIEW] [!if MAIN_FRAME_MAXIMIZED] m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED); [!else] [!if MAIN_FRAME_MINIMIZED] m_pMainWnd->ShowWindow(SW_SHOWMINIMIZED); [!else] [!if APP_TYPE_SDI || APP_TYPE_MTLD] m_pMainWnd->ShowWindow(SW_SHOW); [!else] m_pMainWnd->ShowWindow(m_nCmdShow); [!endif] [!endif] [!endif] m_pMainWnd->UpdateWindow(); [!else] [!if MAIN_FRAME_MAXIMIZED] pFrame->ShowWindow(SW_SHOWMAXIMIZED); [!else] [!if MAIN_FRAME_MINIMIZED] pFrame->ShowWindow(SW_SHOWMINIMIZED); [!else] [!if APP_TYPE_SDI || APP_TYPE_MTLD] pFrame->ShowWindow(SW_SHOW); [!else] pFrame->ShowWindow(m_nCmdShow); [!endif] [!endif] [!endif] pFrame->UpdateWindow(); [!endif] // appelle DragAcceptFiles uniquement s'il y a un suffixe // Dans une application SDI, cet appel doit avoir lieu juste après ProcessShellCommand [!if HAS_SUFFIX && !HTML_EDITVIEW] // Activer les ouvertures via glisser-déplacer m_pMainWnd->DragAcceptFiles(); [!endif] [!endif] return TRUE; [!endif] } [!if !DOCVIEW] // gestionnaires de messages pour [!output APP_CLASS] [!if APP_TYPE_MDI] [!if !DOCVIEW] int [!output APP_CLASS]::ExitInstance() { //TODO : gérez les ressources supplémentaires que vous avez ajoutées if (m_hMDIMenu != NULL) FreeResource(m_hMDIMenu); if (m_hMDIAccel != NULL) FreeResource(m_hMDIAccel); return CWinApp::ExitInstance(); } [!endif] [!endif] [!if APP_TYPE_MDI || DOCVIEW] void [!output APP_CLASS]::OnFileNew() { [!if APP_TYPE_SDI] CString strUntitled; CFrameWnd* pFrameWnd = DYNAMIC_DOWNCAST(CFrameWnd, m_pMainWnd); if (pFrameWnd != NULL) { //TODO : fermez et supprimez toutes les données de fichier spécifiques stockées // en mémoire. Ensuite, exécutez l'instruction if suivante // pour rétablir le titre de la fenêtre frame if (strUntitled.LoadString(AFX_IDS_UNTITLED)) pFrameWnd->UpdateFrameTitleForDocument(strUntitled); else pFrameWnd->UpdateFrameTitleForDocument(NULL); } [!else] [!output MAIN_FRAME_CLASS]* pFrame = STATIC_DOWNCAST([!output MAIN_FRAME_CLASS], m_pMainWnd); // crée une nouvelle fenêtre enfant MDI pFrame->CreateNewChild( RUNTIME_CLASS(CChildFrame), IDR_[!output SAFE_DOC_TYPE_NAME]TYPE, m_hMDIMenu, m_hMDIAccel); [!endif] } [!endif] [!endif] // boîte de dialogue CAboutDlg utilisée pour la boîte de dialogue 'À propos de' pour votre application class CAboutDlg : public CDialog { public: CAboutDlg(); // Données de boîte de dialogue enum { IDD = IDD_ABOUTBOX }; protected: virtual void DoDataExchange(CDataExchange* pDX); // Prise en charge de DDX/DDV // Implémentation protected: DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { [!if ACCESSIBILITY] EnableActiveAccessibility(); [!endif] } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) END_MESSAGE_MAP() // Commande App pour exécuter la boîte de dialogue void [!output APP_CLASS]::OnAppAbout() { CAboutDlg aboutDlg; aboutDlg.DoModal(); } // gestionnaires de messages pour [!output APP_CLASS] [!if APP_TYPE_MTLD] [!if DOCVIEW] void [!output APP_CLASS]::OnFileNewFrame() { ASSERT(m_pDocTemplate != NULL); CDocument* pDoc = NULL; CFrameWnd* pFrame = NULL; // Crée une nouvelle instance du document référencé // par le membre m_pDocTemplate. pDoc = m_pDocTemplate->CreateNewDocument(); if (pDoc != NULL) { // Si la création a réussi, créer un nouveau frame pour ce // document. pFrame = m_pDocTemplate->CreateNewFrame(pDoc, NULL); if (pFrame != NULL) { // Définit le titre et initialise le document. // Si l'initialisation du document échoue, nettoyez // la fenêtre frame et le document. m_pDocTemplate->SetDefaultTitle(pDoc); if (!pDoc->OnNewDocument()) { pFrame->DestroyWindow(); pFrame = NULL; } else { // Sinon, met à jour le frame m_pDocTemplate->InitialUpdateFrame(pFrame, pDoc, TRUE); } } } // En cas d'échec, nettoie le document et affiche un // message à l'utilisateur. if (pFrame == NULL || pDoc == NULL) { delete pDoc; AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC); } } void [!output APP_CLASS]::OnFileNew() { CDocument* pDoc = NULL; CFrameWnd* pFrame; pFrame = DYNAMIC_DOWNCAST(CFrameWnd, CWnd::GetActiveWindow()); if (pFrame != NULL) pDoc = pFrame->GetActiveDocument(); if (pFrame == NULL || pDoc == NULL) { // s'il s'agit du premier document, créer un document standard CWinApp::OnFileNew(); } else { // Sinon, déterminez si les modifications doivent être enregistrées, puis // demandez au document de se réinitialiser lui-même. if (!pDoc->SaveModified()) return; CDocTemplate* pTemplate = pDoc->GetDocTemplate(); ASSERT(pTemplate != NULL); pTemplate->SetDefaultTitle(pDoc); pDoc->OnNewDocument(); } } [!else] void [!output APP_CLASS]::OnFileNewFrame() { CMainFrame* pFrame = new CMainFrame; pFrame->LoadFrame(IDR_MAINFRAME, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, NULL); pFrame->ShowWindow(SW_SHOW); pFrame->UpdateWindow(); m_aryFrames.Add(pFrame->GetSafeHwnd()); } [!endif] [!endif]