CWinApp类
Posted 坦坦荡荡
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CWinApp类相关的知识,希望对你有一定的参考价值。
CWinApp类将封装应用程序的初始化,运行和终止。基于框架生成的应用程序必须有且只有一个对象的类派生自CWinApp,创建窗口前需要构造此对象
CWinApp从CWinThread公有派生,它构成了应用程序执行的主线程
成员变量:
成员方法
CWinApp方法调用顺序:
MFC程序最先执行的不是WinMain函数
//构造函数源码
CWinApp::CWinApp(LPCTSTR lpszAppName) //参数有默认值NULL
{
if (lpszAppName != NULL)
m_pszAppName = _tcsdup(lpszAppName);
else
m_pszAppName = NULL;
// initialize CWinThread state
AFX_MODULE_STATE* pModuleState = _AFX_CMDTARGET_GETSTATE();
ENSURE(pModuleState);
AFX_MODULE_THREAD_STATE* pThreadState = pModuleState->m_thread;
ENSURE(pThreadState);
ASSERT(AfxGetThread() == NULL);
pThreadState->m_pCurrentWinThread = this;
ASSERT(AfxGetThread() == this);
m_hThread = ::GetCurrentThread();
m_nThreadID = ::GetCurrentThreadId();
// initialize CWinApp state
ASSERT(afxCurrentWinApp == NULL); // only one CWinApp object please
pModuleState->m_pCurrentWinApp = this;
ASSERT(AfxGetApp() == this);
// in non-running state until WinMain
m_hInstance = NULL;
m_hLangResourceDLL = NULL;
m_pszHelpFilePath = NULL;
m_pszProfileName = NULL;
m_pszRegistryKey = NULL;
m_pszExeName = NULL;
m_pszAppID = NULL;
m_pRecentFileList = NULL;
m_pDocManager = NULL;
m_atomApp = m_atomSystemTopic = NULL;
m_lpCmdLine = NULL;
m_pCmdInfo = NULL;
m_pDataRecoveryHandler = NULL;
// initialize wait cursor state
m_nWaitCursorCount = 0;
m_hcurWaitCursorRestore = NULL;
// initialize current printer state
m_hDevMode = NULL;
m_hDevNames = NULL;
m_nNumPreviewPages = 0; // not specified (defaults to 1)
// initialize DAO state
m_lpfnDaoTerm = NULL; // will be set if AfxDaoInit called
// other initialization
m_bHelpMode = FALSE;
m_eHelpType = afxWinHelp;
m_nSafetyPoolSize = 512; // default size
m_dwRestartManagerSupportFlags = 0; // don\'t support Restart Manager by default
m_nAutosaveInterval = 5 * 60 * 1000; // default autosave interval is 5 minutes (only has effect if autosave flag is set)
m_bTaskbarInteractionEnabled = TRUE;
// Detect the kind of OS:
OSVERSIONINFO osvi;
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
// Fix for warnings when building against WinBlue build 9444.0.130614-1739
// warning C4996: \'GetVersionExW\': was declared deprecated
// externalapis\\windows\\8.1\\sdk\\inc\\sysinfoapi.h(442)
// Deprecated. Use VerifyVersionInfo* or IsWindows* macros from VersionHelpers.
#pragma warning( disable : 4996 )
::GetVersionEx(&osvi);
#pragma warning( default : 4996 )
m_bIsWindows7 = (osvi.dwMajorVersion == 6) && (osvi.dwMinorVersion >= 1) || (osvi.dwMajorVersion > 6);
// Taskbar initialization:
m_bComInitialized = FALSE;
m_pTaskbarList = NULL;
m_pTaskbarList3 = NULL;
m_bTaskBarInterfacesAvailable = TRUE;
}
以上是关于CWinApp类的主要内容,如果未能解决你的问题,请参考以下文章
mfc中 theapp全局对象是属于cwinapp基类还是属于派生的子类?
CWinApp dll 文件给出带有 CWinApp 类的概率
猎豹MFC1 第一个窗口CWinApp CFrameWnd InitInstance 消息映射CPaint CRect Create