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.

389 lines
8.2 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation 1996-2001.
  5. //
  6. // File: hidwnd.cpp
  7. //
  8. // Contents: implementation of CHiddenWnd
  9. //
  10. //----------------------------------------------------------------------------
  11. #include "stdafx.h"
  12. #include <mmc.h>
  13. #include "wsecmgr.h"
  14. #include "resource.h"
  15. #include "snapmgr.h"
  16. #include "HidWnd.h"
  17. #include "util.h"
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. #define SCEM_UPDATE_ALL_VIEWS (WM_APP+101)
  24. #define SCEM_UPDATE_ITEM (WM_APP+102)
  25. #define SCEM_REFRESH_POLICY (WM_APP+103)
  26. #define SCEM_RELOAD_LOCATION (WM_APP+104)
  27. #define SCEM_SET_PROFILE_DESC (WM_APP+105)
  28. #define SCEM_LOCK_ANAL_PANE (WM_APP+106)
  29. #define SCEM_CLOSE_ANAL_PANE (WM_APP+107)
  30. #define SCEM_SELECT_SCOPE_ITEM (WM_APP+108)
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CHiddenWnd
  33. CHiddenWnd::CHiddenWnd()
  34. {
  35. m_GPTInfo = NULL;
  36. m_pConsole = NULL;
  37. }
  38. CHiddenWnd::~CHiddenWnd()
  39. {
  40. DestroyWindow(); //Memory leak, 4/27/2001
  41. if (m_pConsole) {
  42. m_pConsole->Release();
  43. }
  44. if (m_GPTInfo) {
  45. m_GPTInfo->Release();
  46. }
  47. }
  48. BEGIN_MESSAGE_MAP(CHiddenWnd, CWnd)
  49. //{{AFX_MSG_MAP(CHiddenWnd)
  50. // NOTE - the ClassWizard will add and remove mapping macros here.
  51. //}}AFX_MSG_MAP
  52. ON_MESSAGE(SCEM_UPDATE_ALL_VIEWS,OnUpdateAllViews)
  53. ON_MESSAGE(SCEM_UPDATE_ITEM,OnUpdateItem)
  54. ON_MESSAGE(SCEM_REFRESH_POLICY,OnRefreshPolicy)
  55. ON_MESSAGE(SCEM_RELOAD_LOCATION,OnReloadLocation)
  56. ON_MESSAGE(SCEM_LOCK_ANAL_PANE,OnLockAnalysisPane)
  57. ON_MESSAGE(SCEM_CLOSE_ANAL_PANE,OnCloseAnalysisPane)
  58. ON_MESSAGE(SCEM_SELECT_SCOPE_ITEM,OnSelectScopeItem)
  59. END_MESSAGE_MAP()
  60. /////////////////////////////////////////////////////////////////////////////
  61. // CHiddenWnd message handlers
  62. #define VOID_RET
  63. void
  64. CHiddenWnd::OnUpdateAllViews(WPARAM uParam, LPARAM lParam)
  65. {
  66. PUPDATEVIEWDATA puvd;
  67. puvd = (PUPDATEVIEWDATA)uParam;
  68. if (!puvd) {
  69. return VOID_RET;
  70. }
  71. if (m_pConsole) {
  72. m_pConsole->UpdateAllViews(puvd->pDataObject,puvd->data,puvd->hint);
  73. }
  74. if( puvd->pDataObject && 1 == (int)lParam ) //Raid #357968, #354861, 4/25/2001
  75. {
  76. puvd->pDataObject->Release();
  77. }
  78. LocalFree(puvd);
  79. return VOID_RET;
  80. }
  81. void
  82. CHiddenWnd::OnUpdateItem(WPARAM uParam, LPARAM lParam)
  83. {
  84. LPRESULTDATA pResultPane;
  85. HRESULTITEM hResultItem;
  86. pResultPane = (LPRESULTDATA)uParam;
  87. hResultItem = (HRESULTITEM)lParam;
  88. if (!pResultPane) {
  89. return VOID_RET;
  90. }
  91. try {
  92. pResultPane->UpdateItem(hResultItem);
  93. } catch (...) {
  94. ASSERT(FALSE);
  95. }
  96. return VOID_RET;
  97. }
  98. void
  99. CHiddenWnd::OnRefreshPolicy(WPARAM uParam, LPARAM lParam)
  100. {
  101. GUID guidExtension = { 0x827d319e, 0x6eac, 0x11d2, {0xa4, 0xea, 0x00, 0xc0, 0x4f, 0x79, 0xf8, 0x3a }};
  102. GUID guidSnapin = CLSID_Snapin;
  103. if (!m_GPTInfo) {
  104. return VOID_RET;
  105. }
  106. try {
  107. if (!SUCCEEDED(m_GPTInfo->PolicyChanged(TRUE, TRUE, &guidExtension, &guidSnapin))) {
  108. AfxMessageBox(IDS_ERROR_REFRESH_POLICY_FAILED);
  109. }
  110. } catch (...) {
  111. AfxMessageBox(IDS_ERROR_REFRESH_POLICY_FAILED);
  112. ASSERT(FALSE);
  113. }
  114. return VOID_RET;
  115. }
  116. void
  117. CHiddenWnd::OnReloadLocation(WPARAM uParam, LPARAM lParam)
  118. {
  119. CFolder *pFolder;
  120. CComponentDataImpl *pCDI;
  121. pFolder = reinterpret_cast<CFolder*>(uParam);
  122. if (lParam) {
  123. pCDI = reinterpret_cast<CComponentDataImpl*>(lParam);
  124. } else {
  125. pCDI = m_pCDI;
  126. }
  127. try {
  128. pCDI->ReloadLocation(pFolder);
  129. } catch (...) {
  130. ASSERT(FALSE);
  131. }
  132. return VOID_RET;
  133. }
  134. HRESULT
  135. CHiddenWnd::UpdateAllViews(
  136. LPDATAOBJECT pDO,
  137. CSnapin *pSnapin,
  138. CFolder *pFolder,
  139. CResult *pResult,
  140. UINT uAction
  141. )
  142. {
  143. PUPDATEVIEWDATA puvd;
  144. if(!m_hWnd){
  145. return S_OK;
  146. }
  147. //
  148. // Notify item.
  149. //
  150. puvd = (UpdateViewData *)LocalAlloc(0, sizeof( UpdateViewData ));
  151. if (!puvd) {
  152. return E_FAIL;
  153. }
  154. puvd->pDataObject = (LPDATAOBJECT)pSnapin;
  155. puvd->data = (LPARAM)pResult;
  156. puvd->hint = uAction;
  157. if (!::PostMessage(m_hWnd, SCEM_UPDATE_ALL_VIEWS, (WPARAM)puvd, 0))
  158. {
  159. //
  160. // puvd will be freed by the SCEM_UPDATE_ALL_VIEWS handler,
  161. // but if somehow the PostMessage fails we need to free it ourselves.
  162. //
  163. LocalFree(puvd);
  164. }
  165. return S_OK;
  166. }
  167. HRESULT
  168. CHiddenWnd::UpdateAllViews(LPDATAOBJECT pDO, LPARAM data, LPARAM hint)
  169. {
  170. PUPDATEVIEWDATA puvd;
  171. puvd = (UpdateViewData *)LocalAlloc(0, sizeof(UpdateViewData));
  172. if (!puvd) {
  173. return E_FAIL;
  174. }
  175. puvd->pDataObject = pDO;
  176. puvd->data = data;
  177. puvd->hint = hint;
  178. if (!m_hWnd || !::PostMessage(m_hWnd,SCEM_UPDATE_ALL_VIEWS,(WPARAM)puvd,(LPARAM)1))
  179. {
  180. //
  181. // puvd will be freed by the SCEM_UPDATE_ALL_VIEWS handler,
  182. // but if somehow the PostMessage fails we need to free it ourselves.
  183. //
  184. if( puvd->pDataObject ) //Raid #357968, #354861, 4/25/2001
  185. {
  186. puvd->pDataObject->Release();
  187. }
  188. LocalFree( puvd );
  189. }
  190. return S_OK;
  191. }
  192. HRESULT
  193. CHiddenWnd::UpdateItem(LPRESULTDATA pResultPane,HRESULTITEM hResultItem)
  194. {
  195. if (!pResultPane) {
  196. return E_INVALIDARG;
  197. }
  198. if (m_hWnd) {
  199. ::PostMessage(m_hWnd,SCEM_UPDATE_ITEM,(WPARAM)pResultPane,(LPARAM)hResultItem);
  200. }
  201. return S_OK;
  202. }
  203. HRESULT
  204. CHiddenWnd::RefreshPolicy()
  205. {
  206. if (m_hWnd) {
  207. ::PostMessage(m_hWnd,SCEM_REFRESH_POLICY,0,0);
  208. }
  209. return S_OK;
  210. }
  211. void
  212. CHiddenWnd::SetGPTInformation(LPGPEINFORMATION GPTInfo)
  213. {
  214. if (m_GPTInfo) {
  215. m_GPTInfo->Release();
  216. }
  217. m_GPTInfo = GPTInfo;
  218. if (m_GPTInfo) {
  219. m_GPTInfo->AddRef();
  220. }
  221. }
  222. void
  223. CHiddenWnd::SetConsole(LPCONSOLE pConsole)
  224. {
  225. if (m_pConsole) {
  226. m_pConsole->Release();
  227. }
  228. m_pConsole = pConsole;
  229. if (m_pConsole) {
  230. m_pConsole->AddRef();
  231. }
  232. }
  233. HRESULT
  234. CHiddenWnd::ReloadLocation(CFolder * pFolder,CComponentDataImpl * pCDI)
  235. {
  236. if (m_hWnd) {
  237. ::PostMessage(m_hWnd,SCEM_RELOAD_LOCATION, (WPARAM)pFolder, (LPARAM)pCDI);
  238. }
  239. return S_OK;
  240. }
  241. HRESULT
  242. CHiddenWnd::SetProfileDescription(CString *strFile, CString *strDescription)
  243. {
  244. LPTSTR szFile = NULL;
  245. LPTSTR szDes = NULL; //Raid #prefast
  246. if (!strFile->IsEmpty()) {
  247. szFile = (LPTSTR)LocalAlloc(LPTR,(strFile->GetLength()+1)*sizeof(TCHAR));
  248. if (!szFile) {
  249. return E_OUTOFMEMORY;
  250. }
  251. }
  252. if (!strDescription->IsEmpty()) {
  253. szDes = (LPTSTR)LocalAlloc(LPTR,(strDescription->GetLength()+1)*sizeof(TCHAR));
  254. if (!szDes) {
  255. LocalFree(szFile);
  256. return E_OUTOFMEMORY;
  257. }
  258. }
  259. if (m_hWnd) {
  260. ::PostMessage(m_hWnd,SCEM_RELOAD_LOCATION, (WPARAM)szFile, (LPARAM)szDes);
  261. }
  262. return S_OK;
  263. }
  264. void
  265. CHiddenWnd::OnLockAnalysisPane(WPARAM uParam, LPARAM lParam)
  266. {
  267. try {
  268. m_pCDI->LockAnalysisPane((BOOL)uParam,(BOOL)lParam);
  269. } catch (...) {
  270. ASSERT(FALSE);
  271. }
  272. return VOID_RET;
  273. }
  274. HRESULT
  275. CHiddenWnd::LockAnalysisPane(BOOL bLock, BOOL fRemoveAnalDlg)
  276. {
  277. if (m_hWnd) {
  278. ::PostMessage(m_hWnd,SCEM_LOCK_ANAL_PANE, (WPARAM)bLock, (LPARAM)fRemoveAnalDlg);
  279. }
  280. return S_OK;
  281. }
  282. void
  283. CHiddenWnd::OnCloseAnalysisPane(WPARAM uParam, LPARAM lParam)
  284. {
  285. try {
  286. m_pCDI->CloseAnalysisPane();
  287. } catch (...) {
  288. ASSERT(FALSE);
  289. }
  290. return VOID_RET;
  291. }
  292. void
  293. CHiddenWnd::CloseAnalysisPane()
  294. {
  295. if (m_hWnd) {
  296. ::PostMessage(m_hWnd,SCEM_CLOSE_ANAL_PANE, NULL, NULL);
  297. }
  298. }
  299. void
  300. CHiddenWnd::OnSelectScopeItem(WPARAM uParam, LPARAM lParam)
  301. {
  302. try {
  303. m_pCDI->GetConsole()->SelectScopeItem(uParam);
  304. } catch (...) {
  305. ASSERT(FALSE);
  306. }
  307. return VOID_RET;
  308. }
  309. void
  310. CHiddenWnd::SelectScopeItem(HSCOPEITEM ID)
  311. {
  312. if (m_hWnd) {
  313. ::PostMessage(m_hWnd,SCEM_SELECT_SCOPE_ITEM, (WPARAM) ID, NULL);
  314. }
  315. }