// [!output APP_IMPL] : definisce i comportamenti delle classi per l'applicazione. // #include "stdafx.h" #include "[!output APP_HEADER]" #include "[!output MAIN_FRAME_HEADER]" [!if DOCVIEW] #include "[!output DOC_HEADER]" #include "[!output VIEW_HEADER]" [!endif] #ifdef _DEBUG #define new DEBUG_NEW #endif // [!output APP_CLASS] BEGIN_MESSAGE_MAP([!output APP_CLASS], [!output APP_BASE_CLASS]) [!if !MULTIPLE_PLATFORM] [!if !SMARTPHONE2003_UI_MODEL] ON_COMMAND(ID_APP_ABOUT, &[!output APP_CLASS]::OnAppAbout) [!endif] [!else] [!if SMARTPHONE2003_UI_MODEL] #ifndef WIN32_PLATFORM_WFSP [!endif] ON_COMMAND(ID_APP_ABOUT, &[!output APP_CLASS]::OnAppAbout) [!if SMARTPHONE2003_UI_MODEL] #endif // !WIN32_PLATFORM_WFSP [!endif] [!endif] [!if PRINTING && DOCVIEW] // Comando di stampa standard ON_COMMAND(ID_FILE_PRINT_SETUP, &[!output APP_BASE_CLASS]::OnFilePrintSetup) [!endif] [!if DOCVIEW] ON_COMMAND(ID_FILE_NEW, &[!output APP_BASE_CLASS]::OnFileNew) ON_COMMAND(ID_FILE_OPEN, &[!output APP_BASE_CLASS]::OnFileOpen) [!endif] END_MESSAGE_MAP() // costruzione di [!output APP_CLASS] [!if HELPSTYLE_WINHELP] [!output APP_CLASS]::[!output APP_CLASS](LPCTSTR lpszHelpName) : [!output APP_BASE_CLASS](lpszHelpName) [!else] [!output APP_CLASS]::[!output APP_CLASS]() : [!output APP_BASE_CLASS]() [!endif] { // TODO: inserire qui il codice di costruzione. // Inserire l'inizializzazione significativa in InitInstance. } [!if ATL_SUPPORT] // oggetto modulo ATL CComModule _Module; [!endif] // L'unico e solo oggetto [!output APP_CLASS] [!if HELPSTYLE_WINHELP] [!output APP_CLASS] theApp(_T("HELP_NAME")); [!else] [!output APP_CLASS] theApp; [!endif] // Inizializzazione di [!output APP_CLASS] BOOL [!output APP_CLASS]::InitInstance() { [!if !MULTIPLE_PLATFORM] [!if POCKETPC2003_UI_MODEL || SMARTPHONE2003_UI_MODEL] // Č necessario chiamare SHInitExtraControls una sola volta durante l'inizializzazione dell'applicazione in uso al fine di inizializzare // i controlli specifici di Windows Mobile, come CAPEDIT e SIPPREF. SHInitExtraControls(); [!endif] [!else] [!if POCKETPC2003_UI_MODEL || SMARTPHONE2003_UI_MODEL] #if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP) // Č necessario chiamare SHInitExtraControls una sola volta durante l'inizializzazione dell'applicazione in uso al fine di inizializzare // i controlli specifici di Windows Mobile, come CAPEDIT e SIPPREF. SHInitExtraControls(); #endif // WIN32_PLATFORM_PSPC || WIN32_PLATFORM_WFSP [!endif] [!endif] [!if SOCKETS] if (!AfxSocketInit()) { AfxMessageBox(IDP_SOCKETS_INIT_FAILED); return FALSE; } [!endif] [!if ACTIVEX_CONTROLS] AfxEnableControlContainer(); [!endif] // Inizializzazione standard // Se non si utilizzano queste funzionalitą e si desidera ridurre la dimensione // dell'eseguibile finale, č necessario rimuovere dal seguente codice // le specifiche routine di inizializzazione che non sono necessarie. // Modificare la chiave del Registro di sistema in cui sono memorizzate le impostazioni // TODO: č necessario modificare questa stringa in modo appropriato, // inserendo ad esempio il nome della societą o dell'organizzazione. SetRegistryKey(_T("Applicazioni locali generate tramite la creazione guidata applicazione")); [!if !DOCVIEW] // Per creare la finestra principale, il codice crea un nuovo oggetto della finestra cornice, // quindi lo imposta come oggetto della finestra principale dell'applicazione. CMainFrame* pFrame = new [!output MAIN_FRAME_CLASS]; if (!pFrame) return FALSE; m_pMainWnd = pFrame; [!if APP_TYPE_SDI || APP_TYPE_SDI_DOCLIST] // creare e caricare il frame con le relative risorse. pFrame->LoadFrame(IDR_MAINFRAME, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, NULL); [!endif] [!else] [!if APP_TYPE_SDI_DOCLIST] [!if !MULTIPLE_PLATFORM] [!if POCKETPC2003_UI_MODEL] CDocListDocTemplate* pDocTemplate; pDocTemplate = new CDocListDocTemplate( IDR_MAINFRAME, RUNTIME_CLASS([!output DOC_CLASS]), RUNTIME_CLASS([!output MAIN_FRAME_CLASS]), // finestra cornice SDI principale RUNTIME_CLASS([!output VIEW_CLASS])); AddDocTemplate(pDocTemplate); // Analizza la riga di comando per verificare la presenza di comandi della shell standard, DDE, di apertura file CCommandLineInfo cmdInfo; cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing; ParseCommandLine(cmdInfo); pDocTemplate->ShowDocList(); // se non č presente alcun file nell'elenco dei documenti, ne verrą creato uno nuovo. CDocList* pDocList = pDocTemplate->m_pWndDocList; if (pDocList->GetItemCount() == 0) { pDocList->OnClose(); OnFileNew(); } [!else] CSingleDocTemplate* pDocTemplate; pDocTemplate = new CSingleDocTemplate( IDR_MAINFRAME, RUNTIME_CLASS([!output DOC_CLASS]), RUNTIME_CLASS([!output MAIN_FRAME_CLASS]), // finestra cornice SDI principale RUNTIME_CLASS([!output VIEW_CLASS])); if (!pDocTemplate) return FALSE; AddDocTemplate(pDocTemplate); [!endif] [!else] #ifdef WIN32_PLATFORM_PSPC CDocListDocTemplate* pDocTemplate; pDocTemplate = new CDocListDocTemplate( IDR_MAINFRAME, RUNTIME_CLASS([!output DOC_CLASS]), RUNTIME_CLASS([!output MAIN_FRAME_CLASS]), // finestra cornice SDI principale RUNTIME_CLASS([!output VIEW_CLASS])); AddDocTemplate(pDocTemplate); // Analizza la riga di comando per verificare la presenza di comandi della shell standard, DDE, di apertura file CCommandLineInfo cmdInfo; cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing; ParseCommandLine(cmdInfo); pDocTemplate->ShowDocList(); // se non č presente alcun file nell'elenco dei documenti, ne verrą creato uno nuovo. CDocList* pDocList = pDocTemplate->m_pWndDocList; if (pDocList->GetItemCount() == 0) { pDocList->OnClose(); OnFileNew(); } #else CSingleDocTemplate* pDocTemplate; pDocTemplate = new CSingleDocTemplate( IDR_MAINFRAME, RUNTIME_CLASS([!output DOC_CLASS]), RUNTIME_CLASS([!output MAIN_FRAME_CLASS]), // finestra cornice SDI principale RUNTIME_CLASS([!output VIEW_CLASS])); if (!pDocTemplate) return FALSE; AddDocTemplate(pDocTemplate); #endif // WIN32_PLATFORM_PSPC [!endif] [!else] CSingleDocTemplate* pDocTemplate; pDocTemplate = new CSingleDocTemplate( IDR_MAINFRAME, RUNTIME_CLASS([!output DOC_CLASS]), RUNTIME_CLASS([!output MAIN_FRAME_CLASS]), // finestra cornice SDI principale RUNTIME_CLASS([!output VIEW_CLASS])); if (!pDocTemplate) return FALSE; AddDocTemplate(pDocTemplate); [!endif] [!endif] [!if DOCVIEW] [!if APP_TYPE_SDI_DOCLIST] [!if !MULTIPLE_PLATFORM] [!if !POCKETPC2003_UI_MODEL] // Analizza la riga di comando per verificare la presenza di comandi della shell standard, DDE, di apertura file CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); // Invia i comandi specificati nella riga di comando. Restituisce FALSE se // l'applicazione č stata avviata con l'opzione /RegServer, /Register, /Unregserver o /Unregister. if (!ProcessShellCommand(cmdInfo)) return FALSE; [!endif] [!else] #ifndef WIN32_PLATFORM_PSPC // Analizza la riga di comando per verificare la presenza di comandi della shell standard, DDE, di apertura file CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); // Invia i comandi specificati nella riga di comando. Restituisce FALSE se // l'applicazione č stata avviata con l'opzione /RegServer, /Register, /Unregserver o /Unregister. if (!ProcessShellCommand(cmdInfo)) return FALSE; #endif // !WIN32_PLATFORM_PSPC [!endif] [!else] // Analizza la riga di comando per verificare la presenza di comandi della shell standard, DDE, di apertura file CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); // Invia i comandi specificati nella riga di comando. Restituisce FALSE se // l'applicazione č stata avviata con l'opzione /RegServer, /Register, /Unregserver o /Unregister. if (!ProcessShellCommand(cmdInfo)) return FALSE; [!endif] [!endif] [!if APP_TYPE_SDI_DOCLIST] [!if !MULTIPLE_PLATFORM] [!if !POCKETPC2003_UI_MODEL] // L'unica e sola finestra č stata inizializzata, quindi č possibile visualizzarla e aggiornarla. [!if DOCVIEW] m_pMainWnd->ShowWindow(SW_SHOW); m_pMainWnd->UpdateWindow(); [!else] pFrame->ShowWindow(SW_SHOW); pFrame->UpdateWindow(); [!endif] [!endif] [!else] #ifndef WIN32_PLATFORM_PSPC // L'unica e sola finestra č stata inizializzata, quindi č possibile visualizzarla e aggiornarla. [!if DOCVIEW] m_pMainWnd->ShowWindow(SW_SHOW); m_pMainWnd->UpdateWindow(); [!else] pFrame->ShowWindow(SW_SHOW); pFrame->UpdateWindow(); [!endif] #endif // !WIN32_PLATFORM_PSPC [!endif] [!else] [!if APP_TYPE_SDI] // L'unica e sola finestra č stata inizializzata, quindi č possibile visualizzarla e aggiornarla. [!if DOCVIEW] m_pMainWnd->ShowWindow(SW_SHOW); m_pMainWnd->UpdateWindow(); [!else] pFrame->ShowWindow(SW_SHOW); pFrame->UpdateWindow(); [!endif] [!endif] [!endif] return TRUE; } [!if !DOCVIEW] // gestori dei messaggi di [!output APP_CLASS] [!if DOCVIEW] void [!output APP_CLASS]::OnFileNew() { [!if APP_TYPE_SDI || APP_TYPE_SDI_DOCLIST] CString strUntitled; CFrameWnd* pFrameWnd = DYNAMIC_DOWNCAST(CFrameWnd, m_pMainWnd); if (pFrameWnd != NULL) { //TODO: chiudere ed eliminare tutti i dati specifici del file che si trovano in // memoria. Al termine, eseguire la seguente istruzione if // per reimpostare il titolo della finestra cornice. 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); // creare una nuova finestra MDI figlio. pFrame->CreateNewChild( RUNTIME_CLASS(CChildFrame), IDR_[!output SAFE_DOC_TYPE_NAME]TYPE, m_hMDIMenu, m_hMDIAccel); [!endif] } [!endif] [!endif] [!if !MULTIPLE_PLATFORM] [!if !SMARTPHONE2003_UI_MODEL] // finestra di dialogo CAboutDlg utilizzata per visualizzare le informazioni sull'applicazione. class CAboutDlg : public CDialog { public: CAboutDlg(); // Dati della finestra di dialogo enum { IDD = IDD_ABOUTBOX }; protected: virtual void DoDataExchange(CDataExchange* pDX); // supporto DDX/DDV // Implementazione protected: [!if POCKETPC2003_UI_MODEL] #ifdef _DEVICE_RESOLUTION_AWARE afx_msg void OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/); #endif [!endif] virtual BOOL OnInitDialog(); DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BOOL CAboutDlg::OnInitDialog() { CDialog::OnInitDialog(); return TRUE; // restituisce TRUE a meno che non sia stato impostato lo stato attivo su un controllo // ECCEZIONE: le pagine delle proprietą OCX devono restituire FALSE } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) [!if POCKETPC2003_UI_MODEL] #ifdef _DEVICE_RESOLUTION_AWARE ON_WM_SIZE() #endif [!endif] END_MESSAGE_MAP() [!if POCKETPC2003_UI_MODEL] #ifdef _DEVICE_RESOLUTION_AWARE void CAboutDlg::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/) { if (AfxIsDRAEnabled()) { DRA::RelayoutDialog( AfxGetResourceHandle(), this->m_hWnd, DRA::GetDisplayMode() != DRA::Portrait ? MAKEINTRESOURCE(IDD_ABOUTBOX_WIDE) : MAKEINTRESOURCE(IDD_ABOUTBOX)); } } #endif [!endif] // comando dell'applicazione per eseguire la finestra di dialogo void [!output APP_CLASS]::OnAppAbout() { CAboutDlg aboutDlg; aboutDlg.DoModal(); } [!endif] [!else] [!if SMARTPHONE2003_UI_MODEL] #ifndef WIN32_PLATFORM_WFSP [!endif] // finestra di dialogo CAboutDlg utilizzata per visualizzare le informazioni sull'applicazione. class CAboutDlg : public CDialog { public: CAboutDlg(); // Dati della finestra di dialogo enum { IDD = IDD_ABOUTBOX }; protected: virtual void DoDataExchange(CDataExchange* pDX); // supporto DDX/DDV // Implementazione protected: #ifdef _DEVICE_RESOLUTION_AWARE afx_msg void OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/); #endif virtual BOOL OnInitDialog(); DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BOOL CAboutDlg::OnInitDialog() { CDialog::OnInitDialog(); return TRUE; // restituisce TRUE a meno che non sia stato impostato lo stato attivo su un controllo // ECCEZIONE: le pagine delle proprietą OCX devono restituire FALSE } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) #ifdef _DEVICE_RESOLUTION_AWARE ON_WM_SIZE() #endif END_MESSAGE_MAP() #ifdef _DEVICE_RESOLUTION_AWARE void CAboutDlg::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/) { if (AfxIsDRAEnabled()) { DRA::RelayoutDialog( AfxGetResourceHandle(), this->m_hWnd, DRA::GetDisplayMode() != DRA::Portrait ? MAKEINTRESOURCE(IDD_ABOUTBOX_WIDE) : MAKEINTRESOURCE(IDD_ABOUTBOX)); } } #endif // comando dell'applicazione per eseguire la finestra di dialogo void [!output APP_CLASS]::OnAppAbout() { CAboutDlg aboutDlg; aboutDlg.DoModal(); } [!if SMARTPHONE2003_UI_MODEL] #endif // !WIN32_PLATFORM_WFSP [!endif] [!endif]