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.

273 lines
7.3 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. // FILE : resutil.cpp //
  3. // //
  4. // DESCRIPTION : resource utility functions for MMC use. //
  5. // //
  6. // AUTHOR : yossg //
  7. // //
  8. // HISTORY : //
  9. // Jun 30 1998 zvib Init. //
  10. // Aug 24 1998 adik Add methods to save and load. //
  11. // Aug 31 1998 adik Add GetChmFile & OnSnapinHelp. //
  12. // Mar 28 1999 adik Redefine CColumnsInfo. //
  13. // Apr 27 1999 adik Help support. //
  14. // Jun 02 1999 adik Change the path to comet.chm. //
  15. // Jun 22 1999 adik Change the path to comet.chm to full path. //
  16. // //
  17. // Oct 14 1999 yossg Welcome to Fax //
  18. // //
  19. // Copyright (C) 1998 Microsoft Corporation All Rights Reserved //
  20. /////////////////////////////////////////////////////////////////////////////
  21. #include "stdafx.h"
  22. #include "resutil.h"
  23. #include "commctrl.h"
  24. #include <HtmlHelp.h>
  25. #define MAX_COLUMN_LENGTH 300
  26. /*
  27. - CColumnsInfo::CColumnsInfo
  28. -
  29. * Purpose:
  30. * Constructor
  31. */
  32. CColumnsInfo::CColumnsInfo()
  33. {
  34. m_IsInitialized = FALSE;
  35. }
  36. /*
  37. - CColumnsInfo::~CColumnsInfo
  38. -
  39. * Purpose:
  40. * Destructor
  41. */
  42. CColumnsInfo::~CColumnsInfo()
  43. {
  44. int i;
  45. for (i=0; i < m_Data.GetSize(); i++)
  46. {
  47. SysFreeString(m_Data[i].Header);
  48. }
  49. }
  50. /*
  51. - CColumnsInfo::InsertColumnsIntoMMC
  52. -
  53. * Purpose:
  54. * Add columns to the default result pane
  55. *
  56. * Arguments:
  57. * [in] pHeaderCtrl - console provided result pane header
  58. * [in] hInst - resource handle
  59. * [in] aInitData - columns init data: array of ids & width.
  60. * the last ids must be LAST_IDS.
  61. *
  62. * Return:
  63. * S_OK for success
  64. * + return value from IHeaderCtrl::InsertColumn
  65. */
  66. HRESULT
  67. CColumnsInfo::InsertColumnsIntoMMC(IHeaderCtrl *pHeaderCtrl,
  68. HINSTANCE hInst,
  69. ColumnsInfoInitData aInitData[])
  70. {
  71. int i;
  72. HRESULT hRc = S_OK;
  73. DEBUG_FUNCTION_NAME( _T("CColumnsInfo::InsertColumnsIntoMMC"));
  74. ATLASSERT(pHeaderCtrl);
  75. //
  76. // First time init
  77. //
  78. if (! m_IsInitialized)
  79. {
  80. hRc = Init(hInst, aInitData);
  81. if ( FAILED(hRc) )
  82. {
  83. DebugPrintEx(DEBUG_ERR,_T("Failed to Init. (hRc: %08X)"), hRc);
  84. goto Cleanup;
  85. }
  86. }
  87. ATLASSERT(m_IsInitialized);
  88. //
  89. // Set all columns headers
  90. //
  91. for (i=0; i < m_Data.GetSize(); i++ )
  92. {
  93. //
  94. // Insert the column
  95. //
  96. hRc = pHeaderCtrl->InsertColumn(i,
  97. m_Data[i].Header,
  98. LVCFMT_LEFT,
  99. m_Data[i].Width);
  100. if ( FAILED(hRc) )
  101. {
  102. DebugPrintEx(DEBUG_ERR,_T("Failed to InsertColumn. (hRc: %08X)"), hRc);
  103. goto Cleanup;
  104. }
  105. }
  106. Cleanup:
  107. return hRc;
  108. }
  109. /*
  110. - CColumnsInfo::Init
  111. -
  112. * Purpose:
  113. * Init the class with columns info
  114. *
  115. * Arguments:
  116. * [in] hInst - resource handle
  117. * [in] aInitData - columns init data: array of ids & width.
  118. * the last ids must be LAST_IDS.
  119. *
  120. * Return:
  121. * S_OK for success
  122. * + return value from LoadString
  123. * + E_OUTOFMEMORY
  124. */
  125. HRESULT
  126. CColumnsInfo::Init(HINSTANCE hInst, ColumnsInfoInitData aInitData[])
  127. {
  128. WCHAR buf[MAX_COLUMN_LENGTH];
  129. ColumnsInfoInitData *pData;
  130. int rc, ind;
  131. BOOL fOK;
  132. HRESULT hRc = S_OK;
  133. ColumnData dummy;
  134. DEBUG_FUNCTION_NAME( _T("CColumnsInfo::Init"));
  135. ATLASSERT(aInitData);
  136. ATLASSERT(! m_IsInitialized);
  137. //
  138. // Insert all column headers
  139. //
  140. ZeroMemory(&dummy, sizeof dummy);
  141. for (pData = &aInitData[0]; pData->ids != LAST_IDS; pData++)
  142. {
  143. //
  144. // Load the string from the resource
  145. //
  146. rc = LoadString(hInst, pData->ids , buf, MAX_COLUMN_LENGTH);
  147. if (rc == 0)
  148. {
  149. DWORD dwErr = GetLastError();
  150. hRc = HRESULT_FROM_WIN32(dwErr);
  151. DebugPrintEx(DEBUG_ERR,_T("Failed to LoadString. (hRc: %08X)"), hRc);
  152. goto Cleanup;
  153. }
  154. //
  155. // Duplicates the empty struct into the array
  156. //
  157. fOK = m_Data.Add(dummy);
  158. if (! fOK)
  159. {
  160. hRc = E_OUTOFMEMORY;
  161. DebugPrintEx(DEBUG_ERR,_T(" m_Data.Add failed. (hRc: %08X)"), hRc);
  162. goto Cleanup;
  163. }
  164. //
  165. // Set the data
  166. //
  167. ind = m_Data.GetSize()-1;
  168. ATLASSERT(ind >= 0);
  169. m_Data[ind].Width = pData->Width;
  170. m_Data[ind].Header = SysAllocString(buf);
  171. if (! m_Data[ind].Header)
  172. {
  173. hRc = E_OUTOFMEMORY;
  174. DebugPrintEx(DEBUG_ERR,_T("Failed to SysAllocString. (hRc: %08X)"), hRc);
  175. goto Cleanup;
  176. }
  177. } // endfor
  178. m_IsInitialized = TRUE;
  179. Cleanup:
  180. return hRc;
  181. }
  182. /*
  183. - GetHelpFile
  184. -
  185. * Purpose:
  186. * Get full path to the comet CHM file
  187. *
  188. * Arguments:
  189. * [out] pwszChmFile - fullath of the CHM file
  190. *
  191. * Return:
  192. * OLE error code translated from registry open/query error
  193. */
  194. WCHAR * __cdecl
  195. GetHelpFile()
  196. {
  197. static WCHAR szFile[MAX_PATH] = {0};
  198. DEBUG_FUNCTION_NAME( _T("GetHelpFile"));
  199. if (szFile[0] == L'\0')
  200. {
  201. ExpandEnvironmentStrings(L"%windir%\\help\\FxsAdmin.chm", szFile, MAX_PATH);
  202. }
  203. return (szFile[0])? szFile: NULL;
  204. }
  205. /*
  206. - OnSnapinHelp
  207. -
  208. * Purpose:
  209. * Display Comet.chm help file. This method gets called when the
  210. * MMCN_SNAPINHELP Notify message is sent for IComponent object.
  211. * MMC sends this message when the user requests help about
  212. * the snap-in.
  213. *
  214. * Arguments:
  215. * [in] pConsole - MMC console interface
  216. *
  217. * Return:
  218. * Errors returned from GetChmFile
  219. */
  220. HRESULT __cdecl
  221. OnSnapinHelp(IConsole *pConsole)
  222. {
  223. WCHAR *pszChmFile;
  224. HWND hWnd = NULL;
  225. HRESULT hRc = E_FAIL;
  226. //
  227. // Get the caller window
  228. //
  229. ATLASSERT(pConsole);
  230. pConsole->GetMainWindow(&hWnd);
  231. //
  232. // Get the CHM file name
  233. //
  234. pszChmFile = GetHelpFile();
  235. //
  236. // Use HtmlHelp API to display the help.
  237. //
  238. if ( pszChmFile && *pszChmFile )
  239. {
  240. hRc = S_OK;
  241. // HtmlHelp(hWnd, pszChmFile, HH_DISPLAY_TOPIC, (DWORD)0);
  242. }
  243. return hRc;
  244. }