GLOBALS.CPP
资源名称:MSDN_VC98.zip [点击查看]
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:4k
源码类别:
Windows编程
开发平台:
Visual C++
- // 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 "globals.h"
- /////////////////////////////////////////////////////////////////////////////
- // Cached system metrics, etc
- GLOBAL_DATA globalData;
- // Initialization code
- GLOBAL_DATA::GLOBAL_DATA()
- {
- // Cache various target platform version information
- DWORD dwVersion = ::GetVersion();
- nWinVer = (LOBYTE(dwVersion) << 8) + HIBYTE(dwVersion);
- bWin32s = (dwVersion & 0x80000000) != 0;
- bWin4 = (BYTE)dwVersion >= 4;
- bNotWin4 = 1 - bWin4; // for convenience
- bSmCaption = bWin4;
- bWin31 = bWin32s && !bWin4; // Windows 95 reports Win32s
- // Cached system metrics (updated in CWnd::OnWinIniChange)
- UpdateSysMetrics();
- // Border attributes
- hbrLtGray = ::CreateSolidBrush(RGB(192, 192, 192));
- hbrDkGray = ::CreateSolidBrush(RGB(128, 128, 128));
- ASSERT(hbrLtGray != NULL);
- ASSERT(hbrDkGray != NULL);
- // Cached system values (updated in CWnd::OnSysColorChange)
- hbrBtnFace = NULL;
- hbrBtnShadow = NULL;
- hbrBtnHilite = NULL;
- hbrWindowFrame = NULL;
- hpenBtnShadow = NULL;
- hpenBtnHilite = NULL;
- hpenBtnText = NULL;
- UpdateSysColors();
- // cxBorder2 and cyBorder are 2x borders for Win4
- cxBorder2 = bWin4 ? CX_BORDER*2 : CX_BORDER;
- cyBorder2 = bWin4 ? CY_BORDER*2 : CY_BORDER;
- // allocated on demand
- hStatusFont = NULL;
- hToolTipsFont = NULL;
- }
- // Termination code
- GLOBAL_DATA::~GLOBAL_DATA()
- {
- // cleanup standard brushes
- AfxDeleteObject((HGDIOBJ*)&hbrLtGray);
- AfxDeleteObject((HGDIOBJ*)&hbrDkGray);
- AfxDeleteObject((HGDIOBJ*)&hbrBtnFace);
- AfxDeleteObject((HGDIOBJ*)&hbrBtnShadow);
- AfxDeleteObject((HGDIOBJ*)&hbrBtnHilite);
- AfxDeleteObject((HGDIOBJ*)&hbrWindowFrame);
- // cleanup standard pens
- AfxDeleteObject((HGDIOBJ*)&hpenBtnShadow);
- AfxDeleteObject((HGDIOBJ*)&hpenBtnHilite);
- AfxDeleteObject((HGDIOBJ*)&hpenBtnText);
- // clean up objects we don't actually create
- AfxDeleteObject((HGDIOBJ*)&hStatusFont);
- AfxDeleteObject((HGDIOBJ*)&hToolTipsFont);
- }
- void GLOBAL_DATA::UpdateSysColors()
- {
- clrBtnFace = ::GetSysColor(COLOR_BTNFACE);
- clrBtnShadow = ::GetSysColor(COLOR_BTNSHADOW);
- clrBtnHilite = ::GetSysColor(COLOR_BTNHIGHLIGHT);
- clrBtnText = ::GetSysColor(COLOR_BTNTEXT);
- clrWindowFrame = ::GetSysColor(COLOR_WINDOWFRAME);
- AfxDeleteObject((HGDIOBJ*)&hbrBtnFace);
- AfxDeleteObject((HGDIOBJ*)&hbrBtnShadow);
- AfxDeleteObject((HGDIOBJ*)&hbrBtnHilite);
- AfxDeleteObject((HGDIOBJ*)&hbrWindowFrame);
- hbrBtnFace = ::CreateSolidBrush(clrBtnFace);
- ASSERT(hbrBtnFace != NULL);
- hbrBtnShadow = ::CreateSolidBrush(clrBtnShadow);
- ASSERT(hbrBtnShadow != NULL);
- hbrBtnHilite = ::CreateSolidBrush(clrBtnHilite);
- ASSERT(hbrBtnHilite != NULL);
- hbrWindowFrame = ::CreateSolidBrush(clrWindowFrame);
- ASSERT(hbrWindowFrame != NULL);
- AfxDeleteObject((HGDIOBJ*)&hpenBtnShadow);
- AfxDeleteObject((HGDIOBJ*)&hpenBtnHilite);
- AfxDeleteObject((HGDIOBJ*)&hpenBtnText);
- hpenBtnShadow = ::CreatePen(PS_SOLID, 0, clrBtnShadow);
- ASSERT(hpenBtnShadow != NULL);
- hpenBtnHilite = ::CreatePen(PS_SOLID, 0, clrBtnHilite);
- ASSERT(hpenBtnHilite != NULL);
- hpenBtnText = ::CreatePen(PS_SOLID, 0, clrBtnText);
- ASSERT(hpenBtnText != NULL);
- }
- void GLOBAL_DATA::UpdateSysMetrics()
- {
- // Device metrics for screen
- HDC hDCScreen = GetDC(NULL);
- ASSERT(hDCScreen != NULL);
- cxPixelsPerInch = GetDeviceCaps(hDCScreen, LOGPIXELSX);
- cyPixelsPerInch = GetDeviceCaps(hDCScreen, LOGPIXELSY);
- ReleaseDC(NULL, hDCScreen);
- }
- /////////////////////////////////////////////////////////////////////////////