📄 appcore.cpp
字号:
// This is a part of the Microsoft Foundation Classes C++ library.
// Copyright (C) 1992-1998 Microsoft Corporation
// All rights reserved.
//
// This source code is only intended as a supplement to the
// Microsoft Foundation Classes Reference and related
// electronic documentation provided with the library.
// See these sources for detailed information regarding the
// Microsoft Foundation Classes product.
#include "stdafx.h"
#include <malloc.h>
#ifdef AFX_CORE1_SEG
#pragma code_seg(AFX_CORE1_SEG)
#endif
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
AFX_STATIC_DATA const TCHAR _afxFileSection[] = _T("Recent File List");
AFX_STATIC_DATA const TCHAR _afxFileEntry[] = _T("File%d");
AFX_STATIC_DATA const TCHAR _afxPreviewSection[] = _T("Settings");
AFX_STATIC_DATA const TCHAR _afxPreviewEntry[] = _T("PreviewPages");
/////////////////////////////////////////////////////////////////////////////
// globals (internal library use)
// CDocManager statics are in this file for granularity reasons
BOOL CDocManager::bStaticInit = TRUE;
CDocManager* CDocManager::pStaticDocManager = NULL;
CPtrList* CDocManager::pStaticList = NULL;
BEGIN_MESSAGE_MAP(CWinApp, CCmdTarget)
//{{AFX_MSG_MAP(CWinApp)
// Global File commands
ON_COMMAND(ID_APP_EXIT, OnAppExit)
// MRU - most recently used file menu
ON_UPDATE_COMMAND_UI(ID_FILE_MRU_FILE1, OnUpdateRecentFileMenu)
ON_COMMAND_EX_RANGE(ID_FILE_MRU_FILE1, ID_FILE_MRU_FILE16, OnOpenRecentFile)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// _AFX_WIN_STATE implementation
#ifndef _AFX_NO_GRAYDLG_SUPPORT
#ifdef AFX_INIT_SEG
#pragma code_seg(AFX_INIT_SEG)
#endif
_AFX_WIN_STATE::_AFX_WIN_STATE()
{
// Note: it is only necessary to intialize non-zero data.
}
#ifdef AFX_TERM_SEG
#pragma code_seg(AFX_TERM_SEG)
#endif
_AFX_WIN_STATE::~_AFX_WIN_STATE()
{
AfxDeleteObject((HGDIOBJ*)&m_hDlgBkBrush);
}
#endif //!_AFX_NO_GRAYDLG_SUPPORT
#ifdef AFX_INIT_SEG
#pragma code_seg(AFX_INIT_SEG)
#endif
CWinApp::CWinApp(LPCTSTR lpszAppName)
{
if (lpszAppName != NULL)
m_pszAppName = _tcsdup(lpszAppName);
else
m_pszAppName = NULL;
// initialize CWinThread state
AFX_MODULE_STATE* pModuleState = _AFX_CMDTARGET_GETSTATE();
AFX_MODULE_THREAD_STATE* pThreadState = pModuleState->m_thread;
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_pszHelpFilePath = NULL;
m_pszProfileName = NULL;
m_pszRegistryKey = NULL;
m_pszExeName = NULL;
m_pRecentFileList = NULL;
m_pDocManager = NULL;
m_atomApp = m_atomSystemTopic = NULL;
m_lpCmdLine = NULL;
m_pCmdInfo = 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_nSafetyPoolSize = 512; // default size
}
BOOL CWinApp::InitApplication()
{
if (CDocManager::pStaticDocManager != NULL)
{
if (m_pDocManager == NULL)
m_pDocManager = CDocManager::pStaticDocManager;
CDocManager::pStaticDocManager = NULL;
}
if (m_pDocManager != NULL)
m_pDocManager->AddDocTemplate(NULL);
else
CDocManager::bStaticInit = FALSE;
return TRUE;
}
BOOL CWinApp::InitInstance()
{
return TRUE;
}
void CWinApp::LoadStdProfileSettings(UINT nMaxMRU)
{
ASSERT_VALID(this);
ASSERT(m_pRecentFileList == NULL);
if (nMaxMRU != 0)
{
// create file MRU since nMaxMRU not zero
m_pRecentFileList = new CRecentFileList(0, _afxFileSection, _afxFileEntry,
nMaxMRU);
m_pRecentFileList->ReadList();
}
// 0 by default means not set
m_nNumPreviewPages = GetProfileInt(_afxPreviewSection, _afxPreviewEntry, 0);
}
void CWinApp::ParseCommandLine(CCommandLineInfo& rCmdInfo)
{
for (int i = 1; i < __argc; i++)
{
LPCTSTR pszParam = __targv[i];
BOOL bFlag = FALSE;
BOOL bLast = ((i + 1) == __argc);
if (pszParam[0] == '-' || pszParam[0] == '/')
{
// remove flag specifier
bFlag = TRUE;
++pszParam;
}
rCmdInfo.ParseParam(pszParam, bFlag, bLast);
}
}
/////////////////////////////////////////////////////////////////////////////
// CCommandLineInfo implementation
CCommandLineInfo::CCommandLineInfo()
{
m_bShowSplash = TRUE;
m_bRunEmbedded = FALSE;
m_bRunAutomated = FALSE;
m_nShellCommand = FileNew;
}
CCommandLineInfo::~CCommandLineInfo()
{
}
void CCommandLineInfo::ParseParam(const TCHAR* pszParam,BOOL bFlag,BOOL bLast)
{
if (bFlag)
{
USES_CONVERSION;
ParseParamFlag(T2CA(pszParam));
}
else
ParseParamNotFlag(pszParam);
ParseLast(bLast);
}
#ifdef UNICODE
void CCommandLineInfo::ParseParam(const char* pszParam, BOOL bFlag, BOOL bLast)
{
if (bFlag)
ParseParamFlag(pszParam);
else
ParseParamNotFlag(pszParam);
ParseLast(bLast);
}
#endif // UNICODE
void CCommandLineInfo::ParseParamFlag(const char* pszParam)
{
// OLE command switches are case insensitive, while
// shell command switches are case sensitive
if (lstrcmpA(pszParam, "pt") == 0)
m_nShellCommand = FilePrintTo;
else if (lstrcmpA(pszParam, "p") == 0)
m_nShellCommand = FilePrint;
else if (lstrcmpiA(pszParam, "Unregister") == 0 ||
lstrcmpiA(pszParam, "Unregserver") == 0)
m_nShellCommand = AppUnregister;
else if (lstrcmpA(pszParam, "dde") == 0)
{
AfxOleSetUserCtrl(FALSE);
m_nShellCommand = FileDDE;
}
else if (lstrcmpiA(pszParam, "Embedding") == 0)
{
AfxOleSetUserCtrl(FALSE);
m_bRunEmbedded = TRUE;
m_bShowSplash = FALSE;
}
else if (lstrcmpiA(pszParam, "Automation") == 0)
{
AfxOleSetUserCtrl(FALSE);
m_bRunAutomated = TRUE;
m_bShowSplash = FALSE;
}
}
void CCommandLineInfo::ParseParamNotFlag(const TCHAR* pszParam)
{
if (m_strFileName.IsEmpty())
m_strFileName = pszParam;
else if (m_nShellCommand == FilePrintTo && m_strPrinterName.IsEmpty())
m_strPrinterName = pszParam;
else if (m_nShellCommand == FilePrintTo && m_strDriverName.IsEmpty())
m_strDriverName = pszParam;
else if (m_nShellCommand == FilePrintTo && m_strPortName.IsEmpty())
m_strPortName = pszParam;
}
#ifdef UNICODE
void CCommandLineInfo::ParseParamNotFlag(const char* pszParam)
{
if (m_strFileName.IsEmpty())
m_strFileName = pszParam;
else if (m_nShellCommand == FilePrintTo && m_strPrinterName.IsEmpty())
m_strPrinterName = pszParam;
else if (m_nShellCommand == FilePrintTo && m_strDriverName.IsEmpty())
m_strDriverName = pszParam;
else if (m_nShellCommand == FilePrintTo && m_strPortName.IsEmpty())
m_strPortName = pszParam;
}
#endif
void CCommandLineInfo::ParseLast(BOOL bLast)
{
if (bLast)
{
if (m_nShellCommand == FileNew && !m_strFileName.IsEmpty())
m_nShellCommand = FileOpen;
m_bShowSplash = !m_bRunEmbedded && !m_bRunAutomated;
}
}
/////////////////////////////////////////////////////////////////////////////
// App termination
CWinApp::~CWinApp()
{
// free doc manager
if (m_pDocManager != NULL)
delete m_pDocManager;
// free recent file list
if (m_pRecentFileList != NULL)
delete m_pRecentFileList;
// free static list of document templates
if (!afxContextIsDLL)
{
if (CDocManager::pStaticList != NULL)
{
delete CDocManager::pStaticList;
CDocManager::pStaticList = NULL;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -