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.

270 lines
7.6 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 "Space.h"
  20. #include "Comp.h"
  21. #include <stdio.h>
  22. const GUID CSpaceVehicle::thisGuid = { 0x29743810, 0x4c4b, 0x11d2, { 0x89, 0xd8, 0x0, 0x0, 0x21, 0x47, 0x31, 0x28 } };
  23. const GUID CRocket::thisGuid = { 0x29743811, 0x4c4b, 0x11d2, { 0x89, 0xd8, 0x0, 0x0, 0x21, 0x47, 0x31, 0x28 } };
  24. //==============================================================
  25. //
  26. // CSpaceVehicle implementation
  27. //
  28. //
  29. CSpaceVehicle::CSpaceVehicle()
  30. {
  31. for (int n = 0; n < NUMBER_OF_CHILDREN; n++) {
  32. children[n] = new CRocket();
  33. children[n]->Initialize(_T("Vehicle"), 500000, 265, 75000);
  34. }
  35. }
  36. CSpaceVehicle::~CSpaceVehicle()
  37. {
  38. for (int n = 0; n < NUMBER_OF_CHILDREN; n++)
  39. if (children[n]) {
  40. delete children[n];
  41. }
  42. }
  43. HRESULT CSpaceVehicle::OnShow(IConsole *pConsole, BOOL bShow, HSCOPEITEM scopeitem)
  44. {
  45. HRESULT hr = S_OK;
  46. IHeaderCtrl *pHeaderCtrl = NULL;
  47. IResultData *pResultData = NULL;
  48. if (bShow) {
  49. hr = pConsole->QueryInterface(IID_IHeaderCtrl, (void **)&pHeaderCtrl);
  50. _ASSERT( SUCCEEDED(hr) );
  51. hr = pConsole->QueryInterface(IID_IResultData, (void **)&pResultData);
  52. _ASSERT( SUCCEEDED(hr) );
  53. // Set the column headers in the results pane
  54. hr = pHeaderCtrl->InsertColumn( 0, L"Rocket Class", 0, MMCLV_AUTO );
  55. _ASSERT( S_OK == hr );
  56. hr = pHeaderCtrl->InsertColumn( 1, L"Rocket Weight", 0, MMCLV_AUTO );
  57. _ASSERT( S_OK == hr );
  58. hr = pHeaderCtrl->InsertColumn( 2, L"Rocket Height", 0, MMCLV_AUTO );
  59. _ASSERT( S_OK == hr );
  60. hr = pHeaderCtrl->InsertColumn( 3, L"Rocket Payload", 0, MMCLV_AUTO );
  61. _ASSERT( S_OK == hr );
  62. hr = pHeaderCtrl->InsertColumn( 4, L"Status", 0, MMCLV_AUTO );
  63. _ASSERT( S_OK == hr );
  64. // insert items here
  65. RESULTDATAITEM rdi;
  66. hr = pResultData->DeleteAllRsltItems();
  67. _ASSERT( SUCCEEDED(hr) );
  68. if (!bExpanded) {
  69. // create the child nodes, then expand them
  70. for (int n = 0; n < NUMBER_OF_CHILDREN; n++) {
  71. ZeroMemory(&rdi, sizeof(RESULTDATAITEM) );
  72. rdi.mask = RDI_STR | // Displayname is valid
  73. RDI_IMAGE |
  74. RDI_PARAM; // nImage is valid
  75. rdi.nImage = children[n]->GetBitmapIndex();
  76. rdi.str = MMC_CALLBACK;
  77. rdi.nCol = 0;
  78. rdi.lParam = (LPARAM)children[n];
  79. hr = pResultData->InsertItem( &rdi );
  80. _ASSERT( SUCCEEDED(hr) );
  81. }
  82. }
  83. pHeaderCtrl->Release();
  84. pResultData->Release();
  85. }
  86. return hr;
  87. }
  88. HRESULT CSpaceVehicle::OnAddMenuItems(IContextMenuCallback *pContextMenuCallback, long *pInsertionsAllowed)
  89. {
  90. HRESULT hr = S_OK;
  91. CONTEXTMENUITEM menuItemsNew[] =
  92. {
  93. {
  94. L"Space based", L"Add a new space based vehicle",
  95. IDM_NEW_SPACE, CCM_INSERTIONPOINTID_PRIMARY_NEW, 0, CCM_SPECIAL_DEFAULT_ITEM
  96. },
  97. { NULL, NULL, 0, 0, 0 }
  98. };
  99. // Loop through and add each of the menu items
  100. if (*pInsertionsAllowed & CCM_INSERTIONALLOWED_NEW)
  101. {
  102. for (LPCONTEXTMENUITEM m = menuItemsNew; m->strName; m++)
  103. {
  104. hr = pContextMenuCallback->AddItem(m);
  105. if (FAILED(hr))
  106. break;
  107. }
  108. }
  109. return hr;
  110. }
  111. HRESULT CSpaceVehicle::OnMenuCommand(IConsole *pConsole, long lCommandID)
  112. {
  113. switch (lCommandID)
  114. {
  115. case IDM_NEW_SPACE:
  116. pConsole->MessageBox(L"This sample does not create a new item\nSee Complete sample for a demonstration", L"Menu Command", MB_OK|MB_ICONINFORMATION, NULL);
  117. break;
  118. }
  119. return S_OK;
  120. }
  121. //==============================================================
  122. //
  123. // CRocket implementation
  124. //
  125. //
  126. CRocket::CRocket()
  127. : szName(NULL), lWeight(0), lHeight(0), lPayload(0), iStatus(STOPPED)
  128. {
  129. }
  130. CRocket::~CRocket()
  131. {
  132. if (szName)
  133. delete [] szName;
  134. }
  135. void CRocket::Initialize(_TCHAR *szName, LONG lWeight, LONG lHeight, LONG lPayload)
  136. {
  137. if (szName) {
  138. this->szName = new _TCHAR[_tcslen(szName) + 1];
  139. _tcscpy(this->szName, szName);
  140. }
  141. this->lWeight = lWeight;
  142. this->lHeight = lHeight;
  143. this->lPayload = lPayload;
  144. }
  145. const _TCHAR *CRocket::GetDisplayName(int nCol)
  146. {
  147. static _TCHAR buf[128];
  148. switch (nCol) {
  149. case 0:
  150. _tcscpy(buf, szName ? szName : _T(""));
  151. break;
  152. case 1:
  153. _stprintf(buf, _T("%ld metric tons"), lWeight);
  154. break;
  155. case 2:
  156. _stprintf(buf, _T("%ld meters"), lHeight);
  157. break;
  158. case 3:
  159. _stprintf(buf, _T("%ld kilos"), lPayload);
  160. break;
  161. case 4:
  162. _stprintf(buf, _T("%s"),
  163. iStatus == RUNNING ? _T("running") :
  164. iStatus == PAUSED ? _T("paused") :
  165. iStatus == STOPPED ? _T("stopped") : _T("unknown"));
  166. break;
  167. }
  168. return buf;
  169. }
  170. HRESULT CRocket::OnAddMenuItems(IContextMenuCallback *pContextMenuCallback, long *pInsertionsAllowed)
  171. {
  172. HRESULT hr = S_OK;
  173. CONTEXTMENUITEM menuItemsTask[] =
  174. {
  175. {
  176. L"Start vehicle", L"Start the space vehicle",
  177. IDM_START_SPACE, CCM_INSERTIONPOINTID_PRIMARY_TASK, 0, CCM_SPECIAL_DEFAULT_ITEM
  178. },
  179. {
  180. L"Pause vehicle", L"Pause the space vehicle",
  181. IDM_PAUSE_SPACE, CCM_INSERTIONPOINTID_PRIMARY_TASK, 0, 0
  182. },
  183. {
  184. L"Stop vehicle", L"Stop the space vehicle",
  185. IDM_STOP_SPACE, CCM_INSERTIONPOINTID_PRIMARY_TASK, 0, 0
  186. },
  187. { NULL, NULL, 0, 0, 0 }
  188. };
  189. // Loop through and add each of the menu items
  190. if (*pInsertionsAllowed & CCM_INSERTIONALLOWED_TASK)
  191. {
  192. for (LPCONTEXTMENUITEM m = menuItemsTask; m->strName; m++)
  193. {
  194. hr = pContextMenuCallback->AddItem(m);
  195. if (FAILED(hr))
  196. break;
  197. }
  198. }
  199. return hr;
  200. }
  201. HRESULT CRocket::OnMenuCommand(IConsole *pConsole, long lCommandID)
  202. {
  203. _TCHAR szVehicle[128];
  204. switch (lCommandID) {
  205. case IDM_START_SPACE:
  206. iStatus = RUNNING;
  207. break;
  208. case IDM_PAUSE_SPACE:
  209. iStatus = PAUSED;
  210. break;
  211. case IDM_STOP_SPACE:
  212. iStatus = STOPPED;
  213. break;
  214. }
  215. _stprintf(szVehicle, _T("%s has been %s"), szName,
  216. (long)iStatus == RUNNING ? _T("started") :
  217. (long)iStatus == PAUSED ? _T("paused") :
  218. (long)iStatus == STOPPED ? _T("stopped") : _T("!!!unknown command!!!"));
  219. MAKE_WIDEPTR_FROMTSTR(ptrname, szVehicle);
  220. int ret = 0;
  221. pConsole->MessageBox(ptrname,
  222. L"Vehicle command", MB_OK | MB_ICONINFORMATION, &ret);
  223. return S_OK;
  224. }