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.

670 lines
19 KiB

  1. #include "main.h"
  2. // {febf1208-8aff-11d2-a8a1-00c04fbbcfa2}
  3. #define GPEXT_GUID { 0xfebf1208, 0x8aff, 0x11d2, { 0xa8, 0xa1, 0x0, 0xc0, 0x4f, 0xbb, 0xcf, 0xa2} };
  4. GUID guidGPExt = GPEXT_GUID;
  5. GUID guidSnapin = CLSID_GPTDemoSnapIn;
  6. ///////////////////////////////////////////////////////////////////////////////
  7. // //
  8. // CSnapIn object implementation //
  9. // //
  10. ///////////////////////////////////////////////////////////////////////////////
  11. CSnapIn::CSnapIn(CComponentData *pComponent)
  12. {
  13. m_cRef = 1;
  14. InterlockedIncrement(&g_cRefThisDll);
  15. m_pcd = pComponent;
  16. m_pConsole = NULL;
  17. m_pResult = NULL;
  18. m_pHeader = NULL;
  19. m_pImageResult = NULL;
  20. m_pConsoleVerb = NULL;
  21. m_nColumnSize = 180;
  22. m_lViewMode = LVS_ICON;
  23. LoadString(g_hInstance, IDS_NAME, m_column1, sizeof(m_column1));
  24. }
  25. CSnapIn::~CSnapIn()
  26. {
  27. InterlockedDecrement(&g_cRefThisDll);
  28. }
  29. ///////////////////////////////////////////////////////////////////////////////
  30. // //
  31. // CSnapIn object implementation (IUnknown) //
  32. // //
  33. ///////////////////////////////////////////////////////////////////////////////
  34. HRESULT CSnapIn::QueryInterface (REFIID riid, void **ppv)
  35. {
  36. if (IsEqualIID(riid, IID_IComponent) || IsEqualIID(riid, IID_IUnknown))
  37. {
  38. *ppv = (LPCOMPONENT)this;
  39. m_cRef++;
  40. return S_OK;
  41. }
  42. else if (IsEqualIID(riid, IID_IExtendPropertySheet))
  43. {
  44. *ppv = (LPEXTENDPROPERTYSHEET)this;
  45. m_cRef++;
  46. return S_OK;
  47. }
  48. else
  49. {
  50. *ppv = NULL;
  51. return E_NOINTERFACE;
  52. }
  53. }
  54. ULONG CSnapIn::AddRef (void)
  55. {
  56. return ++m_cRef;
  57. }
  58. ULONG CSnapIn::Release (void)
  59. {
  60. if (--m_cRef == 0) {
  61. delete this;
  62. return 0;
  63. }
  64. return m_cRef;
  65. }
  66. ///////////////////////////////////////////////////////////////////////////////
  67. // //
  68. // CSnapIn object implementation (IComponent) //
  69. // //
  70. ///////////////////////////////////////////////////////////////////////////////
  71. STDMETHODIMP CSnapIn::Initialize(LPCONSOLE lpConsole)
  72. {
  73. HRESULT hr;
  74. // Save the IConsole pointer
  75. m_pConsole = lpConsole;
  76. m_pConsole->AddRef();
  77. hr = m_pConsole->QueryInterface(IID_IHeaderCtrl,
  78. reinterpret_cast<void**>(&m_pHeader));
  79. // Give the console the header control interface pointer
  80. if (SUCCEEDED(hr))
  81. m_pConsole->SetHeader(m_pHeader);
  82. m_pConsole->QueryInterface(IID_IResultData,
  83. reinterpret_cast<void**>(&m_pResult));
  84. hr = m_pConsole->QueryResultImageList(&m_pImageResult);
  85. hr = m_pConsole->QueryConsoleVerb(&m_pConsoleVerb);
  86. return S_OK;
  87. }
  88. STDMETHODIMP CSnapIn::Destroy(long cookie)
  89. {
  90. if (m_pConsole != NULL)
  91. {
  92. m_pConsole->SetHeader(NULL);
  93. m_pConsole->Release();
  94. m_pConsole = NULL;
  95. }
  96. if (m_pHeader != NULL)
  97. {
  98. m_pHeader->Release();
  99. m_pHeader = NULL;
  100. }
  101. if (m_pResult != NULL)
  102. {
  103. m_pResult->Release();
  104. m_pResult = NULL;
  105. }
  106. if (m_pImageResult != NULL)
  107. {
  108. m_pImageResult->Release();
  109. m_pImageResult = NULL;
  110. }
  111. if (m_pConsoleVerb != NULL)
  112. {
  113. m_pConsoleVerb->Release();
  114. m_pConsoleVerb = NULL;
  115. }
  116. return S_OK;
  117. }
  118. STDMETHODIMP CSnapIn::Notify(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, long arg, long param)
  119. {
  120. HRESULT hr = S_OK;
  121. switch(event)
  122. {
  123. case MMCN_DBLCLICK:
  124. hr = S_FALSE;
  125. break;
  126. case MMCN_ADD_IMAGES:
  127. HBITMAP hbmp16x16;
  128. HBITMAP hbmp32x32;
  129. hbmp16x16 = LoadBitmap(g_hInstance, MAKEINTRESOURCE(IDB_16x16));
  130. hbmp32x32 = LoadBitmap(g_hInstance, MAKEINTRESOURCE(IDB_32x32));
  131. // Set the images
  132. m_pImageResult->ImageListSetStrip(reinterpret_cast<long*>(hbmp16x16),
  133. reinterpret_cast<long*>(hbmp32x32),
  134. 0, RGB(255, 0, 255));
  135. DeleteObject(hbmp16x16);
  136. DeleteObject(hbmp32x32);
  137. break;
  138. case MMCN_SHOW:
  139. if (arg == TRUE)
  140. {
  141. RESULTDATAITEM resultItem;
  142. LPGPTDATAOBJECT pGPTDataObject;
  143. long cookie;
  144. INT i;
  145. //
  146. // Get the cookie of the scope pane item
  147. //
  148. hr = lpDataObject->QueryInterface(IID_IGPTDataObject, (LPVOID *)&pGPTDataObject);
  149. if (FAILED(hr))
  150. return S_OK;
  151. hr = pGPTDataObject->GetCookie(&cookie);
  152. pGPTDataObject->Release(); // release initial ref
  153. if (FAILED(hr))
  154. return S_OK;
  155. //
  156. // Prepare the view
  157. //
  158. m_pHeader->InsertColumn(0, m_column1, LVCFMT_LEFT, m_nColumnSize);
  159. m_pResult->SetViewMode(m_lViewMode);
  160. //
  161. // Add result pane items for this node
  162. //
  163. for (i = 0; i < g_NameSpace[cookie].cResultItems; i++)
  164. {
  165. resultItem.mask = RDI_STR | RDI_IMAGE | RDI_PARAM;
  166. resultItem.str = MMC_CALLBACK;
  167. resultItem.nImage = g_NameSpace[cookie].pResultItems[i].iImage;
  168. resultItem.lParam = (LPARAM) &g_NameSpace[cookie].pResultItems[i];
  169. m_pResult->InsertItem(&resultItem);
  170. }
  171. //m_pResult->Sort(0, 0, -1);
  172. }
  173. else
  174. {
  175. m_pHeader->GetColumnWidth(0, &m_nColumnSize);
  176. m_pResult->GetViewMode(&m_lViewMode);
  177. }
  178. break;
  179. case MMCN_SELECT:
  180. if (m_pConsoleVerb)
  181. {
  182. LPRESULTITEM pItem;
  183. LPGPTDATAOBJECT pGPTDataObject;
  184. DATA_OBJECT_TYPES type;
  185. LONG cookie;
  186. //
  187. // Set the default verb to open
  188. //
  189. m_pConsoleVerb->SetDefaultVerb(MMC_VERB_OPEN);
  190. //
  191. // See if this is one of our items.
  192. //
  193. hr = lpDataObject->QueryInterface(IID_IGPTDataObject, (LPVOID *)&pGPTDataObject);
  194. if (FAILED(hr))
  195. break;
  196. pGPTDataObject->GetType(&type);
  197. pGPTDataObject->GetCookie(&cookie);
  198. pGPTDataObject->Release();
  199. //
  200. // If this is a result pane item or the root of the namespace
  201. // nodes, enable the Properties menu item
  202. //
  203. if ((type == CCT_RESULT) || ((type == CCT_SCOPE) && (cookie == 0)))
  204. {
  205. m_pConsoleVerb->SetVerbState(MMC_VERB_PROPERTIES, ENABLED, TRUE);
  206. //
  207. // If this is a result pane item, then change the default
  208. // verb to Properties.
  209. //
  210. if (type == CCT_RESULT)
  211. m_pConsoleVerb->SetDefaultVerb(MMC_VERB_PROPERTIES);
  212. }
  213. }
  214. break;
  215. default:
  216. hr = E_UNEXPECTED;
  217. break;
  218. }
  219. return hr;
  220. }
  221. STDMETHODIMP CSnapIn::GetDisplayInfo(LPRESULTDATAITEM pResult)
  222. {
  223. if (pResult)
  224. {
  225. if (pResult->bScopeItem == TRUE)
  226. {
  227. if (pResult->mask & RDI_STR)
  228. {
  229. if (pResult->nCol == 0)
  230. pResult->str = g_NameSpace[pResult->lParam].szDisplayName;
  231. else
  232. pResult->str = L"";
  233. }
  234. if (pResult->mask & RDI_IMAGE)
  235. {
  236. pResult->nImage = 0;
  237. }
  238. }
  239. else
  240. {
  241. if (pResult->mask & RDI_STR)
  242. {
  243. if (pResult->nCol == 0)
  244. {
  245. LPRESULTITEM lpResultItem = (LPRESULTITEM)pResult->lParam;
  246. if (lpResultItem->szDisplayName[0] == TEXT('\0'))
  247. {
  248. LoadString (g_hInstance, lpResultItem->iStringID,
  249. lpResultItem->szDisplayName,
  250. MAX_DISPLAYNAME_SIZE);
  251. }
  252. pResult->str = lpResultItem->szDisplayName;
  253. }
  254. if (pResult->str == NULL)
  255. pResult->str = (LPOLESTR)L"";
  256. }
  257. }
  258. }
  259. return S_OK;
  260. }
  261. STDMETHODIMP CSnapIn::QueryDataObject(long cookie, DATA_OBJECT_TYPES type, LPDATAOBJECT *ppDataObject)
  262. {
  263. return m_pcd->QueryDataObject(cookie, type, ppDataObject);
  264. }
  265. STDMETHODIMP CSnapIn::GetResultViewType(long cookie, LPOLESTR *ppViewType,
  266. long *pViewOptions)
  267. {
  268. return S_FALSE;
  269. }
  270. STDMETHODIMP CSnapIn::CompareObjects(LPDATAOBJECT lpDataObjectA, LPDATAOBJECT lpDataObjectB)
  271. {
  272. HRESULT hr = S_FALSE;
  273. LPGPTDATAOBJECT pGPTDataObjectA, pGPTDataObjectB;
  274. LONG cookie1, cookie2;
  275. if (lpDataObjectA == NULL || lpDataObjectB == NULL)
  276. return E_POINTER;
  277. //
  278. // QI for the private GPTDataObject interface
  279. //
  280. if (FAILED(lpDataObjectA->QueryInterface(IID_IGPTDataObject,
  281. (LPVOID *)&pGPTDataObjectA)))
  282. {
  283. return S_FALSE;
  284. }
  285. if (FAILED(lpDataObjectB->QueryInterface(IID_IGPTDataObject,
  286. (LPVOID *)&pGPTDataObjectB)))
  287. {
  288. pGPTDataObjectA->Release();
  289. return S_FALSE;
  290. }
  291. pGPTDataObjectA->GetCookie(&cookie1);
  292. pGPTDataObjectB->GetCookie(&cookie2);
  293. if (cookie1 == cookie2)
  294. {
  295. hr = S_OK;
  296. }
  297. pGPTDataObjectA->Release();
  298. pGPTDataObjectB->Release();
  299. return hr;
  300. }
  301. ///////////////////////////////////////////////////////////////////////////////
  302. // //
  303. // CComponentData object implementation (IExtendPropertySheet) //
  304. // //
  305. ///////////////////////////////////////////////////////////////////////////////
  306. STDMETHODIMP CSnapIn::CreatePropertyPages(LPPROPERTYSHEETCALLBACK lpProvider,
  307. long handle, LPDATAOBJECT lpDataObject)
  308. {
  309. HRESULT hr;
  310. PROPSHEETPAGE psp;
  311. HPROPSHEETPAGE hPage[2];
  312. LPGPTDATAOBJECT pGPTDataObject;
  313. LPRESULTITEM pItem;
  314. LONG cookie;
  315. //
  316. // Make sure this is one of our objects
  317. //
  318. if (FAILED(lpDataObject->QueryInterface(IID_IGPTDataObject,
  319. (LPVOID *)&pGPTDataObject)))
  320. {
  321. return S_OK;
  322. }
  323. //
  324. // Get the cookie
  325. //
  326. pGPTDataObject->GetCookie(&cookie);
  327. pGPTDataObject->Release();
  328. pItem = (LPRESULTITEM)cookie;
  329. //
  330. // Initialize the common fields in the property sheet structure
  331. //
  332. psp.dwSize = sizeof(PROPSHEETPAGE);
  333. psp.dwFlags = 0;
  334. psp.hInstance = g_hInstance;
  335. psp.lParam = (LPARAM) this;
  336. //
  337. // Do the page specific stuff
  338. //
  339. switch (pItem->dwID)
  340. {
  341. case 2:
  342. psp.pszTemplate = MAKEINTRESOURCE(IDD_README);
  343. psp.pfnDlgProc = ReadmeDlgProc;
  344. hPage[0] = CreatePropertySheetPage(&psp);
  345. if (hPage[0])
  346. {
  347. hr = lpProvider->AddPage(hPage[0]);
  348. }
  349. else
  350. {
  351. DebugMsg((DM_WARNING, TEXT("CSnapIn::CreatePropertyPages: Failed to create property sheet page with %d."),
  352. GetLastError()));
  353. hr = E_FAIL;
  354. }
  355. break;
  356. case 3:
  357. psp.pszTemplate = MAKEINTRESOURCE(IDD_APPEAR);
  358. psp.pfnDlgProc = AppearDlgProc;
  359. hPage[0] = CreatePropertySheetPage(&psp);
  360. if (hPage[0])
  361. {
  362. hr = lpProvider->AddPage(hPage[0]);
  363. }
  364. else
  365. {
  366. DebugMsg((DM_WARNING, TEXT("CSnapIn::CreatePropertyPages: Failed to create property sheet page with %d."),
  367. GetLastError()));
  368. hr = E_FAIL;
  369. }
  370. break;
  371. }
  372. return (hr);
  373. }
  374. STDMETHODIMP CSnapIn::QueryPagesFor(LPDATAOBJECT lpDataObject)
  375. {
  376. LPGPTDATAOBJECT pGPTDataObject;
  377. DATA_OBJECT_TYPES type;
  378. if (SUCCEEDED(lpDataObject->QueryInterface(IID_IGPTDataObject,
  379. (LPVOID *)&pGPTDataObject)))
  380. {
  381. pGPTDataObject->GetType(&type);
  382. pGPTDataObject->Release();
  383. if (type == CCT_RESULT)
  384. return S_OK;
  385. }
  386. return S_FALSE;
  387. }
  388. ///////////////////////////////////////////////////////////////////////////////
  389. // //
  390. // CSnapIn object implementation (Internal functions) //
  391. // //
  392. ///////////////////////////////////////////////////////////////////////////////
  393. BOOL CALLBACK CSnapIn::ReadmeDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  394. {
  395. return FALSE;
  396. }
  397. BOOL CALLBACK CSnapIn::AppearDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  398. {
  399. CSnapIn * pCS;
  400. static BOOL bAppearDirty;
  401. HKEY hKeyRoot, hKey;
  402. DWORD dwType, dwSize, dwDisp;
  403. TCHAR szBuffer[MAX_PATH];
  404. TCHAR szPath[2 * MAX_PATH];
  405. HRESULT hr;
  406. switch (message)
  407. {
  408. case WM_INITDIALOG:
  409. {
  410. pCS = (CSnapIn *) (((LPPROPSHEETPAGE)lParam)->lParam);
  411. SetWindowLong (hDlg, DWL_USER, (LONG) pCS);
  412. if (!pCS) {
  413. break;
  414. }
  415. CheckRadioButton (hDlg, IDC_RED, IDC_DEFAULT, IDC_DEFAULT);
  416. hr = pCS->m_pcd->m_pGPTInformation->GetFileSysPath (GPO_SECTION_USER, szPath, ARRAYSIZE(szPath));
  417. if (SUCCEEDED(hr))
  418. {
  419. lstrcat (szPath, TEXT("\\gpext.ini"));
  420. GetPrivateProfileString (TEXT("Colors"), TEXT("Background"), TEXT("0 128 128"),
  421. szBuffer, MAX_PATH, szPath);
  422. if (!lstrcmpi(szBuffer, TEXT("255 0 0")))
  423. CheckRadioButton (hDlg, IDC_RED, IDC_DEFAULT, IDC_RED);
  424. else if (!lstrcmpi(szBuffer, TEXT("0 255 0")))
  425. CheckRadioButton (hDlg, IDC_RED, IDC_DEFAULT, IDC_GREEN);
  426. else if (!lstrcmpi(szBuffer, TEXT("0 0 255")))
  427. CheckRadioButton (hDlg, IDC_RED, IDC_DEFAULT, IDC_BLUE);
  428. else if (!lstrcmpi(szBuffer, TEXT("0 0 0")))
  429. CheckRadioButton (hDlg, IDC_RED, IDC_DEFAULT, IDC_BLACK);
  430. else if (!lstrcmpi(szBuffer, TEXT("160 160 164")))
  431. CheckRadioButton (hDlg, IDC_RED, IDC_DEFAULT, IDC_GRAY);
  432. GetPrivateProfileString (TEXT("Desktop"), TEXT("Wallpaper"), TEXT("(None)"),
  433. szBuffer, MAX_PATH, szPath);
  434. SetDlgItemText (hDlg, IDC_WALLPAPER, szBuffer);
  435. GetPrivateProfileString (TEXT("Desktop"), TEXT("TileWallpaper"), TEXT("0"),
  436. szBuffer, MAX_PATH, szPath);
  437. if (szBuffer[0] == TEXT('1'))
  438. CheckRadioButton (hDlg, IDC_TILE, IDC_CENTER, IDC_TILE);
  439. else
  440. CheckRadioButton (hDlg, IDC_TILE, IDC_CENTER, IDC_CENTER);
  441. }
  442. bAppearDirty = FALSE;
  443. break;
  444. }
  445. case WM_COMMAND:
  446. if ((HIWORD(wParam) == BN_CLICKED) || (HIWORD(wParam) == EN_UPDATE))
  447. {
  448. if (!bAppearDirty)
  449. {
  450. SendMessage (GetParent(hDlg), PSM_CHANGED, (WPARAM) hDlg, 0);
  451. bAppearDirty = TRUE;
  452. }
  453. }
  454. break;
  455. case WM_NOTIFY:
  456. pCS = (CSnapIn *) GetWindowLong (hDlg, DWL_USER);
  457. if (!pCS) {
  458. break;
  459. }
  460. switch (((NMHDR FAR*)lParam)->code)
  461. {
  462. case PSN_APPLY:
  463. {
  464. if (bAppearDirty)
  465. {
  466. hr = pCS->m_pcd->m_pGPTInformation->GetFileSysPath (GPO_SECTION_USER, szPath, ARRAYSIZE(szPath));
  467. if (SUCCEEDED(hr))
  468. {
  469. lstrcat (szPath, TEXT("\\gpext.ini"));
  470. lstrcpy (szBuffer, TEXT("0 128 128"));
  471. if (IsDlgButtonChecked (hDlg, IDC_RED) == BST_CHECKED)
  472. lstrcpy (szBuffer, TEXT("255 0 0"));
  473. else if (IsDlgButtonChecked (hDlg, IDC_GREEN) == BST_CHECKED)
  474. lstrcpy (szBuffer, TEXT("0 255 0"));
  475. else if (IsDlgButtonChecked (hDlg, IDC_BLUE) == BST_CHECKED)
  476. lstrcpy (szBuffer, TEXT("0 0 255"));
  477. else if (IsDlgButtonChecked (hDlg, IDC_BLACK) == BST_CHECKED)
  478. lstrcpy (szBuffer, TEXT("0 0 0"));
  479. else if (IsDlgButtonChecked (hDlg, IDC_GRAY) == BST_CHECKED)
  480. lstrcpy (szBuffer, TEXT("160 160 164"));
  481. WritePrivateProfileString (TEXT("Colors"), TEXT("Background"), szBuffer, szPath);
  482. lstrcpy (szBuffer, TEXT("(None)"));
  483. GetDlgItemText (hDlg, IDC_WALLPAPER, szBuffer, MAX_PATH);
  484. WritePrivateProfileString (TEXT("Desktop"), TEXT("Wallpaper"), szBuffer, szPath);
  485. if (IsDlgButtonChecked (hDlg, IDC_TILE) == BST_CHECKED)
  486. lstrcpy (szBuffer, TEXT("1"));
  487. else
  488. lstrcpy (szBuffer, TEXT("0"));
  489. WritePrivateProfileString (TEXT("Desktop"), TEXT("TileWallpaper"), szBuffer, szPath);
  490. bAppearDirty = FALSE;
  491. pCS->m_pcd->m_pGPTInformation->PolicyChanged(FALSE, TRUE, &guidGPExt, &guidSnapin);
  492. }
  493. }
  494. }
  495. // fall through...
  496. case PSN_RESET:
  497. SetWindowLong (hDlg, DWL_MSGRESULT, PSNRET_NOERROR);
  498. return TRUE;
  499. }
  500. break;
  501. }
  502. return FALSE;
  503. }