Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

421 lines
10 KiB

  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. #if _MFC_VER >= 0x0600
  91. template<class TYPE>
  92. class CEmbeddedButActsLikePtr
  93. {
  94. public:
  95. AFX_INLINE TYPE* operator->() { return &m_data; }
  96. AFX_INLINE operator TYPE*() { return &m_data; }
  97. TYPE m_data;
  98. };
  99. #endif
  100. // AFX_MODULE_THREAD_STATE (local to thread *and* module)
  101. class AFX_MODULE_THREAD_STATE : public CNoTrackObject
  102. {
  103. public:
  104. AFX_MODULE_THREAD_STATE();
  105. virtual ~AFX_MODULE_THREAD_STATE();
  106. // current CWinThread pointer
  107. CWinThread* m_pCurrentWinThread;
  108. // list of CFrameWnd objects for thread
  109. CTypedSimpleList<CFrameWnd*> m_frameList;
  110. // temporary/permanent map state
  111. DWORD m_nTempMapLock; // if not 0, temp maps locked
  112. CHandleMap* m_pmapHWND;
  113. CHandleMap* m_pmapHMENU;
  114. CHandleMap* m_pmapHDC;
  115. CHandleMap* m_pmapHGDIOBJ;
  116. CHandleMap* m_pmapHIMAGELIST;
  117. // thread-local MFC new handler (separate from C-runtime)
  118. _PNH m_pfnNewHandler;
  119. #ifndef _AFX_NO_SOCKET_SUPPORT
  120. // WinSock specific thread state
  121. HWND m_hSocketWindow;
  122. #if _MFC_VER >= 0x0600
  123. #ifdef _AFXDLL
  124. CEmbeddedButActsLikePtr<CMapPtrToPtr> m_pmapSocketHandle;
  125. CEmbeddedButActsLikePtr<CMapPtrToPtr> m_pmapDeadSockets;
  126. CEmbeddedButActsLikePtr<CPtrList> m_plistSocketNotifications;
  127. #else
  128. CMapPtrToPtr*m_pmapSocketHandle;
  129. CMapPtrToPtr* m_pmapDeadSockets;
  130. CPtrList* m_plistSocketNotifications;
  131. #endif
  132. #else
  133. CMapPtrToPtr m_mapSocketHandle;
  134. CMapPtrToPtr m_mapDeadSockets;
  135. CPtrList m_listSocketNotifications;
  136. #endif
  137. #endif
  138. };
  139. // forward references required for AFX_MODULE_STATE definition
  140. class CWinApp;
  141. class COleObjectFactory;
  142. class CWnd;
  143. #ifdef _AFXDLL
  144. class CDynLinkLibrary;
  145. #endif
  146. #ifndef _AFX_NO_OCC_SUPPORT
  147. class COccManager;
  148. class COleControlLock;
  149. #endif
  150. #ifndef _AFX_NO_DAO_SUPPORT
  151. class _AFX_DAO_STATE;
  152. #endif
  153. #if _MFC_VER >= 0x0600
  154. class CTypeLibCacheMap : public CMapPtrToPtr
  155. {
  156. public:
  157. virtual void RemoveAll(void* pExcept);
  158. };
  159. #endif
  160. // AFX_MODULE_STATE (global data for a module)
  161. class AFX_MODULE_STATE : public CNoTrackObject
  162. {
  163. public:
  164. #ifdef _AFXDLL
  165. AFX_MODULE_STATE(BOOL bDLL, WNDPROC pfnAfxWndProc, DWORD dwVersion);
  166. AFX_MODULE_STATE(BOOL bDLL, WNDPROC pfnAfxWndProc, DWORD dwVersion,
  167. BOOL bSystem);
  168. #else
  169. AFX_MODULE_STATE(BOOL bDLL);
  170. #endif
  171. ~AFX_MODULE_STATE();
  172. CWinApp* m_pCurrentWinApp;
  173. HINSTANCE m_hCurrentInstanceHandle;
  174. HINSTANCE m_hCurrentResourceHandle;
  175. LPCTSTR m_lpszCurrentAppName;
  176. BYTE m_bDLL; // TRUE if module is a DLL, FALSE if it is an EXE
  177. BYTE m_bSystem; // TRUE if module is a "system" module, FALSE if not
  178. BYTE m_bReserved[2]; // padding
  179. #if _MFC_VER >= 0x0600
  180. DWORD m_fRegisteredClasses; // flags for registered window classes
  181. #else
  182. short m_fRegisteredClasses; // flags for registered window classes
  183. #endif
  184. // runtime class data
  185. #ifdef _AFXDLL
  186. CRuntimeClass* m_pClassInit;
  187. #endif
  188. CTypedSimpleList<CRuntimeClass*> m_classList;
  189. // OLE object factories
  190. #ifndef _AFX_NO_OLE_SUPPORT
  191. #ifdef _AFXDLL
  192. COleObjectFactory* m_pFactoryInit;
  193. #endif
  194. CTypedSimpleList<COleObjectFactory*> m_factoryList;
  195. #endif
  196. // number of locked OLE objects
  197. long m_nObjectCount;
  198. BOOL m_bUserCtrl;
  199. // AfxRegisterClass and AfxRegisterWndClass data
  200. TCHAR m_szUnregisterList[4096];
  201. #ifdef _AFXDLL
  202. WNDPROC m_pfnAfxWndProc;
  203. DWORD m_dwVersion; // version that module linked against
  204. #endif
  205. // variables related to a given process in a module
  206. // (used to be AFX_MODULE_PROCESS_STATE)
  207. #ifdef _AFX_OLD_EXCEPTIONS
  208. // exceptions
  209. AFX_TERM_PROC m_pfnTerminate;
  210. #endif
  211. void (PASCAL *m_pfnFilterToolTipMessage)(MSG*, CWnd*);
  212. #ifdef _AFXDLL
  213. // CDynLinkLibrary objects (for resource chain)
  214. CTypedSimpleList<CDynLinkLibrary*> m_libraryList;
  215. // special case for MFCxxLOC.DLL (localized MFC resources)
  216. HINSTANCE m_appLangDLL;
  217. #endif
  218. #ifndef _AFX_NO_OCC_SUPPORT
  219. // OLE control container manager
  220. COccManager* m_pOccManager;
  221. // locked OLE controls
  222. CTypedSimpleList<COleControlLock*> m_lockList;
  223. #endif
  224. #ifndef _AFX_NO_DAO_SUPPORT
  225. _AFX_DAO_STATE* m_pDaoState;
  226. #endif
  227. #ifndef _AFX_NO_OLE_SUPPORT
  228. // Type library caches
  229. CTypeLibCache m_typeLibCache;
  230. #if _MFC_VER >= 0x0600
  231. CTypeLibCacheMap* m_pTypeLibCacheMap;
  232. #else
  233. CMapPtrToPtr* m_pTypeLibCacheMap;
  234. #endif
  235. #endif
  236. // define thread local portions of module state
  237. THREAD_LOCAL(AFX_MODULE_THREAD_STATE, m_thread)
  238. };
  239. AFX_MODULE_STATE* AFXAPI AfxGetAppModuleState();
  240. #ifdef _AFXDLL
  241. AFX_MODULE_STATE* AFXAPI AfxSetModuleState(AFX_MODULE_STATE* pNewState);
  242. #endif
  243. AFX_MODULE_STATE* AFXAPI AfxGetModuleState();
  244. AFX_MODULE_STATE* AFXAPI AfxGetStaticModuleState();
  245. AFX_MODULE_THREAD_STATE* AFXAPI AfxGetModuleThreadState();
  246. #ifdef _AFXDLL
  247. #define _AFX_CMDTARGET_GETSTATE() (m_pModuleState)
  248. #else
  249. #define _AFX_CMDTARGET_GETSTATE() (AfxGetModuleState())
  250. #endif
  251. /////////////////////////////////////////////////////////////////////////////
  252. // macros & classes to manage pushing/popping the module state
  253. #ifdef _AFXDLL
  254. struct AFX_MAINTAIN_STATE
  255. {
  256. AFX_MAINTAIN_STATE(AFX_MODULE_STATE* pModuleState);
  257. ~AFX_MAINTAIN_STATE();
  258. protected:
  259. AFX_MODULE_STATE* m_pPrevModuleState;
  260. };
  261. #if _MFC_VER >= 0x0600
  262. class _AFX_THREAD_STATE;
  263. struct AFX_MAINTAIN_STATE2
  264. {
  265. AFX_MAINTAIN_STATE2(AFX_MODULE_STATE* pModuleState);
  266. ~AFX_MAINTAIN_STATE2();
  267. protected:
  268. AFX_MODULE_STATE* m_pPrevModuleState;
  269. _AFX_THREAD_STATE* m_pThreadState;
  270. };
  271. #define AFX_MANAGE_STATE(p) AFX_MAINTAIN_STATE2 _ctlState(p);
  272. #else
  273. #define AFX_MANAGE_STATE(p) AFX_MAINTAIN_STATE _ctlState(p);
  274. #endif // _MFC_VER
  275. #else // _AFXDLL
  276. #define AFX_MANAGE_STATE(p)
  277. #endif //!_AFXDLL
  278. /////////////////////////////////////////////////////////////////////////////
  279. // Thread global state
  280. // forward references required for _AFX_THREAD_STATE definition
  281. class CView;
  282. class CToolTipCtrl;
  283. class CControlBar;
  284. class _AFX_THREAD_STATE : public CNoTrackObject
  285. {
  286. public:
  287. _AFX_THREAD_STATE();
  288. virtual ~_AFX_THREAD_STATE();
  289. // override for m_pModuleState in _AFX_APP_STATE
  290. AFX_MODULE_STATE* m_pModuleState;
  291. AFX_MODULE_STATE* m_pPrevModuleState;
  292. // memory safety pool for temp maps
  293. void* m_pSafetyPoolBuffer; // current buffer
  294. // thread local exception context
  295. AFX_EXCEPTION_CONTEXT m_exceptionContext;
  296. // CWnd create, gray dialog hook, and other hook data
  297. CWnd* m_pWndInit;
  298. CWnd* m_pAlternateWndInit; // special case commdlg hooking
  299. DWORD m_dwPropStyle;
  300. DWORD m_dwPropExStyle;
  301. HWND m_hWndInit;
  302. BOOL m_bDlgCreate;
  303. HHOOK m_hHookOldCbtFilter;
  304. HHOOK m_hHookOldMsgFilter;
  305. // other CWnd modal data
  306. MSG m_lastSentMsg; // see CWnd::WindowProc
  307. HWND m_hTrackingWindow; // see CWnd::TrackPopupMenu
  308. HMENU m_hTrackingMenu;
  309. #ifdef _WIN64
  310. TCHAR m_szTempClassName[256]; // see AfxRegisterWndClass
  311. #else
  312. TCHAR m_szTempClassName[96];
  313. #endif
  314. HWND m_hLockoutNotifyWindow; // see CWnd::OnCommand
  315. BOOL m_bInMsgFilter;
  316. // other framework modal data
  317. CView* m_pRoutingView; // see CCmdTarget::GetRoutingView
  318. CFrameWnd* m_pRoutingFrame; // see CCmdTarget::GetRoutingFrame
  319. // MFC/DB thread-local data
  320. BOOL m_bWaitForDataSource;
  321. // common controls thread state
  322. CToolTipCtrl* m_pToolTip;
  323. CWnd* m_pLastHit; // last window to own tooltip
  324. int m_nLastHit; // last hittest code
  325. TOOLINFO m_lastInfo; // last TOOLINFO structure
  326. int m_nLastStatus; // last flyby status message
  327. CControlBar* m_pLastStatus; // last flyby status control bar
  328. // OLE control thread-local data
  329. CWnd* m_pWndPark; // "parking space" window
  330. long m_nCtrlRef; // reference count on parking window
  331. BOOL m_bNeedTerm; // TRUE if OleUninitialize needs to be called
  332. };
  333. EXTERN_THREAD_LOCAL(_AFX_THREAD_STATE, _afxThreadState)
  334. _AFX_THREAD_STATE* AFXAPI AfxGetThreadState();
  335. /////////////////////////////////////////////////////////////////////////////
  336. #ifdef _AFX_PACKING
  337. #pragma pack(pop)
  338. #endif
  339. #undef AFX_DATA
  340. #define AFX_DATA
  341. #endif //__AFXSTATE_H__
  342. /////////////////////////////////////////////////////////////////////////////