home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / mfc / src / appterm.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-16  |  2.2 KB  |  76 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 <ddeml.h> // for MSGF_DDEMGR
  13.  
  14. #ifdef AFX_TERM_SEG
  15. #pragma code_seg(AFX_TERM_SEG)
  16. #endif
  17.  
  18. #ifdef _DEBUG
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22.  
  23. /////////////////////////////////////////////////////////////////////////////
  24. // other globals (internal library use)
  25.  
  26. /////////////////////////////////////////////////////////////////////////////
  27. // Standard cleanup called by WinMain and AfxAbort
  28.  
  29. void AFXAPI AfxWinTerm(void)
  30. {
  31.     // unregister Window classes
  32.     AFX_MODULE_STATE* pModuleState = AfxGetModuleState();
  33.     AfxLockGlobals(CRIT_REGCLASSLIST);
  34.     LPTSTR lpsz = pModuleState->m_szUnregisterList;
  35.     while (*lpsz != 0)
  36.     {
  37.         LPTSTR lpszEnd = _tcschr(lpsz, '\n');
  38.         ASSERT(lpszEnd != NULL);
  39.         *lpszEnd = 0;
  40.         UnregisterClass(lpsz, AfxGetInstanceHandle());
  41.         lpsz = lpszEnd + 1;
  42.     }
  43.     pModuleState->m_szUnregisterList[0] = 0;
  44.     AfxUnlockGlobals(CRIT_REGCLASSLIST);
  45.  
  46.     // cleanup OLE if required
  47.     CWinThread* pThread = AfxGetApp();
  48.     if (pThread != NULL && pThread->m_lpfnOleTermOrFreeLib != NULL)
  49.         (*pThread->m_lpfnOleTermOrFreeLib)(TRUE, FALSE);
  50.  
  51.     // cleanup thread local tooltip window
  52.     _AFX_THREAD_STATE* pThreadState = AfxGetThreadState();
  53.     if (pThreadState->m_pToolTip != NULL)
  54.     {
  55.         if (pThreadState->m_pToolTip->DestroyToolTipCtrl())
  56.             pThreadState->m_pToolTip = NULL;
  57.     }
  58.  
  59.     if (!afxContextIsDLL)
  60.     {
  61.         // unhook windows hooks
  62.         if (pThreadState->m_hHookOldMsgFilter != NULL)
  63.         {
  64.             ::UnhookWindowsHookEx(pThreadState->m_hHookOldMsgFilter);
  65.             pThreadState->m_hHookOldMsgFilter = NULL;
  66.         }
  67.         if (pThreadState->m_hHookOldCbtFilter != NULL)
  68.         {
  69.             ::UnhookWindowsHookEx(pThreadState->m_hHookOldCbtFilter);
  70.             pThreadState->m_hHookOldCbtFilter = NULL;
  71.         }
  72.     }
  73. }
  74.  
  75. /////////////////////////////////////////////////////////////////////////////
  76.