📄 globals.cpp
字号:
//*******************************************************************************
// COPYRIGHT NOTES
// ---------------
// This source code is a part of BCGControlBar library.
// You may use, compile or redistribute it as part of your application
// for free. You cannot redistribute it as a part of a software development
// library without the agreement of the author. If the sources are
// distributed along with the application, you should leave the original
// copyright notes in the source code without any changes.
// This code can be used WITHOUT ANY WARRANTIES on your own risk.
//
// Stas Levin <stas@iet.co.il>
//*******************************************************************************
#include "stdafx.h"
#include "globals.h"
#include "bcgbarres.h"
static const CString strOfficeFontName = _T("Tahoma");
static const CString strDefaultFontName = _T("MS Sans Serif");
static const CString strVertFontName = _T("Arial");
static int CALLBACK FontFamalyProcFonts (const LOGFONT FAR* lplf,
const TEXTMETRIC FAR* /*lptm*/,
ULONG /*ulFontType*/,
LPARAM /*lParam*/)
{
ASSERT (lplf != NULL);
CString strFont = lplf->lfFaceName;
return strFont.CollateNoCase (strOfficeFontName) == 0 ? 0 : 1;
}
/////////////////////////////////////////////////////////////////////////////
// Cached system metrics, etc
GLOBAL_DATA globalData;
// Initialization code
GLOBAL_DATA::GLOBAL_DATA()
{
//---------------------------------------------------------
// Cached system values (updated in CWnd::OnSysColorChange)
//---------------------------------------------------------
hbrBtnShadow = NULL;
hbrBtnHilite = NULL;
UpdateSysColors();
m_hcurStretch = NULL;
m_hcurStretchVert = NULL;
m_hcurHand = NULL;
//------------------
// Initialize fonts:
//------------------
NONCLIENTMETRICS info;
info.cbSize = sizeof(info);
::SystemParametersInfo (SPI_GETNONCLIENTMETRICS, sizeof(info), &info, 0);
LOGFONT lf;
memset (&lf, 0, sizeof (LOGFONT));
lf.lfCharSet = DEFAULT_CHARSET; // Add by Yuhu.Wang on 99/10/25
lf.lfHeight = info.lfMenuFont.lfHeight;
//////////////////////////////////////////////
// Modify by Yuhu.Wang on 99/11/02
// Check if we should use system font
//--------------------------------------------
_tcscpy (lf.lfFaceName, info.lfMenuFont.lfFaceName);
BOOL fUseSystemFont = (info.lfMenuFont.lfCharSet > SYMBOL_CHARSET);
if (!fUseSystemFont)
{
//----------------------------------
// Check for "Tahoma" font existance:
//----------------------------------
CWindowDC dc (NULL);
if (::EnumFontFamilies (dc.GetSafeHdc (), NULL, FontFamalyProcFonts, 0) == 0)
{
//---------------------------
// Found! Use MS Office font!
//---------------------------
_tcscpy (lf.lfFaceName, strOfficeFontName);
}
else
{
//-----------------------------
// Not found. Use default font:
//-----------------------------
_tcscpy (lf.lfFaceName, strDefaultFontName);
}
}
//--------------------------------------------
//////////////////////////////////////////////
fontRegular.CreateFontIndirect (&lf);
//------------------
// Create bold font:
//------------------
lf.lfWeight = FW_BOLD;
fontBold.CreateFontIndirect (&lf);
//----------------------
// Create vertical font:
//----------------------
CFont font;
if (font.CreateStockObject (DEFAULT_GUI_FONT))
{
if (font.GetLogFont (&lf) != 0)
{
lf.lfOrientation = 900;
lf.lfEscapement = 900;
//////////////////////////////////////////////
// Modify by Yuhu.Wang on 99/11/02
//--------------------------------------------
if(!fUseSystemFont)
{
//_tcscpy (lf.lfFaceName, _T("Arial"));
_tcscpy (lf.lfFaceName, strVertFontName);
}
//--------------------------------------------
//////////////////////////////////////////////
fontVert.CreateFontIndirect (&lf);
}
}
UpdateTextMetrics ();
//-----------------------
// Detect the kind of OS:
//-----------------------
OSVERSIONINFO osvi;
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
::GetVersionEx (&osvi);
bIsWindowsNT4 = ((osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) &&
(osvi.dwMajorVersion < 5));
}
//*******************************************************************************************
GLOBAL_DATA::~GLOBAL_DATA()
{
// cleanup standard brushes
AfxDeleteObject((HGDIOBJ*)&hbrBtnShadow);
AfxDeleteObject((HGDIOBJ*)&hbrBtnHilite);
// cleanup standard cursors
AfxDeleteObject ((HGDIOBJ*)&m_hcurStretch);
AfxDeleteObject ((HGDIOBJ*)&m_hcurStretchVert);
AfxDeleteObject ((HGDIOBJ*)&m_hcurHand);
}
//*******************************************************************************************
void GLOBAL_DATA::UpdateSysColors()
{
clrBtnFace = ::GetSysColor(COLOR_BTNFACE);
clrBtnShadow = ::GetSysColor(COLOR_BTNSHADOW);
clrBtnDkShadow = ::GetSysColor(COLOR_3DDKSHADOW);
clrBtnLight = ::GetSysColor(COLOR_3DLIGHT);
clrBtnHilite = ::GetSysColor(COLOR_BTNHIGHLIGHT);
clrBtnText = ::GetSysColor(COLOR_BTNTEXT);
clrGrayedText = ::GetSysColor (COLOR_GRAYTEXT);
clrWindowFrame = ::GetSysColor(COLOR_WINDOWFRAME);
clrHilite = ::GetSysColor(COLOR_HIGHLIGHT);
clrTextHilite = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
clrMenu = ::GetSysColor(COLOR_MENU);
clrMenuText = ::GetSysColor(COLOR_MENUTEXT);
AfxDeleteObject((HGDIOBJ*)&hbrBtnShadow);
AfxDeleteObject((HGDIOBJ*)&hbrBtnHilite);
hbrBtnShadow = ::CreateSolidBrush(clrBtnShadow);
ASSERT(hbrBtnShadow != NULL);
hbrBtnHilite = ::CreateSolidBrush(clrBtnHilite);
ASSERT(hbrBtnHilite != NULL);
brBtnFace.DeleteObject ();
brBtnFace.CreateSolidBrush (clrBtnFace);
brHilite.DeleteObject ();
brHilite.CreateSolidBrush (clrHilite);
}
//************************************************************************************
BOOL GLOBAL_DATA::SetMenuFont (LPLOGFONT lpLogFont, BOOL bHorz)
{
ASSERT (lpLogFont != NULL);
if (bHorz)
{
//---------------------
// Create regular font:
//---------------------
fontRegular.DeleteObject ();
if (!fontRegular.CreateFontIndirect (lpLogFont))
{
ASSERT (FALSE);
return FALSE;
}
//---------------------------------------------------
// Create bold font (used in the defaulr menu items):
//---------------------------------------------------
long lSavedWeight = lpLogFont->lfWeight;
lpLogFont->lfWeight = 700;
fontBold.DeleteObject ();
BOOL bResult = fontBold.CreateFontIndirect (lpLogFont);
lpLogFont->lfWeight = lSavedWeight; // Restore weight
if (!bResult)
{
ASSERT (FALSE);
return FALSE;
}
}
else // Vertical font
{
fontVert.DeleteObject ();
if (!fontVert.CreateFontIndirect (lpLogFont))
{
ASSERT (FALSE);
return FALSE;
}
}
UpdateTextMetrics ();
return TRUE;
}
//************************************************************************************
void GLOBAL_DATA::UpdateTextMetrics ()
{
CWindowDC dc (NULL);
CFont* pOldFont = dc.SelectObject (&fontRegular);
ASSERT (pOldFont != NULL);
TEXTMETRIC tm;
dc.GetTextMetrics (&tm);
m_nTextHeightHorz = tm.tmHeight + 2;
dc.SelectObject (&fontVert);
dc.GetTextMetrics (&tm);
m_nTextHeightVert = tm.tmHeight + 2;
dc.SelectObject (pOldFont);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -