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.

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