afxstat_.h 10 KB

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