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.

274 lines
8.2 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 "Space.h"
  21. #include "Comp.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. //==============================================================
  89. //
  90. // CRocket implementation
  91. //
  92. //
  93. CRocket::CRocket()
  94. : szName(NULL), lWeight(0), lHeight(0), lPayload(0), iStatus(STOPPED)
  95. {
  96. }
  97. CRocket::~CRocket()
  98. {
  99. if (szName)
  100. delete [] szName;
  101. }
  102. void CRocket::Initialize(_TCHAR *szName, LONG lWeight, LONG lHeight, LONG lPayload)
  103. {
  104. if (szName) {
  105. this->szName = new _TCHAR[_tcslen(szName) + 1];
  106. _tcscpy(this->szName, szName);
  107. }
  108. this->lWeight = lWeight;
  109. this->lHeight = lHeight;
  110. this->lPayload = lPayload;
  111. }
  112. const _TCHAR *CRocket::GetDisplayName(int nCol)
  113. {
  114. static _TCHAR buf[128];
  115. switch (nCol) {
  116. case 0:
  117. _tcscpy(buf, szName ? szName : _T(""));
  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. HMENU CRocket::GetMenu(int nMenuId)
  138. {
  139. HMENU hResMenu = LoadMenu(g_hinst, MAKEINTRESOURCE(nMenuId));
  140. HMENU hMenu = GetSubMenu(hResMenu,0);
  141. if (IDR_STATE_MENU == nMenuId) {
  142. switch (iStatus)
  143. {
  144. case RUNNING:
  145. EnableMenuItem(hMenu, ID_COMMAND_START, MF_BYCOMMAND | MF_GRAYED);
  146. EnableMenuItem(hMenu, ID_COMMAND_PAUSE, MF_BYCOMMAND | MF_ENABLED);
  147. EnableMenuItem(hMenu, ID_COMMAND_STOP, MF_BYCOMMAND | MF_ENABLED);
  148. break;
  149. case PAUSED:
  150. EnableMenuItem(hMenu, ID_COMMAND_START, MF_BYCOMMAND | MF_ENABLED);
  151. EnableMenuItem(hMenu, ID_COMMAND_PAUSE, MF_BYCOMMAND | MF_GRAYED);
  152. EnableMenuItem(hMenu, ID_COMMAND_STOP, MF_BYCOMMAND | MF_ENABLED);
  153. break;
  154. case STOPPED:
  155. EnableMenuItem(hMenu, ID_COMMAND_START, MF_BYCOMMAND | MF_ENABLED);
  156. EnableMenuItem(hMenu, ID_COMMAND_START, MF_BYCOMMAND | MF_ENABLED);
  157. EnableMenuItem(hMenu, ID_COMMAND_STOP, MF_BYCOMMAND | MF_GRAYED);
  158. break;
  159. }
  160. } else {
  161. // some other menu, set state accordingly
  162. }
  163. return hMenu;
  164. }
  165. HRESULT CRocket::SetMenuState(IControlbar *pControlbar,
  166. IMenuButton *pMenuButton,
  167. BOOL bScope,
  168. BOOL bSelect)
  169. {
  170. HRESULT hr = S_OK;
  171. if (bSelect) {
  172. // Always make sure the menuButton is attached
  173. hr = pControlbar->Attach(MENUBUTTON, pMenuButton);
  174. hr = pMenuButton->SetButtonState(IDR_STATE_MENU, HIDDEN, FALSE);
  175. hr = pMenuButton->SetButtonState(IDR_STATE_MENU, ENABLED, TRUE);
  176. } else if (!bSelect) {
  177. hr = pMenuButton->SetButtonState(IDR_STATE_MENU, ENABLED, FALSE);
  178. hr = pMenuButton->SetButtonState(IDR_STATE_MENU, HIDDEN, TRUE);
  179. }
  180. return hr;
  181. }
  182. HRESULT CRocket::OnSetMenuButton(IConsole *pConsole, MENUBUTTONDATA *pmbd)
  183. {
  184. HMENU hMenu = GetMenu(pmbd->idCommand);
  185. HRESULT hr = S_FALSE;
  186. HWND hWnd;
  187. if (hMenu) {
  188. hr = pConsole->GetMainWindow(&hWnd);
  189. if (SUCCEEDED(hr)) {
  190. LONG ret = TrackPopupMenuEx(hMenu, TPM_NONOTIFY | TPM_RETURNCMD,
  191. pmbd->x, pmbd->y, hWnd, NULL);
  192. if (ret != 0) { // !cancelled
  193. hr = OnMenuButtonCommand(pConsole, pmbd->idCommand, ret);
  194. }
  195. }
  196. DestroyMenu(hMenu);
  197. }
  198. return hr;
  199. }
  200. HRESULT CRocket::OnMenuButtonCommand(IConsole *pConsole, int nMenuId, long lCommandID)
  201. {
  202. _TCHAR szVehicle[128];
  203. if (IDR_STATE_MENU == nMenuId) {
  204. switch (lCommandID) {
  205. case ID_COMMAND_START:
  206. iStatus = RUNNING;
  207. break;
  208. case ID_COMMAND_PAUSE:
  209. iStatus = PAUSED;
  210. break;
  211. case ID_COMMAND_STOP:
  212. iStatus = STOPPED;
  213. break;
  214. }
  215. wsprintf(szVehicle, _T("Vehicle %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. int ret = 0;
  220. MAKE_WIDEPTR_FROMTSTR(pszVehicle, szVehicle);
  221. pConsole->MessageBox(pszVehicle,
  222. L"Vehicle command", MB_OK | MB_ICONINFORMATION, &ret);
  223. }
  224. return S_OK;
  225. }