home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / mfc / src / app3d.cpp < prev    next >
C/C++ Source or Header  |  1998-06-16  |  4KB  |  133 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.  
  13. #ifdef AFX_INIT_SEG
  14. #pragma code_seg(AFX_INIT_SEG)
  15. #endif
  16.  
  17. #ifdef _DEBUG
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21.  
  22. /////////////////////////////////////////////////////////////////////////////
  23. // _AFX_CTL3D_STATE
  24.  
  25. #ifndef _AFX_NO_CTL3D_SUPPORT
  26.  
  27. _AFX_CTL3D_STATE::~_AFX_CTL3D_STATE()
  28. {
  29.     if (m_pfnUnregister != NULL)
  30.         (*m_pfnUnregister)(NULL);
  31.  
  32.     if (m_hCtl3dLib != NULL)
  33.         ::FreeLibrary(m_hCtl3dLib);
  34. }
  35.  
  36. _AFX_CTL3D_THREAD::~_AFX_CTL3D_THREAD()
  37. {
  38.     _AFX_CTL3D_STATE* pCtl3dState = _afxCtl3dState.GetDataNA();
  39.     if (pCtl3dState != NULL && pCtl3dState->m_pfnUnAutoSubclass != NULL)
  40.         (*pCtl3dState->m_pfnUnAutoSubclass)();
  41. }
  42.  
  43. /////////////////////////////////////////////////////////////////////////////
  44. // Support for CTL3D32.DLL (3D controls DLL)
  45.  
  46. BOOL CWinApp::Enable3dControls()
  47. {
  48.     ASSERT(!afxContextIsDLL);   // Should only be called by apps
  49.  
  50.     // 3d controls and dialogs are automatic on newer versions of Windows
  51.     if (afxData.bWin4)
  52.         return TRUE;
  53.  
  54.     // otherwise, attempt to load CTL3D32.DLL
  55.     _AFX_CTL3D_STATE* pCtl3dState = _afxCtl3dState.GetData();
  56.     if (!pCtl3dState->m_bCtl3dInited)
  57.     {
  58.         pCtl3dState->m_hCtl3dLib = ::LoadLibraryA("CTL3D32.DLL");
  59.         if (pCtl3dState->m_hCtl3dLib != NULL)
  60.         {
  61.             // get address of Ctl3d functions
  62.             (FARPROC&)pCtl3dState->m_pfnRegister =
  63.                 GetProcAddress(pCtl3dState->m_hCtl3dLib, (LPCSTR)12);
  64.             (FARPROC&)pCtl3dState->m_pfnUnregister =
  65.                 GetProcAddress(pCtl3dState->m_hCtl3dLib, (LPCSTR)13);
  66.             (FARPROC&)pCtl3dState->m_pfnAutoSubclass =
  67.                 GetProcAddress(pCtl3dState->m_hCtl3dLib, (LPCSTR)16);
  68.             (FARPROC&)pCtl3dState->m_pfnUnAutoSubclass =
  69.                 GetProcAddress(pCtl3dState->m_hCtl3dLib, (LPCSTR)24);
  70.             (FARPROC&)pCtl3dState->m_pfnColorChange =
  71.                 GetProcAddress(pCtl3dState->m_hCtl3dLib, (LPCSTR)6);
  72.             (FARPROC&)pCtl3dState->m_pfnSubclassDlgEx =
  73.                 GetProcAddress(pCtl3dState->m_hCtl3dLib, (LPCSTR)21);
  74.             (FARPROC&)pCtl3dState->m_pfnWinIniChange =
  75.                 GetProcAddress(pCtl3dState->m_hCtl3dLib, (LPCSTR)22);
  76.             (FARPROC&)pCtl3dState->m_pfnSubclassCtl =
  77.                 GetProcAddress(pCtl3dState->m_hCtl3dLib, (LPCSTR)3);
  78.             (FARPROC&)pCtl3dState->m_pfnSubclassCtlEx =
  79.                 GetProcAddress(pCtl3dState->m_hCtl3dLib, (LPCSTR)25);
  80.         }
  81.  
  82.         // may be incorrect version -- check for errors
  83.         if (pCtl3dState->m_pfnRegister == NULL ||
  84.             pCtl3dState->m_pfnAutoSubclass == NULL ||
  85.             pCtl3dState->m_pfnColorChange == NULL ||
  86.             pCtl3dState->m_pfnSubclassDlgEx == NULL ||
  87.             pCtl3dState->m_pfnUnregister == NULL ||
  88.             !pCtl3dState->m_pfnRegister(AfxGetInstanceHandle()))
  89.         {
  90.             // don't want to be partially initialized
  91.             pCtl3dState->m_pfnRegister = NULL;
  92.             pCtl3dState->m_pfnUnregister = NULL;
  93.             pCtl3dState->m_pfnAutoSubclass = NULL;
  94.             pCtl3dState->m_pfnUnAutoSubclass = NULL;
  95.             pCtl3dState->m_pfnColorChange = NULL;
  96.             pCtl3dState->m_pfnSubclassDlgEx = NULL;
  97.             pCtl3dState->m_pfnWinIniChange = NULL;
  98.             pCtl3dState->m_pfnSubclassCtl = NULL;
  99.             pCtl3dState->m_pfnSubclassCtlEx = NULL;
  100.  
  101.             // only try once -- but return FALSE
  102.             if (pCtl3dState->m_hCtl3dLib != NULL)
  103.             {
  104.                 ::FreeLibrary(pCtl3dState->m_hCtl3dLib);
  105.                 pCtl3dState->m_hCtl3dLib = NULL;
  106.             }
  107.         }
  108.         pCtl3dState->m_bCtl3dInited = TRUE;
  109.     }
  110.  
  111.     // check that library was loaded and all entry-points were found
  112.     if (pCtl3dState->m_hCtl3dLib == NULL)
  113.         return FALSE;
  114.  
  115.     // turn on auto subclassing (for primary thread)
  116.     return (*pCtl3dState->m_pfnAutoSubclass)(AfxGetInstanceHandle());
  117. }
  118.  
  119. _AFX_CTL3D_STATE* AFXAPI AfxGetCtl3dState()
  120. {
  121.     return _afxCtl3dState.GetData();
  122. }
  123.  
  124. #pragma warning(disable: 4074)
  125. #pragma init_seg(lib)
  126.  
  127. THREAD_LOCAL(_AFX_CTL3D_THREAD, _afxCtl3dThread)
  128. PROCESS_LOCAL(_AFX_CTL3D_STATE, _afxCtl3dState)
  129.  
  130. #endif //!_AFX_NO_CTL3D_SUPPORT
  131.  
  132. /////////////////////////////////////////////////////////////////////////////
  133.