home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / OLDBARS.PAK / GLOBALS.CPP next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  3.9 KB  |  129 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1995 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. #ifndef _MAC
  29.     bSmCaption = bWin4;
  30. #else
  31.     bSmCaption = TRUE;
  32. #endif
  33.     bWin31 = bWin32s && !bWin4; // Windows 95 reports Win32s
  34.  
  35.     // Cached system metrics (updated in CWnd::OnWinIniChange)
  36.     UpdateSysMetrics();
  37.  
  38.     // Border attributes
  39.     hbrLtGray = ::CreateSolidBrush(RGB(192, 192, 192));
  40.     hbrDkGray = ::CreateSolidBrush(RGB(128, 128, 128));
  41.     ASSERT(hbrLtGray != NULL);
  42.     ASSERT(hbrDkGray != NULL);
  43.  
  44.     // Cached system values (updated in CWnd::OnSysColorChange)
  45.     hbrBtnFace = NULL;
  46.     hbrBtnShadow = NULL;
  47.     hbrBtnHilite = NULL;
  48.     hbrWindowFrame = NULL;
  49.     hpenBtnShadow = NULL;
  50.     hpenBtnHilite = NULL;
  51.     hpenBtnText = NULL;
  52.     UpdateSysColors();
  53.  
  54.     // cxBorder2 and cyBorder are 2x borders for Win4
  55.     cxBorder2 = bWin4 ? CX_BORDER*2 : CX_BORDER;
  56.     cyBorder2 = bWin4 ? CY_BORDER*2 : CY_BORDER;
  57.  
  58.     // allocated on demand
  59.     hStatusFont = NULL;
  60.     hToolTipsFont = NULL;
  61. }
  62.  
  63. // Termination code
  64. GLOBAL_DATA::~GLOBAL_DATA()
  65. {
  66.     // cleanup standard brushes
  67.     AfxDeleteObject((HGDIOBJ*)&hbrLtGray);
  68.     AfxDeleteObject((HGDIOBJ*)&hbrDkGray);
  69.     AfxDeleteObject((HGDIOBJ*)&hbrBtnFace);
  70.     AfxDeleteObject((HGDIOBJ*)&hbrBtnShadow);
  71.     AfxDeleteObject((HGDIOBJ*)&hbrBtnHilite);
  72.     AfxDeleteObject((HGDIOBJ*)&hbrWindowFrame);
  73.  
  74.     // cleanup standard pens
  75.     AfxDeleteObject((HGDIOBJ*)&hpenBtnShadow);
  76.     AfxDeleteObject((HGDIOBJ*)&hpenBtnHilite);
  77.     AfxDeleteObject((HGDIOBJ*)&hpenBtnText);
  78.  
  79.     // clean up objects we don't actually create
  80.     AfxDeleteObject((HGDIOBJ*)&hStatusFont);
  81.     AfxDeleteObject((HGDIOBJ*)&hToolTipsFont);
  82. }
  83.  
  84. void GLOBAL_DATA::UpdateSysColors()
  85. {
  86.     clrBtnFace = ::GetSysColor(COLOR_BTNFACE);
  87.     clrBtnShadow = ::GetSysColor(COLOR_BTNSHADOW);
  88.     clrBtnHilite = ::GetSysColor(COLOR_BTNHIGHLIGHT);
  89.     clrBtnText = ::GetSysColor(COLOR_BTNTEXT);
  90.     clrWindowFrame = ::GetSysColor(COLOR_WINDOWFRAME);
  91.  
  92.     AfxDeleteObject((HGDIOBJ*)&hbrBtnFace);
  93.     AfxDeleteObject((HGDIOBJ*)&hbrBtnShadow);
  94.     AfxDeleteObject((HGDIOBJ*)&hbrBtnHilite);
  95.     AfxDeleteObject((HGDIOBJ*)&hbrWindowFrame);
  96.  
  97.     hbrBtnFace = ::CreateSolidBrush(clrBtnFace);
  98.     ASSERT(hbrBtnFace != NULL);
  99.     hbrBtnShadow = ::CreateSolidBrush(clrBtnShadow);
  100.     ASSERT(hbrBtnShadow != NULL);
  101.     hbrBtnHilite = ::CreateSolidBrush(clrBtnHilite);
  102.     ASSERT(hbrBtnHilite != NULL);
  103.     hbrWindowFrame = ::CreateSolidBrush(clrWindowFrame);
  104.     ASSERT(hbrWindowFrame != NULL);
  105.  
  106.     AfxDeleteObject((HGDIOBJ*)&hpenBtnShadow);
  107.     AfxDeleteObject((HGDIOBJ*)&hpenBtnHilite);
  108.     AfxDeleteObject((HGDIOBJ*)&hpenBtnText);
  109.  
  110.     hpenBtnShadow = ::CreatePen(PS_SOLID, 0, clrBtnShadow);
  111.     ASSERT(hpenBtnShadow != NULL);
  112.     hpenBtnHilite = ::CreatePen(PS_SOLID, 0, clrBtnHilite);
  113.     ASSERT(hpenBtnHilite != NULL);
  114.     hpenBtnText = ::CreatePen(PS_SOLID, 0, clrBtnText);
  115.     ASSERT(hpenBtnText != NULL);
  116. }
  117.  
  118. void GLOBAL_DATA::UpdateSysMetrics()
  119. {
  120.     // Device metrics for screen
  121.     HDC hDCScreen = GetDC(NULL);
  122.     ASSERT(hDCScreen != NULL);
  123.     cxPixelsPerInch = GetDeviceCaps(hDCScreen, LOGPIXELSX);
  124.     cyPixelsPerInch = GetDeviceCaps(hDCScreen, LOGPIXELSY);
  125.     ReleaseDC(NULL, hDCScreen);
  126. }
  127.  
  128. /////////////////////////////////////////////////////////////////////////////
  129.