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.

240 lines
8.4 KiB

  1. //==============================================================;
  2. //
  3. // This source code is only intended as a supplement to
  4. // existing Microsoft documentation.
  5. //
  6. //
  7. //
  8. //
  9. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  10. // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  11. // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  12. // PURPOSE.
  13. //
  14. // Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  15. //
  16. //
  17. //
  18. //==============================================================;
  19. #include <Shlwapi.h>
  20. #include <Shlobj.H>
  21. #include "StatNode.h"
  22. #include "Space.h"
  23. #include "Sky.h"
  24. #include "People.h"
  25. #include "Land.h"
  26. const GUID CStaticNode::thisGuid = { 0x2974380c, 0x4c4b, 0x11d2, { 0x89, 0xd8, 0x0, 0x0, 0x21, 0x47, 0x31, 0x28 } };
  27. //==============================================================
  28. //
  29. // CStaticNode implementation
  30. //
  31. //
  32. CStaticNode::CStaticNode()
  33. {
  34. children[0] = new CPeoplePoweredVehicle;
  35. children[1] = new CLandBasedVehicle;
  36. children[2] = new CSkyBasedVehicle;
  37. children[3] = new CSpaceVehicle;
  38. }
  39. CStaticNode::~CStaticNode()
  40. {
  41. for (int n = 0; n < NUMBER_OF_CHILDREN; n++)
  42. if (children[n]) {
  43. delete children[n];
  44. }
  45. }
  46. HRESULT CStaticNode::OnExpand(IConsoleNameSpace *pConsoleNameSpace, IConsole *pConsole, HSCOPEITEM parent)
  47. {
  48. SCOPEDATAITEM sdi;
  49. if (GetHandle() == NULL) {
  50. SetHandle((HANDLE)parent);
  51. }
  52. if (!bExpanded) {
  53. // create the child nodes, then expand them
  54. for (int n = 0; n < NUMBER_OF_CHILDREN; n++) {
  55. ZeroMemory(&sdi, sizeof(SCOPEDATAITEM) );
  56. sdi.mask = SDI_STR | // Displayname is valid
  57. SDI_PARAM | // lParam is valid
  58. SDI_IMAGE | // nImage is valid
  59. SDI_OPENIMAGE | // nOpenImage is valid
  60. SDI_PARENT |
  61. SDI_CHILDREN;
  62. sdi.relativeID = (HSCOPEITEM)parent;
  63. sdi.nImage = children[n]->GetBitmapIndex();
  64. sdi.nOpenImage = INDEX_OPENFOLDER;
  65. sdi.displayname = MMC_CALLBACK;
  66. sdi.lParam = (LPARAM)children[n]; // The cookie
  67. sdi.cChildren = (n == 0); // only the first child has children
  68. HRESULT hr = pConsoleNameSpace->InsertItem( &sdi );
  69. children[n]->SetHandle((HANDLE)sdi.ID);
  70. _ASSERT( SUCCEEDED(hr) );
  71. }
  72. }
  73. return S_OK;
  74. }
  75. HRESULT CStaticNode::CreatePropertyPages(IPropertySheetCallback *lpProvider, LONG_PTR handle)
  76. {
  77. PROPSHEETPAGE psp;
  78. HPROPSHEETPAGE hPage = NULL;
  79. psp.dwSize = sizeof(PROPSHEETPAGE);
  80. psp.dwFlags = PSP_DEFAULT;
  81. psp.hInstance = g_hinst;
  82. psp.pszTemplate = MAKEINTRESOURCE(IDD_CHOOSER_CHOOSE_MACHINE);
  83. psp.pfnDlgProc = DialogProc;
  84. psp.lParam = reinterpret_cast<LPARAM>(&snapInData);
  85. psp.pszTitle = MAKEINTRESOURCE(IDS_SELECT_COMPUTER);
  86. hPage = CreatePropertySheetPage(&psp);
  87. _ASSERT(hPage);
  88. return lpProvider->AddPage(hPage);
  89. }
  90. HRESULT CStaticNode::HasPropertySheets()
  91. {
  92. return S_OK;
  93. }
  94. HRESULT CStaticNode::GetWatermarks(HBITMAP *lphWatermark,
  95. HBITMAP *lphHeader,
  96. HPALETTE *lphPalette,
  97. BOOL *bStretch)
  98. {
  99. *lphHeader = (HBITMAP)LoadImage(g_hinst, MAKEINTRESOURCE(IDB_HEADER), IMAGE_BITMAP, 0, 0, 0);
  100. *lphWatermark = (HBITMAP)LoadImage(g_hinst, MAKEINTRESOURCE(IDB_WATERMARK), IMAGE_BITMAP, 0, 0, 0);
  101. *bStretch = FALSE;
  102. return S_OK;
  103. }
  104. BOOL CALLBACK CStaticNode::DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  105. {
  106. static privateData *pData = NULL;
  107. static HWND m_hwndCheckboxOverride;
  108. switch (uMsg)
  109. {
  110. case WM_INITDIALOG:
  111. pData = reinterpret_cast<privateData *>(reinterpret_cast<PROPSHEETPAGE *>(lParam)->lParam);
  112. SendDlgItemMessage(hwndDlg, IDC_CHOOSER_RADIO_LOCAL_MACHINE, BM_SETCHECK, pData->m_fIsRadioLocalMachine, 0L);
  113. SendDlgItemMessage(hwndDlg, IDC_CHOOSER_RADIO_SPECIFIC_MACHINE, BM_SETCHECK, !pData->m_fIsRadioLocalMachine, 0L);
  114. EnableWindow(GetDlgItem(hwndDlg, IDC_CHOOSER_EDIT_MACHINE_NAME), !pData->m_fIsRadioLocalMachine);
  115. EnableWindow(GetDlgItem(hwndDlg, IDC_CHOOSER_BUTTON_BROWSE_MACHINENAMES), !pData->m_fIsRadioLocalMachine);
  116. m_hwndCheckboxOverride = ::GetDlgItem(hwndDlg, IDC_CHOOSER_CHECK_OVERRIDE_MACHINE_NAME);
  117. // fill in the supplied machine name (could be us, need to check here first)
  118. if (*pData->m_host != '\0')
  119. {
  120. ::SetWindowText(GetDlgItem(hwndDlg, IDC_CHOOSER_EDIT_MACHINE_NAME), pData->m_host);
  121. ::SendMessage(GetDlgItem(hwndDlg, IDC_CHOOSER_RADIO_SPECIFIC_MACHINE), BM_CLICK, 0, 0);
  122. }
  123. return TRUE;
  124. case WM_COMMAND:
  125. switch (wParam)
  126. {
  127. case IDC_CHOOSER_RADIO_LOCAL_MACHINE:
  128. pData->m_fIsRadioLocalMachine = TRUE;
  129. EnableWindow(GetDlgItem(hwndDlg, IDC_CHOOSER_EDIT_MACHINE_NAME), FALSE);
  130. EnableWindow(GetDlgItem(hwndDlg, IDC_CHOOSER_BUTTON_BROWSE_MACHINENAMES), FALSE);
  131. break;
  132. case IDC_CHOOSER_RADIO_SPECIFIC_MACHINE:
  133. pData->m_fIsRadioLocalMachine = FALSE;
  134. EnableWindow(GetDlgItem(hwndDlg, IDC_CHOOSER_EDIT_MACHINE_NAME), TRUE);
  135. EnableWindow(GetDlgItem(hwndDlg, IDC_CHOOSER_BUTTON_BROWSE_MACHINENAMES), TRUE);
  136. break;
  137. case IDC_CHOOSER_BUTTON_BROWSE_MACHINENAMES:
  138. {
  139. // Fall back to IE-style browser
  140. BROWSEINFO bi;
  141. LPITEMIDLIST lpItemIdList;
  142. LPMALLOC lpMalloc;
  143. if (SUCCEEDED(SHGetSpecialFolderLocation(hwndDlg, CSIDL_NETWORK, &lpItemIdList)))
  144. {
  145. _TCHAR szBrowserCaption[MAX_PATH];
  146. LoadString(g_hinst, IDS_COMPUTER_BROWSER_CAPTION, szBrowserCaption, sizeof(szBrowserCaption));
  147. bi.hwndOwner = hwndDlg;
  148. bi.pidlRoot = lpItemIdList;
  149. bi.pszDisplayName = pData->m_host;
  150. bi.lpszTitle = szBrowserCaption;
  151. bi.ulFlags = BIF_BROWSEFORCOMPUTER | BIF_EDITBOX;
  152. bi.lpfn = NULL;
  153. bi.lParam = NULL;
  154. bi.iImage = NULL;
  155. if (SHBrowseForFolder(&bi) != NULL)
  156. {
  157. if (*pData->m_host != '\0')
  158. {
  159. ::SetWindowText(GetDlgItem(hwndDlg,
  160. IDC_CHOOSER_EDIT_MACHINE_NAME), pData->m_host);
  161. }
  162. }
  163. if (SUCCEEDED(SHGetMalloc(&lpMalloc)))
  164. {
  165. lpMalloc->Free(lpItemIdList);
  166. lpMalloc->Release();
  167. }
  168. }
  169. }
  170. break;
  171. case IDC_CHOOSER_CHECK_OVERRIDE_MACHINE_NAME:
  172. break;
  173. }
  174. break;
  175. case WM_NOTIFY:
  176. switch (((LPNMHDR)lParam)->code) {
  177. case PSN_SETACTIVE:
  178. PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_FINISH);
  179. break;
  180. case PSN_WIZFINISH:
  181. if (pData->m_fIsRadioLocalMachine) {
  182. // Return empty string to caller
  183. *pData->m_host = '\0';
  184. } else {
  185. // Get the machine name from the edit window
  186. GetWindowText(GetDlgItem(hwndDlg, IDC_CHOOSER_EDIT_MACHINE_NAME),
  187. pData->m_host, sizeof(pData->m_host));
  188. }
  189. // Save the override flag if the caller asked for it
  190. pData->m_fAllowOverrideMachineNameOut =
  191. SendMessage(m_hwndCheckboxOverride, BM_GETCHECK, 0, 0) == BST_CHECKED ? TRUE : FALSE;
  192. break;
  193. }
  194. break;
  195. }
  196. return FALSE;
  197. }