auxdata.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. #include "stdafx.h"
  11. #include <malloc.h>
  12. #ifdef AFX_INIT_SEG
  13. #pragma code_seg(AFX_INIT_SEG)
  14. #endif
  15. #ifdef _DEBUG
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19. #undef AfxEnableWin30Compatibility
  20. #undef AfxEnableWin40Compatibility
  21. #undef AfxEnableWin31Compatibility
  22. /////////////////////////////////////////////////////////////////////////////
  23. // Cached system metrics, etc
  24. AFX_DATADEF AUX_DATA afxData;
  25. // Win40 compatibility is now the default. It is not necessary to call
  26. // this if your application is marked as 4.0. It is provided only for
  27. // backward compatibility.
  28. void AFXAPI AfxEnableWin40Compatibility()
  29. {
  30. if (afxData.bWin4)
  31. {
  32. // Later versions of Windows report "correct" scrollbar metrics
  33. // MFC assumes the old metrics, so they need to be adjusted.
  34. afxData.cxVScroll = GetSystemMetrics(SM_CXVSCROLL) + CX_BORDER;
  35. afxData.cyHScroll = GetSystemMetrics(SM_CYHSCROLL) + CY_BORDER;
  36. afxData.bMarked4 = TRUE;
  37. }
  38. }
  39. // Call this API in your InitInstance if your application is marked
  40. // as a Windows 3.1 application.
  41. // This is done by linking with /subsystem:windows,3.1.
  42. void AFXAPI AfxEnableWin31Compatibility()
  43. {
  44. afxData.cxVScroll = GetSystemMetrics(SM_CXVSCROLL);
  45. afxData.cyHScroll = GetSystemMetrics(SM_CYHSCROLL);
  46. afxData.bMarked4 = FALSE;
  47. }
  48. // Initialization code
  49. AUX_DATA::AUX_DATA()
  50. {
  51. // Cache various target platform version information
  52. DWORD dwVersion = ::GetVersion();
  53. nWinVer = (LOBYTE(dwVersion) << 8) + HIBYTE(dwVersion);
  54. bWin95 = (dwVersion & 0x80000000) != 0;
  55. bWin4 = (BYTE)dwVersion >= 4;
  56. bNotWin4 = 1 - bWin4; // for convenience
  57. bSmCaption = bWin4;
  58. bMarked4 = FALSE;
  59. // determine various metrics based on EXE subsystem version mark
  60. if (bWin4)
  61. bMarked4 = (GetProcessVersion(0) >= 0x00040000);
  62. // Cached system metrics (updated in CWnd::OnWinIniChange)
  63. UpdateSysMetrics();
  64. // Cached system values (updated in CWnd::OnSysColorChange)
  65. hbrBtnFace = NULL;
  66. UpdateSysColors();
  67. // Standard cursors
  68. hcurWait = ::LoadCursor(NULL, IDC_WAIT);
  69. hcurArrow = ::LoadCursor(NULL, IDC_ARROW);
  70. ASSERT(hcurWait != NULL);
  71. ASSERT(hcurArrow != NULL);
  72. hcurHelp = NULL; // loaded on demand
  73. // cxBorder2 and cyBorder are 2x borders for Win4
  74. cxBorder2 = bWin4 ? CX_BORDER*2 : CX_BORDER;
  75. cyBorder2 = bWin4 ? CY_BORDER*2 : CY_BORDER;
  76. // allocated on demand
  77. hbmMenuDot = NULL;
  78. hcurHelp = NULL;
  79. }
  80. #ifdef AFX_TERM_SEG
  81. #pragma code_seg(AFX_TERM_SEG)
  82. #endif
  83. // Termination code
  84. AUX_DATA::~AUX_DATA()
  85. {
  86. // clean up objects we don't actually create
  87. AfxDeleteObject((HGDIOBJ*)&hbmMenuDot);
  88. }
  89. #ifdef AFX_CORE1_SEG
  90. #pragma code_seg(AFX_CORE1_SEG)
  91. #endif
  92. void AUX_DATA::UpdateSysColors()
  93. {
  94. clrBtnFace = ::GetSysColor(COLOR_BTNFACE);
  95. clrBtnShadow = ::GetSysColor(COLOR_BTNSHADOW);
  96. clrBtnHilite = ::GetSysColor(COLOR_BTNHIGHLIGHT);
  97. clrBtnText = ::GetSysColor(COLOR_BTNTEXT);
  98. clrWindowFrame = ::GetSysColor(COLOR_WINDOWFRAME);
  99. hbrBtnFace = ::GetSysColorBrush(COLOR_BTNFACE);
  100. ASSERT(hbrBtnFace != NULL);
  101. hbrWindowFrame = ::GetSysColorBrush(COLOR_WINDOWFRAME);
  102. ASSERT(hbrWindowFrame != NULL);
  103. }
  104. void AUX_DATA::UpdateSysMetrics()
  105. {
  106. // System metrics
  107. cxIcon = GetSystemMetrics(SM_CXICON);
  108. cyIcon = GetSystemMetrics(SM_CYICON);
  109. // System metrics which depend on subsystem version
  110. if (bMarked4)
  111. AfxEnableWin40Compatibility();
  112. else
  113. AfxEnableWin31Compatibility();
  114. // Device metrics for screen
  115. HDC hDCScreen = GetDC(NULL);
  116. ASSERT(hDCScreen != NULL);
  117. cxPixelsPerInch = GetDeviceCaps(hDCScreen, LOGPIXELSX);
  118. cyPixelsPerInch = GetDeviceCaps(hDCScreen, LOGPIXELSY);
  119. ReleaseDC(NULL, hDCScreen);
  120. }
  121. /////////////////////////////////////////////////////////////////////////////