目录
接下:VC++基于MFC的程序框架剖析 AfxWinMain函数 AfxGetThread函数 AfxGetApp函数 afxCurrentWinApp函数(四)
CWinApp类的定义(afxwin.h*):
class CWinApp : public CWinThread
{
DECLARE_DYNAMIC(CWinApp)
public:
// Constructor
explicit CWinApp(LPCTSTR lpszAppName = NULL); // app name defaults to EXE name
// Attributes
// Startup args (do not change)
// This module's hInstance.
HINSTANCE m_hInstance;
// Pointer to the command-line.
LPTSTR m_lpCmdLine;
// Initial state of the application's window; normally,
// this is an argument to ShowWindow().
int m_nCmdShow;
// Running args (can be changed in InitInstance)
// Human-redable name of the application. Normally set in
// constructor or retreived from AFX_IDS_APP_TITLE.
LPCTSTR m_pszAppName;
/// <summary>
/// Application User Model ID.</summary>
LPCTSTR m_pszAppID;
// Name of registry key for this application. See
// SetRegistryKey() member function.
LPCTSTR m_pszRegistryKey;
// Pointer to CDocManager used to manage document templates
// for this application instance.
CDocManager* m_pDocManager;
// Support for Shift+F1 help mode.
// TRUE if we're in SHIFT+F1 mode.
BOOL m_bHelpMode;
public:
// set in constructor to override default
// Executable name (no spaces).
LPCTSTR m_pszExeName;
// Default based on this module's path.
LPCTSTR m_pszHelpFilePath;
// Default based on this application's name.
LPCTSTR m_pszProfileName;
// Sets and initializes usage of HtmlHelp instead of WinHelp.
void EnableHtmlHelp();
// Sets and initializes usage of HtmlHelp instead of WinHelp.
void SetHelpMode( AFX_HELP_TYPE eHelpType );
AFX_HELP_TYPE GetHelpMode();
// help mode used by the app
AFX_HELP_TYPE m_eHelpType;
// Returns TRUE is application is running under Windows 7 or higher
BOOL IsWindows7();
// Initialization Operations - should be done in InitInstance
protected:
// Load MRU file list and last preview state.
void LoadStdProfileSettings(UINT nMaxMRU = _AFX_MRU_COUNT);
void EnableShellOpen();
// SetDialogBkColor is no longer supported.
// To change dialog background and text color, handle WM_CTLCOLORDLG instead.
AFX_DEPRECATED("CWinApp::SetDialogBkColor is no longer supported. Instead, handle WM_CTLCOLORDLG in your dialog")
void SetDialogBkColor(COLORREF clrCtlBk = RGB(192, 192, 192), COLORREF clrCtlText = RGB(0, 0, 0));
// Set registry key name to be used by CWinApp's
// profile member functions; prevents writing to an INI file.
void SetRegistryKey(LPCTSTR lpszRegistryKey);
void SetRegistryKey(UINT nIDRegistryKey);
/// <summary>
/// Explicitly sets Application User Model ID for the application. This method should be called before any user interface
/// is presented to user (the best place is the application constructor).</summary>
/// <param name="lpcszAppID">Specifies the Application User Model ID.</param>
void SetAppID(LPCTSTR lpcszAppID);
// Enable3dControls and Enable3dControlsStatic are no longer necessary.
AFX_DEPRECATED("CWinApp::Enable3dControls is no longer needed. You should remove this call.")
BOOL Enable3dControls();
#ifndef _AFXDLL
AFX_DEPRECATED("CWinApp::Enable3dControlsStatic is no longer needed. You should remove this call.")
BOOL Enable3dControlsStatic();
#endif
void RegisterShellFileTypes(BOOL bCompat = FALSE);
// call after all doc templates are registered
void UnregisterShellFileTypes();
public:
// Loads a cursor resource.
HCURSOR LoadCursor(LPCTSTR lpszResourceName) const;
HCURSOR LoadCursor(UINT nIDResource) const;
// Loads a stock cursor resource; for for IDC_* values.
HCURSOR LoadStandardCursor(LPCTSTR lpszCursorName) const;
// Loads an OEM cursor; for all OCR_* values.
HCURSOR LoadOEMCursor(UINT nIDCursor) const;
// Loads an icon resource.
HICON LoadIcon(LPCTSTR lpszResourceName) const;
HICON LoadIcon(UINT nIDResource) const;
// Loads an icon resource; for stock IDI_ values.
HICON LoadStandardIcon(LPCTSTR lpszIconName) const;
// Loads an OEM icon resource; for all OIC_* values.
HICON LoadOEMIcon(UINT nIDIcon) const;
// Retrieve an integer value from INI file or registry.
virtual UINT GetProfileInt(LPCTSTR lpszSection, LPCTSTR lpszEntry, int nDefault);
// Sets an integer value to INI file or registry.
virtual BOOL WriteProfileInt(LPCTSTR lpszSection, LPCTSTR lpszEntry, int nValue);
// Retrieve a string value from INI file or registry.
virtual CString GetProfileString(LPCTSTR lpszSection, LPCTSTR lpszEntry, LPCTSTR lpszDefault = NULL);
// Sets a string value to INI file or registry.