home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / mfc / include / afxstat_.h < prev    next >
C/C++ Source or Header  |  1998-06-16  |  10KB  |  396 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. #ifndef __AFXSTATE_H__
  12. #define __AFXSTATE_H__
  13.  
  14. #ifdef _AFX_PACKING
  15. #pragma pack(push, _AFX_PACKING)
  16. #endif
  17.  
  18. #ifndef __AFXTLS_H__
  19.     #include <afxtls_.h>
  20. #endif
  21.  
  22. #undef AFX_DATA
  23. #define AFX_DATA AFX_CORE_DATA
  24.  
  25. /////////////////////////////////////////////////////////////////////////////
  26. // _AFX_DEBUG_STATE
  27.  
  28. #ifdef _DEBUG
  29.  
  30. class _AFX_DEBUG_STATE : public CNoTrackObject
  31. {
  32. public:
  33.     _AFX_DEBUG_STATE();
  34.     virtual ~_AFX_DEBUG_STATE();
  35. };
  36.  
  37. EXTERN_PROCESS_LOCAL(_AFX_DEBUG_STATE, afxDebugState)
  38.  
  39. #endif //_DEBUG
  40.  
  41. /////////////////////////////////////////////////////////////////////////////
  42. // _AFX_WIN_STATE
  43.  
  44. #undef AFX_DATA
  45. #define AFX_DATA
  46.  
  47. class _AFX_WIN_STATE : public CNoTrackObject
  48. {
  49. #ifndef _AFX_NO_GRAYDLG_SUPPORT
  50. public:
  51.     _AFX_WIN_STATE();
  52.     virtual ~_AFX_WIN_STATE();
  53.  
  54.     // gray dialog support
  55.     HBRUSH m_hDlgBkBrush; // dialog and message box background brush
  56.     COLORREF m_crDlgTextClr;
  57. #endif //!_AFX_NO_GRAYDLG_SUPPORT
  58.  
  59. public:
  60.     // printing abort
  61.     BOOL m_bUserAbort;
  62. };
  63.  
  64. EXTERN_PROCESS_LOCAL(_AFX_WIN_STATE, _afxWinState)
  65.  
  66. /////////////////////////////////////////////////////////////////////////////
  67. // Type library cache - AFX_INTERNAL
  68.  
  69. #ifndef _AFX_NO_OLE_SUPPORT
  70.  
  71. struct ITypeInfo;
  72. typedef ITypeInfo* LPTYPEINFO;
  73.  
  74. struct ITypeLib;
  75. typedef ITypeLib* LPTYPELIB;
  76.  
  77. typedef struct _GUID GUID;
  78. #ifndef _REFCLSID_DEFINED
  79. #define REFGUID const GUID &
  80. #endif
  81.  
  82. class CTypeLibCache
  83. {
  84. public:
  85.     CTypeLibCache() : m_cRef(0), m_lcid((LCID)-1), m_ptlib(NULL), m_ptinfo(NULL) {}
  86.     void Lock();
  87.     void Unlock();
  88.     BOOL Lookup(LCID lcid, LPTYPELIB* pptlib);
  89.     void Cache(LCID lcid, LPTYPELIB ptlib);
  90.     BOOL LookupTypeInfo(LCID lcid, REFGUID guid, LPTYPEINFO* pptinfo);
  91.     void CacheTypeInfo(LCID lcid, REFGUID guid, LPTYPEINFO ptinfo);
  92.     const GUID* m_pTypeLibID;
  93.  
  94. protected:
  95.     LCID m_lcid;
  96.     LPTYPELIB m_ptlib;
  97.     GUID m_guidInfo;
  98.     LPTYPEINFO m_ptinfo;
  99.     long m_cRef;
  100. };
  101.  
  102. #endif //!_AFX_NO_OLE_SUPPORT
  103.  
  104. /////////////////////////////////////////////////////////////////////////////
  105. // AFX_MODULE_STATE : portion of state that is pushed/popped
  106.  
  107. // forward references required for AFX_MODULE_THREAD_STATE definition
  108. class CWinThread;
  109. class CHandleMap;
  110. class CFrameWnd;
  111.  
  112. #ifndef _PNH_DEFINED
  113. typedef int (__cdecl * _PNH)( size_t );
  114. #define _PNH_DEFINED
  115. #endif
  116.  
  117. template<class TYPE>
  118. class CEmbeddedButActsLikePtr
  119. {
  120. public:
  121.     AFX_INLINE TYPE* operator->() { return &m_data; }
  122.     AFX_INLINE operator TYPE*() { return &m_data; }
  123.     TYPE m_data;
  124. };
  125.  
  126. // AFX_MODULE_THREAD_STATE (local to thread *and* module)
  127. class AFX_MODULE_THREAD_STATE : public CNoTrackObject
  128. {
  129. public:
  130.     AFX_MODULE_THREAD_STATE();
  131.     virtual ~AFX_MODULE_THREAD_STATE();
  132.  
  133.     // current CWinThread pointer
  134.     CWinThread* m_pCurrentWinThread;
  135.  
  136.     // list of CFrameWnd objects for thread
  137.     CTypedSimpleList<CFrameWnd*> m_frameList;
  138.  
  139.     // temporary/permanent map state
  140.     DWORD m_nTempMapLock;           // if not 0, temp maps locked
  141.     CHandleMap* m_pmapHWND;
  142.     CHandleMap* m_pmapHMENU;
  143.     CHandleMap* m_pmapHDC;
  144.     CHandleMap* m_pmapHGDIOBJ;
  145.     CHandleMap* m_pmapHIMAGELIST;
  146.  
  147.     // thread-local MFC new handler (separate from C-runtime)
  148.     _PNH m_pfnNewHandler;
  149.  
  150. #ifndef _AFX_NO_SOCKET_SUPPORT
  151.     // WinSock specific thread state
  152.     HWND m_hSocketWindow;
  153. #ifdef _AFXDLL
  154.     CEmbeddedButActsLikePtr<CMapPtrToPtr> m_pmapSocketHandle;
  155.     CEmbeddedButActsLikePtr<CMapPtrToPtr> m_pmapDeadSockets;
  156.     CEmbeddedButActsLikePtr<CPtrList> m_plistSocketNotifications;
  157. #else
  158.     CMapPtrToPtr* m_pmapSocketHandle;
  159.     CMapPtrToPtr* m_pmapDeadSockets;
  160.     CPtrList* m_plistSocketNotifications;
  161. #endif
  162. #endif
  163. };
  164.  
  165. // forward references required for AFX_MODULE_STATE definition
  166. class CWinApp;
  167. class COleObjectFactory;
  168.  
  169. class CWnd;
  170.  
  171. #ifdef _AFXDLL
  172. class CDynLinkLibrary;
  173. #endif
  174.  
  175. #ifndef _AFX_NO_OCC_SUPPORT
  176. class COccManager;
  177. class COleControlLock;
  178. #endif
  179.  
  180. #ifndef _AFX_NO_DAO_SUPPORT
  181. class _AFX_DAO_STATE;
  182. #endif
  183.  
  184. class CTypeLibCacheMap : public CMapPtrToPtr
  185. {
  186. public:
  187.     virtual void RemoveAll(void* pExcept);
  188. };
  189.  
  190. // AFX_MODULE_STATE (global data for a module)
  191. class AFX_MODULE_STATE : public CNoTrackObject
  192. {
  193. public:
  194. #ifdef _AFXDLL
  195.     AFX_MODULE_STATE(BOOL bDLL, WNDPROC pfnAfxWndProc, DWORD dwVersion);
  196.     AFX_MODULE_STATE(BOOL bDLL, WNDPROC pfnAfxWndProc, DWORD dwVersion,
  197.         BOOL bSystem);
  198. #else
  199.     AFX_MODULE_STATE(BOOL bDLL);
  200. #endif
  201.     ~AFX_MODULE_STATE();
  202.  
  203.     CWinApp* m_pCurrentWinApp;
  204.     HINSTANCE m_hCurrentInstanceHandle;
  205.     HINSTANCE m_hCurrentResourceHandle;
  206.     LPCTSTR m_lpszCurrentAppName;
  207.     BYTE m_bDLL;    // TRUE if module is a DLL, FALSE if it is an EXE
  208.     BYTE m_bSystem; // TRUE if module is a "system" module, FALSE if not
  209.     BYTE m_bReserved[2]; // padding
  210.  
  211.     DWORD m_fRegisteredClasses; // flags for registered window classes
  212.  
  213.     // runtime class data
  214. #ifdef _AFXDLL
  215.     CRuntimeClass* m_pClassInit;
  216. #endif
  217.     CTypedSimpleList<CRuntimeClass*> m_classList;
  218.  
  219.     // OLE object factories
  220. #ifndef _AFX_NO_OLE_SUPPORT
  221. #ifdef _AFXDLL
  222.     COleObjectFactory* m_pFactoryInit;
  223. #endif
  224.     CTypedSimpleList<COleObjectFactory*> m_factoryList;
  225. #endif
  226.     // number of locked OLE objects
  227.     long m_nObjectCount;
  228.     BOOL m_bUserCtrl;
  229.  
  230.     // AfxRegisterClass and AfxRegisterWndClass data
  231.     TCHAR m_szUnregisterList[4096];
  232. #ifdef _AFXDLL
  233.     WNDPROC m_pfnAfxWndProc;
  234.     DWORD m_dwVersion;  // version that module linked against
  235. #endif
  236.  
  237.     // variables related to a given process in a module
  238.     //  (used to be AFX_MODULE_PROCESS_STATE)
  239. #ifdef _AFX_OLD_EXCEPTIONS
  240.     // exceptions
  241.     AFX_TERM_PROC m_pfnTerminate;
  242. #endif
  243.     void (PASCAL *m_pfnFilterToolTipMessage)(MSG*, CWnd*);
  244.  
  245. #ifdef _AFXDLL
  246.     // CDynLinkLibrary objects (for resource chain)
  247.     CTypedSimpleList<CDynLinkLibrary*> m_libraryList;
  248.  
  249.     // special case for MFCxxLOC.DLL (localized MFC resources)
  250.     HINSTANCE m_appLangDLL;
  251. #endif
  252.  
  253. #ifndef _AFX_NO_OCC_SUPPORT
  254.     // OLE control container manager
  255.     COccManager* m_pOccManager;
  256.     // locked OLE controls
  257.     CTypedSimpleList<COleControlLock*> m_lockList;
  258. #endif
  259.  
  260. #ifndef _AFX_NO_DAO_SUPPORT
  261.     _AFX_DAO_STATE* m_pDaoState;
  262. #endif
  263.  
  264. #ifndef _AFX_NO_OLE_SUPPORT
  265.     // Type library caches
  266.     CTypeLibCache m_typeLibCache;
  267.     CTypeLibCacheMap* m_pTypeLibCacheMap;
  268. #endif
  269.  
  270.     // define thread local portions of module state
  271.     THREAD_LOCAL(AFX_MODULE_THREAD_STATE, m_thread)
  272. };
  273.  
  274. AFX_MODULE_STATE* AFXAPI AfxGetAppModuleState();
  275. #ifdef _AFXDLL
  276. AFX_MODULE_STATE* AFXAPI AfxSetModuleState(AFX_MODULE_STATE* pNewState);
  277. #endif
  278. AFX_MODULE_STATE* AFXAPI AfxGetModuleState();
  279. AFX_MODULE_STATE* AFXAPI AfxGetStaticModuleState();
  280.  
  281. AFX_MODULE_THREAD_STATE* AFXAPI AfxGetModuleThreadState();
  282.  
  283. #ifdef _AFXDLL
  284. #define _AFX_CMDTARGET_GETSTATE() (m_pModuleState)
  285. #else
  286. #define _AFX_CMDTARGET_GETSTATE() (AfxGetModuleState())
  287. #endif
  288.  
  289. /////////////////////////////////////////////////////////////////////////////
  290. // macros & classes to manage pushing/popping the module state
  291.  
  292. #ifdef _AFXDLL
  293. struct AFX_MAINTAIN_STATE
  294. {
  295.     AFX_MAINTAIN_STATE(AFX_MODULE_STATE* pModuleState);
  296.     ~AFX_MAINTAIN_STATE();
  297.  
  298. protected:
  299.     AFX_MODULE_STATE* m_pPrevModuleState;
  300. };
  301.  
  302. class _AFX_THREAD_STATE;
  303. struct AFX_MAINTAIN_STATE2
  304. {
  305.     AFX_MAINTAIN_STATE2(AFX_MODULE_STATE* pModuleState);
  306.     ~AFX_MAINTAIN_STATE2();
  307.  
  308. protected:
  309.     AFX_MODULE_STATE* m_pPrevModuleState;
  310.     _AFX_THREAD_STATE* m_pThreadState;
  311. };
  312. #define AFX_MANAGE_STATE(p) AFX_MAINTAIN_STATE2 _ctlState(p);
  313. #else  // _AFXDLL
  314. #define AFX_MANAGE_STATE(p)
  315. #endif //!_AFXDLL
  316.  
  317. /////////////////////////////////////////////////////////////////////////////
  318. // Thread global state
  319.  
  320. // forward references required for _AFX_THREAD_STATE definition
  321. class CView;
  322. class CToolTipCtrl;
  323. class CControlBar;
  324.  
  325. class _AFX_THREAD_STATE : public CNoTrackObject
  326. {
  327. public:
  328.     _AFX_THREAD_STATE();
  329.     virtual ~_AFX_THREAD_STATE();
  330.  
  331.     // override for m_pModuleState in _AFX_APP_STATE
  332.     AFX_MODULE_STATE* m_pModuleState;
  333.     AFX_MODULE_STATE* m_pPrevModuleState;
  334.  
  335.     // memory safety pool for temp maps
  336.     void* m_pSafetyPoolBuffer;    // current buffer
  337.  
  338.     // thread local exception context
  339.     AFX_EXCEPTION_CONTEXT m_exceptionContext;
  340.  
  341.     // CWnd create, gray dialog hook, and other hook data
  342.     CWnd* m_pWndInit;
  343.     CWnd* m_pAlternateWndInit;      // special case commdlg hooking
  344.     DWORD m_dwPropStyle;
  345.     DWORD m_dwPropExStyle;
  346.     HWND m_hWndInit;
  347.     BOOL m_bDlgCreate;
  348.     HHOOK m_hHookOldCbtFilter;
  349.     HHOOK m_hHookOldMsgFilter;
  350.  
  351.     // other CWnd modal data
  352.     MSG m_lastSentMsg;              // see CWnd::WindowProc
  353.     HWND m_hTrackingWindow;         // see CWnd::TrackPopupMenu
  354.     HMENU m_hTrackingMenu;
  355.     TCHAR m_szTempClassName[96];    // see AfxRegisterWndClass
  356.     HWND m_hLockoutNotifyWindow;    // see CWnd::OnCommand
  357.     BOOL m_bInMsgFilter;
  358.  
  359.     // other framework modal data
  360.     CView* m_pRoutingView;          // see CCmdTarget::GetRoutingView
  361.     CFrameWnd* m_pRoutingFrame;     // see CCmdTarget::GetRoutingFrame
  362.  
  363.     // MFC/DB thread-local data
  364.     BOOL m_bWaitForDataSource;
  365.  
  366.     // common controls thread state
  367.     CToolTipCtrl* m_pToolTip;
  368.     CWnd* m_pLastHit;       // last window to own tooltip
  369.     int m_nLastHit;         // last hittest code
  370.     TOOLINFO m_lastInfo;    // last TOOLINFO structure
  371.     int m_nLastStatus;      // last flyby status message
  372.     CControlBar* m_pLastStatus; // last flyby status control bar
  373.  
  374.     // OLE control thread-local data
  375.     CWnd* m_pWndPark;       // "parking space" window
  376.     long m_nCtrlRef;        // reference count on parking window
  377.     BOOL m_bNeedTerm;       // TRUE if OleUninitialize needs to be called
  378. };
  379.  
  380. EXTERN_THREAD_LOCAL(_AFX_THREAD_STATE, _afxThreadState)
  381.  
  382. _AFX_THREAD_STATE* AFXAPI AfxGetThreadState();
  383.  
  384. /////////////////////////////////////////////////////////////////////////////
  385.  
  386. #ifdef _AFX_PACKING
  387. #pragma pack(pop)
  388. #endif
  389.  
  390. #undef AFX_DATA
  391. #define AFX_DATA
  392.  
  393. #endif //__AFXSTATE_H__
  394.  
  395. /////////////////////////////////////////////////////////////////////////////
  396.