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.

289 lines
8.8 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 <stdio.h>
  20. #include <windows.h>
  21. #include "Space.h"
  22. #include "Comp.h"
  23. #include "resource.h"
  24. const GUID CSpaceVehicle::thisGuid = { 0x29743810, 0x4c4b, 0x11d2, { 0x89, 0xd8, 0x0, 0x0, 0x21, 0x47, 0x31, 0x28 } };
  25. const GUID CRocket::thisGuid = { 0x29743811, 0x4c4b, 0x11d2, { 0x89, 0xd8, 0x0, 0x0, 0x21, 0x47, 0x31, 0x28 } };
  26. //==============================================================
  27. //
  28. // CSpaceVehicle implementation
  29. //
  30. //
  31. CSpaceVehicle::CSpaceVehicle()
  32. {
  33. for (int n = 0; n < NUMBER_OF_CHILDREN; n++) {
  34. children[n] = new CRocket(_T("Rocket"), n+1, 500000, 265, 75000);
  35. }
  36. }
  37. CSpaceVehicle::~CSpaceVehicle()
  38. {
  39. for (int n = 0; n < NUMBER_OF_CHILDREN; n++)
  40. if (children[n]) {
  41. delete children[n];
  42. }
  43. }
  44. HRESULT CSpaceVehicle::OnShow(IConsole *pConsole, BOOL bShow, HSCOPEITEM scopeitem)
  45. {
  46. HRESULT hr = S_OK;
  47. IHeaderCtrl *pHeaderCtrl = NULL;
  48. IResultData *pResultData = NULL;
  49. if (bShow) {
  50. hr = pConsole->QueryInterface(IID_IHeaderCtrl, (void **)&pHeaderCtrl);
  51. _ASSERT( SUCCEEDED(hr) );
  52. hr = pConsole->QueryInterface(IID_IResultData, (void **)&pResultData);
  53. _ASSERT( SUCCEEDED(hr) );
  54. // Set the column headers in the results pane
  55. hr = pHeaderCtrl->InsertColumn( 0, L"Rocket Class", 0, MMCLV_AUTO );
  56. _ASSERT( S_OK == hr );
  57. hr = pHeaderCtrl->InsertColumn( 1, L"Rocket Weight", 0, MMCLV_AUTO );
  58. _ASSERT( S_OK == hr );
  59. hr = pHeaderCtrl->InsertColumn( 2, L"Rocket Height", 0, MMCLV_AUTO );
  60. _ASSERT( S_OK == hr );
  61. hr = pHeaderCtrl->InsertColumn( 3, L"Rocket Payload", 0, MMCLV_AUTO );
  62. _ASSERT( S_OK == hr );
  63. hr = pHeaderCtrl->InsertColumn( 4, L"Status", 0, MMCLV_AUTO );
  64. _ASSERT( S_OK == hr );
  65. // insert items here
  66. RESULTDATAITEM rdi;
  67. hr = pResultData->DeleteAllRsltItems();
  68. _ASSERT( SUCCEEDED(hr) );
  69. if (!bExpanded) {
  70. // create the child nodes, then expand them
  71. for (int n = 0; n < NUMBER_OF_CHILDREN; n++) {
  72. ZeroMemory(&rdi, sizeof(RESULTDATAITEM) );
  73. rdi.mask = RDI_STR | // Displayname is valid
  74. RDI_IMAGE |
  75. RDI_PARAM; // nImage is valid
  76. rdi.nImage = children[n]->GetBitmapIndex();
  77. rdi.str = MMC_CALLBACK;
  78. rdi.nCol = 0;
  79. rdi.lParam = (LPARAM)children[n];
  80. hr = pResultData->InsertItem( &rdi );
  81. children[n]->SetHandle((HANDLE)rdi.itemID);
  82. _ASSERT( SUCCEEDED(hr) );
  83. }
  84. }
  85. pHeaderCtrl->Release();
  86. pResultData->Release();
  87. }
  88. return hr;
  89. }
  90. //==============================================================
  91. //
  92. // CRocket implementation
  93. //
  94. //
  95. CRocket::CRocket(_TCHAR *szName, int id, LONG lWeight, LONG lHeight, LONG lPayload)
  96. : szName(NULL), lWeight(0), lHeight(0), lPayload(0), iStatus(STOPPED)
  97. {
  98. if (szName) {
  99. this->szName = new _TCHAR[(_tcslen(szName) + 1) * sizeof(_TCHAR)];
  100. _tcscpy(this->szName, szName);
  101. }
  102. this->nId = id;
  103. this->lWeight = lWeight;
  104. this->lHeight = lHeight;
  105. this->lPayload = lPayload;
  106. }
  107. CRocket::~CRocket()
  108. {
  109. if (szName)
  110. delete [] szName;
  111. }
  112. const _TCHAR *CRocket::GetDisplayName(int nCol)
  113. {
  114. static _TCHAR buf[128];
  115. switch (nCol) {
  116. case 0:
  117. _stprintf(buf, _T("%s (#%d)"), szName ? szName : _T(""), nId);
  118. break;
  119. case 1:
  120. _stprintf(buf, _T("%ld metric tons"), lWeight);
  121. break;
  122. case 2:
  123. _stprintf(buf, _T("%ld meters"), lHeight);
  124. break;
  125. case 3:
  126. _stprintf(buf, _T("%ld kilos"), lPayload);
  127. break;
  128. case 4:
  129. _stprintf(buf, _T("%s"),
  130. iStatus == RUNNING ? _T("running") :
  131. iStatus == PAUSED ? _T("paused") :
  132. iStatus == STOPPED ? _T("stopped") : _T("unknown"));
  133. break;
  134. }
  135. return buf;
  136. }
  137. HRESULT CRocket::OnRename(LPOLESTR pszNewName)
  138. {
  139. if (szName) {
  140. delete [] szName;
  141. szName = NULL;
  142. }
  143. MAKE_TSTRPTR_FROMWIDE(ptrname, pszNewName);
  144. szName = new _TCHAR[(_tcslen(ptrname) + 1) * sizeof(_TCHAR)];
  145. _tcscpy(szName, ptrname);
  146. return S_OK;
  147. }
  148. HRESULT CRocket::OnSelect(IConsole *pConsole, BOOL bScope, BOOL bSelect)
  149. {
  150. IConsoleVerb *pConsoleVerb;
  151. HRESULT hr = pConsole->QueryConsoleVerb(&pConsoleVerb);
  152. _ASSERT(SUCCEEDED(hr));
  153. hr = pConsoleVerb->SetVerbState(MMC_VERB_RENAME, ENABLED, TRUE);
  154. hr = pConsoleVerb->SetVerbState(MMC_VERB_PROPERTIES, ENABLED, TRUE);
  155. pConsoleVerb->Release();
  156. return S_OK;
  157. }
  158. BOOL CALLBACK CRocket::DialogProc(
  159. HWND hwndDlg, // handle to dialog box
  160. UINT uMsg, // message
  161. WPARAM wParam, // first message parameter
  162. LPARAM lParam // second message parameter
  163. )
  164. {
  165. static CRocket *pRocket = NULL;
  166. switch (uMsg) {
  167. case WM_INITDIALOG:
  168. pRocket = reinterpret_cast<CRocket *>(reinterpret_cast<PROPSHEETPAGE *>(lParam)->lParam);
  169. SetDlgItemText(hwndDlg, IDC_ROCKET_NAME, pRocket->szName);
  170. SetDlgItemInt(hwndDlg, IDC_ROCKET_HEIGHT, pRocket->lHeight, FALSE);
  171. SetDlgItemInt(hwndDlg, IDC_ROCKET_WEIGHT, pRocket->lWeight, FALSE);
  172. SetDlgItemInt(hwndDlg, IDC_ROCKET_PAYLOAD, pRocket->lPayload, FALSE);
  173. _ASSERT( CB_ERR != SendDlgItemMessage(hwndDlg, IDC_ROCKET_STATUS, CB_INSERTSTRING, 0, (LPARAM)_T("Running")) );
  174. _ASSERT( CB_ERR != SendDlgItemMessage(hwndDlg, IDC_ROCKET_STATUS, CB_INSERTSTRING, 1, (LPARAM)_T("Paused")) );
  175. _ASSERT( CB_ERR != SendDlgItemMessage(hwndDlg, IDC_ROCKET_STATUS, CB_INSERTSTRING, 2, (LPARAM)_T("Stopped")) );
  176. SendDlgItemMessage(hwndDlg, IDC_ROCKET_STATUS, CB_SETCURSEL, (WPARAM)pRocket->iStatus, 0);
  177. break;
  178. case WM_COMMAND:
  179. if (HIWORD(wParam) == EN_CHANGE ||
  180. HIWORD(wParam) == CBN_SELCHANGE)
  181. SendMessage(GetParent(hwndDlg), PSM_CHANGED, (WPARAM)hwndDlg, 0);
  182. break;
  183. case WM_NOTIFY:
  184. switch (((NMHDR *) lParam)->code) {
  185. case PSN_APPLY:
  186. if (pRocket->szName) {
  187. delete [] pRocket->szName;
  188. pRocket->szName = NULL;
  189. }
  190. {
  191. int n = SendDlgItemMessage(hwndDlg, IDC_ROCKET_NAME, WM_GETTEXTLENGTH, 0, 0);
  192. if (n != 0) {
  193. pRocket->szName = new _TCHAR[n + 1];
  194. GetDlgItemText(hwndDlg, IDC_ROCKET_NAME, pRocket->szName, n + 1);
  195. }
  196. }
  197. pRocket->lHeight = GetDlgItemInt(hwndDlg, IDC_ROCKET_HEIGHT, NULL, FALSE);
  198. pRocket->lWeight = GetDlgItemInt(hwndDlg, IDC_ROCKET_WEIGHT, NULL, FALSE);
  199. pRocket->lPayload = GetDlgItemInt(hwndDlg, IDC_ROCKET_PAYLOAD, NULL, FALSE);
  200. pRocket->iStatus = (ROCKET_STATUS)SendDlgItemMessage(hwndDlg, IDC_ROCKET_STATUS, CB_GETCURSEL, 0, 0);
  201. return PSNRET_NOERROR;
  202. }
  203. break;
  204. }
  205. return DefWindowProc(hwndDlg, uMsg, wParam, lParam);
  206. }
  207. HRESULT CRocket::HasPropertySheets()
  208. {
  209. return S_OK;
  210. }
  211. HRESULT CRocket::CreatePropertyPages(IPropertySheetCallback *lpProvider, LONG_PTR handle)
  212. {
  213. PROPSHEETPAGE psp;
  214. HPROPSHEETPAGE hPage = NULL;
  215. psp.dwSize = sizeof(PROPSHEETPAGE);
  216. psp.dwFlags = PSP_DEFAULT | PSP_USETITLE | PSP_USEICONID;
  217. psp.hInstance = g_hinst;
  218. psp.pszTemplate = MAKEINTRESOURCE(IDD_PROPPAGE_LARGE);
  219. psp.pfnDlgProc = DialogProc;
  220. psp.lParam = reinterpret_cast<LPARAM>(this);
  221. psp.pszTitle = MAKEINTRESOURCE(IDS_PST_ROCKET);
  222. psp.pszIcon = MAKEINTRESOURCE(IDI_PSI_ROCKET);
  223. hPage = CreatePropertySheetPage(&psp);
  224. _ASSERT(hPage);
  225. return lpProvider->AddPage(hPage);
  226. }
  227. HRESULT CRocket::GetWatermarks(HBITMAP *lphWatermark,
  228. HBITMAP *lphHeader,
  229. HPALETTE *lphPalette,
  230. BOOL *bStretch)
  231. {
  232. return S_FALSE;
  233. }