home *** CD-ROM | disk | FTP | other *** search
/ Supercompiler 1997 / SUPERCOMPILER97.iso / MS_VC.50 / VC / MFC / SRC / AUXDATA.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-30  |  6.2 KB  |  230 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1997 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 <malloc.h>
  13. #ifdef _MAC
  14. #include <macname1.h>
  15. #include <Types.h>
  16. #include <macos\Windows.h>
  17. #include <macname2.h>
  18. #endif
  19.  
  20. #ifdef AFX_INIT_SEG
  21. #pragma code_seg(AFX_INIT_SEG)
  22. #endif
  23.  
  24. #ifdef _DEBUG
  25. #undef THIS_FILE
  26. static char THIS_FILE[] = __FILE__;
  27. #endif
  28.  
  29. #undef AfxEnableWin30Compatibility
  30. #undef AfxEnableWin40Compatibility
  31. #undef AfxEnableWin31Compatibility
  32.  
  33. /////////////////////////////////////////////////////////////////////////////
  34. // Cached system metrics, etc
  35.  
  36. AFX_DATADEF AUX_DATA afxData;
  37.  
  38. // Win40 compatibility is now the default.  It is not necessary to call
  39. // this if your application is marked as 4.0.  It is provided only for
  40. // backward compatibility.
  41. void AFXAPI AfxEnableWin40Compatibility()
  42. {
  43.     if (afxData.bWin4)
  44.     {
  45.         // Later versions of Windows report "correct" scrollbar metrics
  46.         // MFC assumes the old metrics, so they need to be adjusted.
  47.         afxData.cxVScroll = GetSystemMetrics(SM_CXVSCROLL) + CX_BORDER;
  48.         afxData.cyHScroll = GetSystemMetrics(SM_CYHSCROLL) + CY_BORDER;
  49.         afxData.bMarked4 = TRUE;
  50.     }
  51. }
  52.  
  53. // Call this API in your InitInstance if your application is marked
  54. // as a Windows 3.1 application.
  55. // This is done by linking with /subsystem:windows,3.1.
  56. void AFXAPI AfxEnableWin31Compatibility()
  57. {
  58.     afxData.cxVScroll = GetSystemMetrics(SM_CXVSCROLL);
  59.     afxData.cyHScroll = GetSystemMetrics(SM_CYHSCROLL);
  60.     afxData.bMarked4 = FALSE;
  61. }
  62.  
  63. // Initialization code
  64. AUX_DATA::AUX_DATA()
  65. {
  66.     // Cache various target platform version information
  67.     DWORD dwVersion = ::GetVersion();
  68.     nWinVer = (LOBYTE(dwVersion) << 8) + HIBYTE(dwVersion);
  69.     bWin32s = (dwVersion & 0x80000000) != 0;
  70.     bWin4 = (BYTE)dwVersion >= 4;
  71.     bNotWin4 = 1 - bWin4;   // for convenience
  72. #ifndef _MAC
  73.     bSmCaption = bWin4;
  74. #else
  75.     bSmCaption = TRUE;
  76.     bOleIgnoreSuspend = FALSE;
  77. #endif
  78.     bMarked4 = FALSE;
  79.  
  80. #ifndef _MAC
  81.     // determine various metrics based on EXE subsystem version mark
  82.     if (bWin4)
  83.         bMarked4 = (GetProcessVersion(0) >= 0x00040000);
  84. #endif
  85.  
  86.     // Cached system metrics (updated in CWnd::OnWinIniChange)
  87.     UpdateSysMetrics();
  88.  
  89.     // Cached system values (updated in CWnd::OnSysColorChange)
  90.     hbrBtnFace = NULL;
  91. #ifdef _MAC
  92.     hbr3DLight = NULL;
  93. #endif
  94.     UpdateSysColors();
  95.  
  96.     // Standard cursors
  97.     hcurWait = ::LoadCursor(NULL, IDC_WAIT);
  98.     hcurArrow = ::LoadCursor(NULL, IDC_ARROW);
  99.     ASSERT(hcurWait != NULL);
  100.     ASSERT(hcurArrow != NULL);
  101.     hcurHelp = NULL;    // loaded on demand
  102.  
  103.     // cxBorder2 and cyBorder are 2x borders for Win4
  104.     cxBorder2 = bWin4 ? CX_BORDER*2 : CX_BORDER;
  105.     cyBorder2 = bWin4 ? CY_BORDER*2 : CY_BORDER;
  106.  
  107.     // allocated on demand
  108.     hbmMenuDot = NULL;
  109.     hcurHelp = NULL;
  110. }
  111.  
  112. #ifdef AFX_TERM_SEG
  113. #pragma code_seg(AFX_TERM_SEG)
  114. #endif
  115.  
  116. // Termination code
  117. AUX_DATA::~AUX_DATA()
  118. {
  119.     // clean up objects we don't actually create
  120.     AfxDeleteObject((HGDIOBJ*)&hbmMenuDot);
  121. }
  122.  
  123. #ifdef AFX_CORE1_SEG
  124. #pragma code_seg(AFX_CORE1_SEG)
  125. #endif
  126.  
  127. void AUX_DATA::UpdateSysColors()
  128. {
  129.     clrBtnFace = ::GetSysColor(COLOR_BTNFACE);
  130.     clrBtnShadow = ::GetSysColor(COLOR_BTNSHADOW);
  131.     clrBtnHilite = ::GetSysColor(COLOR_BTNHIGHLIGHT);
  132.     clrBtnText = ::GetSysColor(COLOR_BTNTEXT);
  133.     clrWindowFrame = ::GetSysColor(COLOR_WINDOWFRAME);
  134. #ifdef _MAC
  135.     clr3DLight = ::GetSysColor(COLOR_3DLIGHT);
  136. #endif
  137.  
  138.     hbrBtnFace = ::GetSysColorBrush(COLOR_BTNFACE);
  139.     ASSERT(hbrBtnFace != NULL);
  140.     hbrWindowFrame = ::GetSysColorBrush(COLOR_WINDOWFRAME);
  141.     ASSERT(hbrWindowFrame != NULL);
  142. #ifdef _MAC
  143.     hbr3DLight = ::GetSysColorBrush(COLOR_3DLIGHT);
  144.     ASSERT(hbr3DLight != NULL);
  145. #endif
  146. }
  147.  
  148. void AUX_DATA::UpdateSysMetrics()
  149. {
  150.     // System metrics
  151.     cxIcon = GetSystemMetrics(SM_CXICON);
  152.     cyIcon = GetSystemMetrics(SM_CYICON);
  153.  
  154.     // System metrics which depend on subsystem version
  155.     if (bMarked4)
  156.         AfxEnableWin40Compatibility();
  157.     else
  158.         AfxEnableWin31Compatibility();
  159.  
  160.     // Device metrics for screen
  161.     HDC hDCScreen = GetDC(NULL);
  162.     ASSERT(hDCScreen != NULL);
  163.     cxPixelsPerInch = GetDeviceCaps(hDCScreen, LOGPIXELSX);
  164.     cyPixelsPerInch = GetDeviceCaps(hDCScreen, LOGPIXELSY);
  165.     ReleaseDC(NULL, hDCScreen);
  166. }
  167.  
  168. /////////////////////////////////////////////////////////////////////////////
  169. // DLL loading helpers
  170.  
  171. #ifdef _AFXDLL
  172.  
  173. HINSTANCE AFXAPI AfxLoadDll(HINSTANCE* volatile pInst, LPCSTR lpszDLL,
  174.     FARPROC* pProcPtrs, LPCSTR lpszProcName)
  175. {
  176.     // we test hInst for NULL twice
  177.     // if hInst == NULL we need to enter a critical section to set it
  178.     // however, after entering the critical section, we should test it again
  179.     // because it could change from NULL to non-NULL in that time.
  180.     // if hInst != NULL initially (usually true), we save several function
  181.     // calls as well as entering/leaving a critical section.
  182.     if (*pInst == NULL)
  183.     {
  184.         AfxLockGlobals(CRIT_DYNDLLLOAD);
  185.         if (*pInst == NULL)
  186.         {
  187. #ifndef _MAC
  188.             *pInst = LoadLibraryA(lpszDLL);
  189. #else
  190.             *pInst = LoadLibraryEx(lpszDLL, NULL, LOAD_BY_FRAGMENT_NAME);
  191. #endif
  192.             ASSERT(*pInst != NULL);
  193.         }
  194.         AfxUnlockGlobals(CRIT_DYNDLLLOAD);
  195.         if (*pInst == NULL)
  196.         {
  197.             TRACE1("Error: Unable to load DLL '%hs'!\n", lpszDLL);
  198.  
  199.             CString strError, strFormatted;
  200.             VERIFY(strError.LoadString(AFX_IDP_DLL_LOAD_FAILED));
  201.             strFormatted.Format(strError, lpszDLL);
  202.             AfxMessageBox(strFormatted, MB_ICONEXCLAMATION);
  203.             AfxThrowMemoryException();
  204.         }
  205.     }
  206.  
  207.     if (pProcPtrs != NULL)
  208.     {
  209.         *pProcPtrs = GetProcAddress(*pInst, lpszProcName);
  210.         if (pProcPtrs == NULL)
  211.         {
  212.             CString strError, strFormatted;
  213.             VERIFY(strError.LoadString(AFX_IDP_DLL_BAD_VERSION));
  214.             strFormatted.Format(strError, lpszProcName, lpszDLL, lpszDLL);
  215.             AfxMessageBox(strFormatted, MB_ICONEXCLAMATION);
  216.         }
  217.         ASSERT(*pProcPtrs != NULL);
  218.     }
  219.     return *pInst;
  220. }
  221.  
  222. HINSTANCE AFXAPI AfxLoadDll(HINSTANCE* volatile pInst, LPCSTR lpszDLL)
  223. {
  224.     return AfxLoadDll(pInst, lpszDLL, NULL, NULL);
  225. }
  226.  
  227. #endif
  228.  
  229. /////////////////////////////////////////////////////////////////////////////
  230.