// [!output APP_IMPL] : 定義應用程式的類別行為。 // #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] // 標準列印設定命令 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() // [!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: 在此加入建構程式碼, // 將所有重要的初始設定加入 InitInstance 中 } [!if ATL_SUPPORT] // ATL 模組物件 CComModule _Module; [!endif] // 僅有的一個 [!output APP_CLASS] 物件 [!if HELPSTYLE_WINHELP] [!output APP_CLASS] theApp(_T("HELP_NAME")); [!else] [!output APP_CLASS] theApp; [!endif] // [!output APP_CLASS] 初始設定 BOOL [!output APP_CLASS]::InitInstance() { [!if !MULTIPLE_PLATFORM] [!if POCKETPC2003_UI_MODEL || SMARTPHONE2003_UI_MODEL] // 必須在應用程式初始化過程中呼叫一次 SHInitExtraControls,以初始化 // 任何 Windows Mobile 專用的控制項,如 CAPEDIT 和 SIPPREF。 SHInitExtraControls(); [!endif] [!else] [!if POCKETPC2003_UI_MODEL || SMARTPHONE2003_UI_MODEL] #if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP) // 必須在應用程式初始化過程中呼叫一次 SHInitExtraControls,以初始化 // 任何 Windows Mobile 專用的控制項,如 CAPEDIT 和 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] // 標準初始設定 // 如果您不使用這些功能並且想減少 // 最後完成的可執行檔大小,您可以 // 從下列程式碼移除不需要的初始化常式, // 變更儲存設定值的登錄機碼 // TODO: 您應該適度修改此字串 // (例如,公司名稱或組織名稱) SetRegistryKey(_T("本機 AppWizard 所產生的應用程式")); [!if !DOCVIEW] // 若要建立主視窗,此程式碼建立新的框架視窗物件,且將其設定為 // 應用程式的主視窗物件 CMainFrame* pFrame = new [!output MAIN_FRAME_CLASS]; if (!pFrame) return FALSE; m_pMainWnd = pFrame; [!if APP_TYPE_SDI || APP_TYPE_SDI_DOCLIST] // 使用其資源建立並載入框架 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]), // 主 SDI 框架視窗 RUNTIME_CLASS([!output VIEW_CLASS])); AddDocTemplate(pDocTemplate); // 剖析標準 Shell 命令、DDE、檔案開啟舊檔的命令列 CCommandLineInfo cmdInfo; cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing; ParseCommandLine(cmdInfo); pDocTemplate->ShowDocList(); // 如果 doclist 中沒有檔案,我們就建立新的檔案。 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]), // 主 SDI 框架視窗 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]), // 主 SDI 框架視窗 RUNTIME_CLASS([!output VIEW_CLASS])); AddDocTemplate(pDocTemplate); // 剖析標準 Shell 命令、DDE、檔案開啟舊檔的命令列 CCommandLineInfo cmdInfo; cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing; ParseCommandLine(cmdInfo); pDocTemplate->ShowDocList(); // 如果 doclist 中沒有檔案,我們就建立新的檔案。 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]), // 主 SDI 框架視窗 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]), // 主 SDI 框架視窗 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] // 剖析標準 Shell 命令、DDE、檔案開啟舊檔的命令列 CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); // 在命令列中指定的分派命令。如果已使用 // /RegServer、/Register、/Unregserver 或 /Unregister 啟動應用程式,將傳回 FALSE。 if (!ProcessShellCommand(cmdInfo)) return FALSE; [!endif] [!else] #ifndef WIN32_PLATFORM_PSPC // 剖析標準 Shell 命令、DDE、檔案開啟舊檔的命令列 CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); // 在命令列中指定的分派命令。如果已使用 // /RegServer、/Register、/Unregserver 或 /Unregister 啟動應用程式,將傳回 FALSE。 if (!ProcessShellCommand(cmdInfo)) return FALSE; #endif // !WIN32_PLATFORM_PSPC [!endif] [!else] // 剖析標準 Shell 命令、DDE、檔案開啟舊檔的命令列 CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); // 在命令列中指定的分派命令。如果已使用 // /RegServer、/Register、/Unregserver 或 /Unregister 啟動應用程式,將傳回 FALSE。 if (!ProcessShellCommand(cmdInfo)) return FALSE; [!endif] [!endif] [!if APP_TYPE_SDI_DOCLIST] [!if !MULTIPLE_PLATFORM] [!if !POCKETPC2003_UI_MODEL] // 僅初始化一個視窗,所以顯示並更新該視窗 [!if DOCVIEW] m_pMainWnd->ShowWindow(SW_SHOW); m_pMainWnd->UpdateWindow(); [!else] pFrame->ShowWindow(SW_SHOW); pFrame->UpdateWindow(); [!endif] [!endif] [!else] #ifndef WIN32_PLATFORM_PSPC // 僅初始化一個視窗,所以顯示並更新該視窗 [!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] // 僅初始化一個視窗,所以顯示並更新該視窗 [!if DOCVIEW] m_pMainWnd->ShowWindow(SW_SHOW); m_pMainWnd->UpdateWindow(); [!else] pFrame->ShowWindow(SW_SHOW); pFrame->UpdateWindow(); [!endif] [!endif] [!endif] return TRUE; } [!if !DOCVIEW] // [!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: 關閉並摧毀任何您從記憶體所取得 // 有關特定檔案的資料。一旦完成, // 如果陳述式重設框架視窗的標題則執行下列 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); // 建立新的 MDI 子視窗 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] // 對 App About 使用 CAboutDlg 對話方塊 class CAboutDlg : public CDialog { public: CAboutDlg(); // 對話方塊資料 enum { IDD = IDD_ABOUTBOX }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支援 // 程式碼實作 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; // 傳回 TRUE,除非您對控制項設定焦點 // EXCEPTION: OCX 屬性頁應傳回 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] // 執行對話方塊的應用程式命令 void [!output APP_CLASS]::OnAppAbout() { CAboutDlg aboutDlg; aboutDlg.DoModal(); } [!endif] [!else] [!if SMARTPHONE2003_UI_MODEL] #ifndef WIN32_PLATFORM_WFSP [!endif] // 對 App About 使用 CAboutDlg 對話方塊 class CAboutDlg : public CDialog { public: CAboutDlg(); // 對話方塊資料 enum { IDD = IDD_ABOUTBOX }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支援 // 程式碼實作 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; // 傳回 TRUE,除非您對控制項設定焦點 // EXCEPTION: OCX 屬性頁應傳回 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 // 執行對話方塊的應用程式命令 void [!output APP_CLASS]::OnAppAbout() { CAboutDlg aboutDlg; aboutDlg.DoModal(); } [!if SMARTPHONE2003_UI_MODEL] #endif // !WIN32_PLATFORM_WFSP [!endif] [!endif]