码迷,mamicode.com
首页 > 移动开发 > 详细

CWinApp类

时间:2020-03-30 00:23:04      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:构造函数   cmd   窗口   build   wpa   需要   default   star   mdt   

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类

标签:构造函数   cmd   窗口   build   wpa   需要   default   star   mdt   

原文地址:https://www.cnblogs.com/liu6666/p/12595931.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!