home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / advanced / oldbars / globals.cpp next >
Encoding:
C/C++ Source or Header  |  1998-03-27  |  3.9 KB  |  125 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10.  
  11. #include "stdafx.h"
  12. #include "globals.h"
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // Cached system metrics, etc
  16.  
  17. GLOBAL_DATA globalData;
  18.  
  19. // Initialization code
  20. GLOBAL_DATA::GLOBAL_DATA()
  21. {
  22.     // Cache various target platform version information
  23.     DWORD dwVersion = ::GetVersion();
  24.     nWinVer = (LOBYTE(dwVersion) << 8) + HIBYTE(dwVersion);
  25.     bWin32s = (dwVersion & 0x80000000) != 0;
  26.     bWin4 = (BYTE)dwVersion >= 4;
  27.     bNotWin4 = 1 - bWin4;   // for convenience
  28.     bSmCaption = bWin4;
  29.     bWin31 = bWin32s && !bWin4; // Windows 95 reports Win32s
  30.  
  31.     // Cached system metrics (updated in CWnd::OnWinIniChange)
  32.     UpdateSysMetrics();
  33.  
  34.     // Border attributes
  35.     hbrLtGray = ::CreateSolidBrush(RGB(192, 192, 192));
  36.     hbrDkGray = ::CreateSolidBrush(RGB(128, 128, 128));
  37.     ASSERT(hbrLtGray != NULL);
  38.     ASSERT(hbrDkGray != NULL);
  39.  
  40.     // Cached system values (updated in CWnd::OnSysColorChange)
  41.     hbrBtnFace = NULL;
  42.     hbrBtnShadow = NULL;
  43.     hbrBtnHilite = NULL;
  44.     hbrWindowFrame = NULL;
  45.     hpenBtnShadow = NULL;
  46.     hpenBtnHilite = NULL;
  47.     hpenBtnText = NULL;
  48.     UpdateSysColors();
  49.  
  50.     // cxBorder2 and cyBorder are 2x borders for Win4
  51.     cxBorder2 = bWin4 ? CX_BORDER*2 : CX_BORDER;
  52.     cyBorder2 = bWin4 ? CY_BORDER*2 : CY_BORDER;
  53.  
  54.     // allocated on demand
  55.     hStatusFont = NULL;
  56.     hToolTipsFont = NULL;
  57. }
  58.  
  59. // Termination code
  60. GLOBAL_DATA::~GLOBAL_DATA()
  61. {
  62.     // cleanup standard brushes
  63.     AfxDeleteObject((HGDIOBJ*)&hbrLtGray);
  64.     AfxDeleteObject((HGDIOBJ*)&hbrDkGray);
  65.     AfxDeleteObject((HGDIOBJ*)&hbrBtnFace);
  66.     AfxDeleteObject((HGDIOBJ*)&hbrBtnShadow);
  67.     AfxDeleteObject((HGDIOBJ*)&hbrBtnHilite);
  68.     AfxDeleteObject((HGDIOBJ*)&hbrWindowFrame);
  69.  
  70.     // cleanup standard pens
  71.     AfxDeleteObject((HGDIOBJ*)&hpenBtnShadow);
  72.     AfxDeleteObject((HGDIOBJ*)&hpenBtnHilite);
  73.     AfxDeleteObject((HGDIOBJ*)&hpenBtnText);
  74.  
  75.     // clean up objects we don't actually create
  76.     AfxDeleteObject((HGDIOBJ*)&hStatusFont);
  77.     AfxDeleteObject((HGDIOBJ*)&hToolTipsFont);
  78. }
  79.  
  80. void GLOBAL_DATA::UpdateSysColors()
  81. {
  82.     clrBtnFace = ::GetSysColor(COLOR_BTNFACE);
  83.     clrBtnShadow = ::GetSysColor(COLOR_BTNSHADOW);
  84.     clrBtnHilite = ::GetSysColor(COLOR_BTNHIGHLIGHT);
  85.     clrBtnText = ::GetSysColor(COLOR_BTNTEXT);
  86.     clrWindowFrame = ::GetSysColor(COLOR_WINDOWFRAME);
  87.  
  88.     AfxDeleteObject((HGDIOBJ*)&hbrBtnFace);
  89.     AfxDeleteObject((HGDIOBJ*)&hbrBtnShadow);
  90.     AfxDeleteObject((HGDIOBJ*)&hbrBtnHilite);
  91.     AfxDeleteObject((HGDIOBJ*)&hbrWindowFrame);
  92.  
  93.     hbrBtnFace = ::CreateSolidBrush(clrBtnFace);
  94.     ASSERT(hbrBtnFace != NULL);
  95.     hbrBtnShadow = ::CreateSolidBrush(clrBtnShadow);
  96.     ASSERT(hbrBtnShadow != NULL);
  97.     hbrBtnHilite = ::CreateSolidBrush(clrBtnHilite);
  98.     ASSERT(hbrBtnHilite != NULL);
  99.     hbrWindowFrame = ::CreateSolidBrush(clrWindowFrame);
  100.     ASSERT(hbrWindowFrame != NULL);
  101.  
  102.     AfxDeleteObject((HGDIOBJ*)&hpenBtnShadow);
  103.     AfxDeleteObject((HGDIOBJ*)&hpenBtnHilite);
  104.     AfxDeleteObject((HGDIOBJ*)&hpenBtnText);
  105.  
  106.     hpenBtnShadow = ::CreatePen(PS_SOLID, 0, clrBtnShadow);
  107.     ASSERT(hpenBtnShadow != NULL);
  108.     hpenBtnHilite = ::CreatePen(PS_SOLID, 0, clrBtnHilite);
  109.     ASSERT(hpenBtnHilite != NULL);
  110.     hpenBtnText = ::CreatePen(PS_SOLID, 0, clrBtnText);
  111.     ASSERT(hpenBtnText != NULL);
  112. }
  113.  
  114. void GLOBAL_DATA::UpdateSysMetrics()
  115. {
  116.     // Device metrics for screen
  117.     HDC hDCScreen = GetDC(NULL);
  118.     ASSERT(hDCScreen != NULL);
  119.     cxPixelsPerInch = GetDeviceCaps(hDCScreen, LOGPIXELSX);
  120.     cyPixelsPerInch = GetDeviceCaps(hDCScreen, LOGPIXELSY);
  121.     ReleaseDC(NULL, hDCScreen);
  122. }
  123.  
  124. /////////////////////////////////////////////////////////////////////////////
  125.