Leaked source code of windows server 2003
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.

334 lines
9.0 KiB

  1. // ChainWiz.h : Declaration of the CChainWiz
  2. #ifndef __CHAINWIZ_H_
  3. #define __CHAINWIZ_H_
  4. #include "resource.h" // main symbols
  5. #include "PPPBag.h"
  6. #include "tmplRichEdit.h"
  7. #include <assert.h>
  8. class CDummyComponent : public IAddPropertySheets
  9. {
  10. private:
  11. BOOL m_bIsWelcomePage;
  12. ULONG m_refs;
  13. CDummyComponent( BOOL bIsWelcomePage )
  14. {
  15. m_bIsWelcomePage = bIsWelcomePage;
  16. m_refs = 0;
  17. }
  18. ~CDummyComponent( ) {}
  19. public:
  20. static IAddPropertySheets* Create( BOOL bIsWelcomePage )
  21. {
  22. IAddPropertySheets* pAPSs = NULL;
  23. CDummyComponent* pDC = new CDummyComponent( bIsWelcomePage );
  24. if( pDC )
  25. {
  26. pDC->AddRef();
  27. pDC->QueryInterface( IID_IAddPropertySheets, (void**)&pAPSs );
  28. pDC->Release();
  29. }
  30. return pAPSs;
  31. }
  32. virtual HRESULT STDMETHODCALLTYPE QueryInterface( REFIID riid, void** ppvObject )
  33. {
  34. HRESULT hr = S_OK;
  35. if ((riid == IID_IUnknown) ||
  36. (riid == IID_IAddPropertySheets) )
  37. {
  38. AddRef();
  39. *ppvObject = (void*)this;
  40. }
  41. else
  42. {
  43. hr = E_NOINTERFACE;
  44. }
  45. return hr;
  46. }
  47. virtual ULONG STDMETHODCALLTYPE AddRef( )
  48. {
  49. InterlockedIncrement( (PLONG)&m_refs );
  50. return m_refs;
  51. }
  52. virtual ULONG STDMETHODCALLTYPE Release( )
  53. {
  54. InterlockedDecrement( (PLONG)&m_refs );
  55. ULONG l = m_refs;
  56. if( m_refs == 0 )
  57. {
  58. delete this;
  59. }
  60. return l;
  61. }
  62. virtual HRESULT STDMETHODCALLTYPE EnumPropertySheets( IAddPropertySheet* pADS) { return S_FALSE; }
  63. virtual HRESULT STDMETHODCALLTYPE ProvideFinishText ( LPOLESTR* lpolestrString, LPOLESTR * pMoreInfoText) { return E_NOTIMPL; }
  64. virtual HRESULT STDMETHODCALLTYPE ReadProperties ( IPropertyPagePropertyBag* pPPPBag) { return S_OK; }
  65. virtual HRESULT STDMETHODCALLTYPE WriteProperties ( IPropertyPagePropertyBag* pPPPBag) { return S_OK; }
  66. };
  67. class CComponents
  68. {
  69. private:
  70. IAddPropertySheets* m_pAPSs;
  71. public:
  72. CComponents( IAddPropertySheets* pAPSs )
  73. {
  74. if( pAPSs )
  75. {
  76. pAPSs->AddRef ();
  77. }
  78. m_pAPSs = pAPSs;
  79. }
  80. ~CComponents( )
  81. {
  82. if( m_pAPSs )
  83. {
  84. m_pAPSs->Release();
  85. m_pAPSs = NULL;
  86. }
  87. }
  88. IAddPropertySheets* GetComponent( ) { return m_pAPSs; }
  89. };
  90. /////////////////////////////////////////////////////////////////////////////
  91. // CChainWiz
  92. class ATL_NO_VTABLE CChainWiz :
  93. public CComObjectRootEx<CComSingleThreadModel>,
  94. public CComCoClass<CChainWiz, &CLSID_ChainWiz>,
  95. public IChainWiz
  96. {
  97. public:
  98. HWND m_hWndLink;
  99. HWND m_hWndWelcomeLink;
  100. CWindowImplHotlinkRichEdit<> m_Hotlink;
  101. DWORD m_dwWizardStyle;
  102. HMODULE m_hModuleRichEdit;
  103. private:
  104. PROPSHEETHEADERW* m_psh;
  105. std::list<CComponents*> m_listOfAPSs;
  106. std::map<LPDLGTEMPLATE, LPDLGTEMPLATE> m_mapOfTemplates;
  107. LPOLESTR m_szFinishText;
  108. HFONT m_hf;
  109. BSTR m_szWelcomeTitle;
  110. BSTR m_szFinishHeader;
  111. BSTR m_szFinishSubHeader;
  112. BSTR m_szFirstFinishTextLine;
  113. BSTR m_bstrTempFileName;
  114. CComObject<CPropertyPagePropertyBag>* m_PPPBag;
  115. IAddPropertySheets* m_CurrentComponent;
  116. IAddPropertySheets* m_PreviousComponent;
  117. private:
  118. void DestroyMaps( )
  119. {
  120. std::list<CComponents*>::iterator iterAPSs = m_listOfAPSs.begin();
  121. for( CComponents* pComps = *iterAPSs; iterAPSs != m_listOfAPSs.end(); pComps = *++iterAPSs )
  122. {
  123. delete pComps;
  124. }
  125. m_listOfAPSs.clear();
  126. // destroy templates
  127. std::map<LPDLGTEMPLATE, LPDLGTEMPLATE>::iterator iterTemp = m_mapOfTemplates.begin();
  128. while( iterTemp != m_mapOfTemplates.end() )
  129. {
  130. GlobalFree( iterTemp->second );
  131. iterTemp++;
  132. }
  133. m_mapOfTemplates.clear();
  134. }
  135. public:
  136. CChainWiz( ) : m_bstrTempFileName(NULL), m_hWndLink(NULL), m_hWndWelcomeLink(NULL), m_szFirstFinishTextLine(NULL), m_dwWizardStyle(0)
  137. {
  138. m_hModuleRichEdit = NULL;
  139. m_psh = NULL;
  140. m_szFinishText = NULL;
  141. m_szWelcomeTitle = NULL;
  142. m_szFinishHeader = NULL;
  143. m_szFinishSubHeader = NULL;
  144. m_PPPBag = NULL;
  145. CComObject<CPropertyPagePropertyBag>::CreateInstance( &m_PPPBag );
  146. if( m_PPPBag )
  147. {
  148. m_PPPBag->AddRef();
  149. }
  150. m_CurrentComponent = NULL;
  151. m_PreviousComponent = NULL;
  152. // copied from wiz97.cpp (sample code)
  153. NONCLIENTMETRICS ncm = {0};
  154. ncm.cbSize = sizeof (ncm);
  155. SystemParametersInfo( SPI_GETNONCLIENTMETRICS, 0, &ncm, 0 );
  156. LOGFONT lf = ncm.lfMessageFont;
  157. lf.lfWeight = FW_BOLD;
  158. // using font name in resource file instead of hard-coding 'Verdana Bold'
  159. WCHAR szFont[32];
  160. ::LoadString( (HINSTANCE)_Module.GetModuleInstance(), IDS_WIZARD97_FONT, szFont, 32 );
  161. wcscpy (lf.lfFaceName, szFont);
  162. // using font name in resource file instead of hard-coding 'Verdana Bold'
  163. HDC hdc = GetDC( NULL ); // gets the screen DC
  164. int FontSize = 12;
  165. lf.lfHeight = 0 - ((GetDeviceCaps( hdc, LOGPIXELSY ) * FontSize) / 72);
  166. m_hf = CreateFontIndirect( &lf );
  167. ReleaseDC( NULL, hdc );
  168. }
  169. ~CChainWiz()
  170. {
  171. if( m_hModuleRichEdit )
  172. {
  173. FreeLibrary(m_hModuleRichEdit);
  174. }
  175. if( m_hf )
  176. {
  177. DeleteObject( (HGDIOBJ)m_hf );
  178. }
  179. if( m_PPPBag )
  180. {
  181. m_PPPBag->Release();
  182. }
  183. if( m_psh )
  184. {
  185. delete[] m_psh->phpage;
  186. delete m_psh;
  187. }
  188. if( m_szFinishText )
  189. {
  190. CoTaskMemFree( m_szFinishText );
  191. }
  192. if( m_szWelcomeTitle )
  193. {
  194. SysFreeString( m_szWelcomeTitle );
  195. }
  196. if( m_szFinishHeader )
  197. {
  198. SysFreeString( m_szFinishHeader );
  199. }
  200. if( m_szFinishSubHeader )
  201. {
  202. SysFreeString( m_szFinishSubHeader );
  203. }
  204. if( m_szFirstFinishTextLine )
  205. {
  206. SysFreeString( m_szFirstFinishTextLine );
  207. }
  208. if (m_bstrTempFileName)
  209. {
  210. DeleteFile( m_bstrTempFileName );
  211. SysFreeString( m_bstrTempFileName );
  212. }
  213. // release all pAPSs
  214. DestroyMaps( );
  215. }
  216. HRESULT Add( PROPSHEETPAGEW* psp );
  217. HRESULT GetAllFinishText( LPOLESTR* pstring, LPOLESTR* pMoreInfoText );
  218. DECLARE_REGISTRY_RESOURCEID(IDR_CHAINWIZ)
  219. DECLARE_NOT_AGGREGATABLE(CChainWiz)
  220. DECLARE_PROTECT_FINAL_CONSTRUCT()
  221. BEGIN_COM_MAP(CChainWiz)
  222. COM_INTERFACE_ENTRY(IChainWiz)
  223. END_COM_MAP()
  224. // IChainWiz
  225. public:
  226. STDMETHOD(DoModal) ( /*[out]*/ long* ret );
  227. STDMETHOD(AddWizardComponent) ( /*[in, string]*/ LPOLESTR szClsidOfComponent );
  228. STDMETHOD(Initialize) ( /*[in]*/ HBITMAP hbmWatermark, /*[in]*/ HBITMAP hbmHeader, /*[in, string]*/ LPOLESTR szTitle, /*[in, string]*/ LPOLESTR szWelcomeHeader, /*[in, string]*/ LPOLESTR szWelcomeText, /*[in, string]*/ LPOLESTR szFinishHeader, /*[in, string]*/ LPOLESTR szFinishIntroText, LPOLESTR /*[in, string]*/ szFinishText );
  229. STDMETHOD(get_MoreInfoFileName) ( /*[out, retval*]*/ BSTR * pbstrMoreInfoFileName);
  230. STDMETHOD(put_WizardStyle)(/*[in*/ VARIANT * pVar);
  231. public:
  232. // for welcomedlgproc
  233. PROPSHEETHEADERW* GetPropSheetHeader( ) { return m_psh; }
  234. // for finishdlgproc
  235. HFONT GetBoldFont( ) { return m_hf; }
  236. BSTR GetFinishHeader( ) { return m_szFinishHeader; }
  237. BSTR GetFinishSubHeader( ) { return m_szFinishSubHeader; }
  238. // for cancel message box
  239. BSTR GetTitle( ) { return m_szWelcomeTitle; }
  240. STDMETHOD(get_PropertyBag)( /*[out, retval]*/ IDispatch* *pVal );
  241. CComObject<CPropertyPagePropertyBag>* GetPPPBag( ) { return m_PPPBag; }
  242. IAddPropertySheets* GetCurrentComponent( ) { return m_CurrentComponent; }
  243. void SetCurrentComponent( IAddPropertySheets* CurrentComponent ) { m_CurrentComponent = CurrentComponent; }
  244. IAddPropertySheets* GetPreviousComponent( ) { return m_PreviousComponent; }
  245. void SetPreviousComponent( IAddPropertySheets* PreviousComponent ) { m_PreviousComponent = PreviousComponent; }
  246. HRESULT WriteTempFile ( LPCTSTR szText );
  247. HRESULT LaunchMoreInfo( );
  248. LPDLGTEMPLATE GetAtlTemplate( LPDLGTEMPLATE lpdt )
  249. {
  250. std::map<LPDLGTEMPLATE, LPDLGTEMPLATE>::iterator iterTemp = m_mapOfTemplates.find (lpdt);
  251. if( iterTemp != m_mapOfTemplates.end() )
  252. {
  253. return iterTemp->second;
  254. }
  255. return NULL;
  256. }
  257. };
  258. #endif //__CHAINWIZ_H_