class CWinApp: public CWinThread {DECLARE_DYNAMIC (CWinApp) public: // ConstructorCWinApp (LPCTSTR lpszAppName = NULL); // app name defaults to EXE name // Attributes // Startup args (do not change) HINSTANCE m_hInstance; HINSTANCE m_hPrevInstance; LPTSTR m_lpCmdLine ; int m_nCmdShow; // Running args (can be changed in InitInstance) LPCTSTR m_pszAppName; // human readable name // (from constructor or AFX_IDS_APP_TITLE) LPCTSTR m_pszRegistryKey; // used for registry entriesCDocManager * m_pDocManager; // Support for Shift F1 help mode.BOOL m_bHelpMode; // are we in Shift F1 mode public: // set in constructor to override defaultLPCTSTR m_pszExeName; // executable name (no spaces) LPCTSTR m_pszHelpFilePath; // default based on module pathLPCTSTR m_pszProfileName; //? default based on app name // Initialization Operations - should be done in InitInstanceprotected: void LoadStdProfileSettings (UINT nMaxMRU = _AFX_MRU_COUNT); // load MRU file list and last preview statevoid EnableShellOpen (); # ifndef _AFX_NO_GRAYD LG_SUPPORTvoid SetDialogBkColor (COLORREF clrCtlBk = RGB (192, 192, 192), COLORREF clrCtlText = RGB (0, 0, 0)); // set dialog box and message box background color # endifvoid SetRegistryKey (LPCTSTR lpszRegistryKey); void SetRegistryKey (UINT nIDRegistryKey); // enables app settings in registry instead of INI files // (registry key is usually a "company name") # ifndef _AFX_NO_CTL3D_SUPPORTBOOL Enable3dControls (); // use CTL3D32.DLL for 3D controls in dialogs # ifndef _AFXDLLBOOL Enable3dControlsStatic ( ); // staticly link ctl3d.lib instead # Endif # Endifvoid Registershellfiletypes (Bool BCompat = false); // Call After all doc templates are registeredvoid registershellfiletypescompat ();
// for backwards compatibilityvoid UnregisterShellFileTypes (); // Helper Operations - usually done in InitInstancepublic: // CursorsHCURSOR LoadCursor (LPCTSTR lpszResourceName) const; HCURSOR LoadCursor (UINT nIDResource) const; HCURSOR LoadStandardCursor (LPCTSTR lpszCursorName) const; // for IDC_ valuesHCURSOR LoadOEMCursor (UINT nIDCursor) const; // for OCR_ values // IconsHICON LoadIcon (LPCTSTR lpszResourceName) const; HICON LoadIcon (UINT nIDResource) const; HICON LoadStandardIcon (LPCTSTR lpszIconName) const; // for IDI_ valuesHICON LoadOEMIcon (UINT nIDIcon) const; // for OIC_ values // Profile settings (to the app specific .INI file, or registry) UINT GetProfileInt (LPCTSTR lpszSection, LPCTSTR lpszEntry, int nDefault); BOOL WriteProfileInt (LPCTSTR lpszSection, LPCTSTR lpszEntry, int nValue); CString GetProfileString ( LPCTSTR lpszSection, LPCTSTR lpszEntry, LPCTSTR lpszDefault = NULL); BOOL WriteProfileString (LPCTSTR lpszSection, LPCTSTR lpszEntry, LPCTSTR lpszValue); BOOL GetProfileBinary (LPCTSTR lp szSection, LPCTSTR lpszEntry, LPBYTE * ppData, UINT * pBytes); BOOL WriteProfileBinary (LPCTSTR lpszSection, LPCTSTR lpszEntry, LPBYTE pData, UINT nBytes); BOOL Unregister (); LONG DelRegTree (HKEY hParentKey, const CString & strKeyName); // Running Operations - to be done on a running application // Dealing with document templatesvoid AddDocTemplate (CDocTemplate * pTemplate); POSITION GetFirstDocTemplatePosition () const; CDocTemplate * GetNextDocTemplate (POSITION & pos) const; // Dealing with filesvirtual CDocument * OpenDocumentFile (LPCTSTR lpszFileName); / / Open named filevirtual void addtorecentfilelist (lpctstr lpszpathname); // add to MRU // Printer DC setup routine, 'struct tagpd'
is a PRINTDLG structurevoid SelectPrinter (HANDLE hDevNames, HANDLE hDevMode, BOOL bFreeOld = TRUE); BOOL CreatePrinterDC (CDC & dc); # ifndef _UNICODEBOOL GetPrinterDeviceDefaults (struct tagPDA * pPrintDlg); # elseBOOL GetPrinterDeviceDefaults (struct tagPDW * pPrintDlg); # endif // Command line parsingBOOL RunEmbedded (); BOOL RunAutomated (); void ParseCommandLine (CCommandLineInfo & rCmdInfo); BOOL ProcessShellCommand (CCommandLineInfo & rCmdInfo); // Overridables // hooks for your initialization codevirtual BOOL InitApplication (); // exitingvirtual BOOL SaveAllModified (); / / save before exitvoid HideApplication (); void CloseAllDocuments (BOOL bEndSession); // close documents before exiting // Advanced: to override message boxes and other hooksvirtual int DoMessageBox (LPCTSTR lpszPrompt, UINT nType, UINT nIDPrompt); virtual void DoWaitCursor (int Ncode); // 0 => restore, 1 => begin, -1 => end // Advanced: Process Async Dde Requestvirtual Bool OnDDecommand; // Advanced: Help SupportVirtual Void Win Help (DWORD dwData, UINT nCmd = HELP_CONTEXT); // Command Handlersprotected: // map to the following for file new / openafx_msg void OnFileNew (); afx_msg void OnFileOpen (); // map to the following to enable print setupafx_msg void OnFilePrintSetup (); // map to the following to enable helpafx_msg void OnContextHelp (); // shift-F1afx_msg void OnHelp (); // F1 (uses current context) afx_msg void OnHelpIndex (); // ID_HELP_INDEXafx_msg void OnHelpFinder (); / / ID_HELP_FINDER, ID_DEFAULT_HELPafx_msg void OnHelpUsing (); // ID_HELP_USING // Implementationprotected: HGLOBAL m_hDevMode; // printer Dev ModeHGLOBAL m_hDevNames; // printer Device NamesDWORD m_dwPromptContext;
// help context override for message boxint m_nWaitCursorCount; // for wait cursor (> 0 => waiting) HCURSOR m_hcurWaitCursorRestore; // old cursor to restore after wait cursorCRecentFileList * m_pRecentFileList; void UpdatePrinterSelection (BOOL bForceDefaults); void SaveStdProfileSettings (); / / save options to .INI filepublic: // public for implementation accessCCommandLineInfo * m_pCmdInfo; ATOM m_atomApp, m_atomSystemTopic; // for DDE openUINT m_nNumPreviewPages; // number of default printed pagessize_t m_nSafetyPoolSize; // ideal sizevoid (AFXAPI * m_lpfnDaoTerm) (); void DevModeChange (LPTSTR lpDeviceName); void SetCurrentHandles (); int GetOpenDocumentCount (); // helpers for standard commdlg dialogsBOOL DoPromptFileName (CString & fileName, UINT nIDSTitle, DWORD lFlags, BOOL bOpenFileDialog, CDocTemplate * pTemplate); int DoPrintDialog (CPrintDialog * pPD) void enablemodeless; // to disable ole in-place dialogs // overrides for implementationvirtual bool initInstance (); Virtual Int ExitInst ance (); // return app exit codevirtual int Run (); virtual BOOL OnIdle (LONG lCount); // return TRUE if more idle processingvirtual LRESULT ProcessWndProcException (CException * e, const MSG * pMsg); public: virtual ~ CWinApp ( ); # ifdef _DEBUGvirtual void AssertValid () const; virtual void Dump (CDumpContext & dc) const; # endif // helpers for registrationHKEY GetSectionKey (LPCTSTR lpszSection); HKEY GetAppRegistryKey (); protected: // {{aFX_MSG (CWinApp) afx_msg void ONAPPEXIT (); AFX_MSG Void OnupdateRecentFileMenu (CCMDUI * PCMDUI); AFX_MSG BOOL ONOPENRECENTFILE (UINT NID); //}}} AFX_MSGDECLARE_MESSAGE_MAP ()};
1:
Public: // constructorcwinapp (lpctstr lpszappname = null); // App Name defaults to EXE NAME
Why not set the CWINAPP constructor to protected? This is obvious and the CVIEW is not the design? CWINAPP must inherit, Overrided InitInstace () functions can only be used. as follows:
BOOL CEx03aApp :: InitInstance () {AfxEnableControlContainer (); # ifdef _AFXDLLEnable3dControls (); // Call this when using MFC in a shared DLL # elseEnable3dControlsStatic (); // Call this when linking to MFC statically # endifSetRegistryKey (_T ( "Local AppWizard-Generated Applications ")); LoadStdProfileSettings (); // Load standard INI file options (including MRU) CSingleDocTemplate * pDocTemplate; pDocTemplate = new CSingleDocTemplate (IDR_MAINFRAME, RUNTIME_CLASS (CEx03aDoc), RUNTIME_CLASS (CMainFrame), // main SDI frame windowRUNTIME_CLASS (CEx03aView)); AddDocTemplate (pDocTemplate); CCommandLineInfo cmdInfo; ParseCommandLine (cmdInfo);! if (ProcessShellCommand (cmdInfo)) return FALSE; m_pMainWnd-> ShowWindow (SW_SHOW); m_pMainWnd-> UpdateWindow (); return TRUE;}
Does CWINAPP have any secrets? Or purely a negligence of the MFC group?
2:...
Public: // attributes // startup args (do not change) hinstance m_hinstance; hinstance m_hprevinstance; lptstr m_lpcmdline; int m_ncmdshow;
...
It is also possible to see that the command parameters of the Winmain function are stored, many friends may be strange, if in Delphi, how to get command parameters like Winmain? Because, Delphi's entry is not a function, but begin ... End. Delphi can of course take command parameters, using Object Pascal's function.
Int apientry Winmain (Hinstance Hinstance, Hinstance Hprevinstance, LPSTR LPCMDLINE, INT NCMDSHOW) {// Todo: Place Code Here.msg Msg; Haccel HaccelTable; ...
}
Seeing this, it seems that it doesn't comply with the OO rule, because how can the class data go out? In fact, there is nothing in the world "absolute", in addition to "sports" :), if you don't put data public, you must use a lot, hinstance getxxx () {} and void setxxx (hinstance h) {}, such a function, Such a function, using the efficiency of C , flexible philosophical thinking is violated, can be said to be C ugly code, then what code can go out in public, what must be hidden? If the class data is any assignment, it is not necessary to monitor it, it is possible to put it. Conversely, you must private! So, what kind of behavior can be used as a member of the class, and those don't need to be a class member function? According to the parent of C : class = data behavior, the condition is: under the invariance of the class. If the behavior of a class does not maintain the "implicit invariant", the function can be used as an external function.
If the type implied invariance is: f, class name: c, data: a; class behavior: b, then: f (c) = a b; um, long.
3:
// CursorsHCURSOR LoadCursor (LPCTSTR lpszResourceName) const; HCURSOR LoadCursor (UINT nIDResource) const; HCURSOR LoadStandardCursor (LPCTSTR lpszCursorName) const; // for IDC_ valuesHCURSOR LoadOEMCursor (UINT nIDCursor) const; // for OCR_ values // IconsHICON LoadIcon (LPCTSTR lpszResourceName ) Const; Hicon LoadCon (LPCTSTR LPSZICONNAME) const; // for idi_ valueshicon loadingoemicon (uint nidicon) const; // for ic_ value
...
There is a big pile of GUI methods, in Delphi, make these methods in the property and put this information in * .frm form code, not part of the * .pas code. The PAS code is responsible for the logic code. So the same functionality VC .H / CPP code and PAS code, the PAS code is very concise, clean. If you are vc, you have to take some energy to put it on the Gui, ft ,,,
4:
protected: // map to the following for file new / openafx_msg void OnFileNew (); afx_msg void OnFileOpen (); // map to the following to enable print setupafx_msg void OnFilePrintSetup (); // map to the following to enable helpafx_msg void OnContextHelp (); // shift-F1afx_msg void OnHelp (); // F1 (uses current context) afx_msg void OnHelpIndex (); // ID_HELP_INDEXafx_msg void OnHelpFinder (); // ID_HELP_FINDER, ID_DEFAULT_HELPafx_msg void OnHelpUsing (); // ID_HELP_USING this section Is an event code. CWINApp This role, in the Tapplication in Delphi, is associated with one of them, but due to the different way of frame design, the purpose and realization of these 2 classes. MFC uses the MVC frame design pattern, and Delphi uses the Layer Service frame design mode to be Continued
--- by Littleroy 2004-7-2