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.

288 lines
9.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 "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(CComponentData *pComponentData)
  30. {
  31. m_pComponentData = pComponentData;
  32. for (int n = 0; n < NUMBER_OF_CHILDREN; n++) {
  33. children[n] = new CRocket(pComponentData);
  34. children[n]->Initialize(_T("Vehicle"), 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. _ASSERT( SUCCEEDED(hr) );
  82. }
  83. }
  84. pHeaderCtrl->Release();
  85. pResultData->Release();
  86. }
  87. return hr;
  88. }
  89. //==============================================================
  90. //
  91. // CRocket implementation
  92. //
  93. //
  94. CRocket::CRocket(CComponentData *pComponentData)
  95. : szName(NULL), lWeight(0), lHeight(0), lPayload(0), iStatus(STOPPED)
  96. {
  97. m_pComponentData = pComponentData;
  98. }
  99. CRocket::~CRocket()
  100. {
  101. if (szName)
  102. delete [] szName;
  103. }
  104. void CRocket::Initialize(_TCHAR *szName, LONG lWeight, LONG lHeight, LONG lPayload)
  105. {
  106. if (szName) {
  107. this->szName = new _TCHAR[_tcslen(szName) + 1];
  108. _tcscpy(this->szName, szName);
  109. }
  110. this->lWeight = lWeight;
  111. this->lHeight = lHeight;
  112. this->lPayload = lPayload;
  113. }
  114. const _TCHAR *CRocket::GetDisplayName(int nCol)
  115. {
  116. static _TCHAR buf[128];
  117. switch (nCol) {
  118. case 0:
  119. _tcscpy(buf, szName ? szName : _T(""));
  120. break;
  121. case 1:
  122. _stprintf(buf, _T("%ld metric tons"), lWeight);
  123. break;
  124. case 2:
  125. _stprintf(buf, _T("%ld meters"), lHeight);
  126. break;
  127. case 3:
  128. _stprintf(buf, _T("%ld kilos"), lPayload);
  129. break;
  130. case 4:
  131. _stprintf(buf, _T("%s"),
  132. iStatus == RUNNING ? _T("running") :
  133. iStatus == PAUSED ? _T("paused") :
  134. iStatus == STOPPED ? _T("stopped") : _T("unknown"));
  135. break;
  136. }
  137. return buf;
  138. }
  139. HRESULT CRocket::OnSelect(CComponent *pComponent, BOOL bScope, BOOL bSelect)
  140. {
  141. if (bSelect) {
  142. switch (iStatus)
  143. {
  144. case RUNNING:
  145. pComponent->getToolbar()->SetButtonState(ID_BUTTONSTART, BUTTONPRESSED, TRUE);
  146. pComponent->getToolbar()->SetButtonState(ID_BUTTONSTART, ENABLED, FALSE);
  147. pComponent->getToolbar()->SetButtonState(ID_BUTTONPAUSE, BUTTONPRESSED, FALSE);
  148. pComponent->getToolbar()->SetButtonState(ID_BUTTONPAUSE, ENABLED, TRUE);
  149. pComponent->getToolbar()->SetButtonState(ID_BUTTONSTOP, BUTTONPRESSED, FALSE);
  150. pComponent->getToolbar()->SetButtonState(ID_BUTTONSTOP, ENABLED, TRUE);
  151. break;
  152. case PAUSED:
  153. pComponent->getToolbar()->SetButtonState(ID_BUTTONSTART, BUTTONPRESSED, FALSE);
  154. pComponent->getToolbar()->SetButtonState(ID_BUTTONSTART, ENABLED, TRUE);
  155. pComponent->getToolbar()->SetButtonState(ID_BUTTONPAUSE, BUTTONPRESSED, TRUE);
  156. pComponent->getToolbar()->SetButtonState(ID_BUTTONPAUSE, ENABLED, FALSE);
  157. pComponent->getToolbar()->SetButtonState(ID_BUTTONSTOP, BUTTONPRESSED, FALSE);
  158. pComponent->getToolbar()->SetButtonState(ID_BUTTONSTOP, ENABLED, TRUE);
  159. break;
  160. case STOPPED:
  161. pComponent->getToolbar()->SetButtonState(ID_BUTTONSTART, BUTTONPRESSED, FALSE);
  162. pComponent->getToolbar()->SetButtonState(ID_BUTTONSTART, ENABLED, TRUE);
  163. pComponent->getToolbar()->SetButtonState(ID_BUTTONPAUSE, BUTTONPRESSED, FALSE);
  164. pComponent->getToolbar()->SetButtonState(ID_BUTTONPAUSE, ENABLED, TRUE);
  165. pComponent->getToolbar()->SetButtonState(ID_BUTTONSTOP, BUTTONPRESSED, TRUE);
  166. pComponent->getToolbar()->SetButtonState(ID_BUTTONSTOP, ENABLED, FALSE);
  167. break;
  168. }
  169. }
  170. return S_OK;
  171. }
  172. HRESULT CRocket::OnButtonClicked(CComponent *pComponent)
  173. {
  174. switch (iStatus)
  175. {
  176. case RUNNING:
  177. pComponent->getToolbar()->SetButtonState(ID_BUTTONSTART, BUTTONPRESSED, TRUE);
  178. pComponent->getToolbar()->SetButtonState(ID_BUTTONSTART, ENABLED, FALSE);
  179. pComponent->getToolbar()->SetButtonState(ID_BUTTONPAUSE, BUTTONPRESSED, FALSE);
  180. pComponent->getToolbar()->SetButtonState(ID_BUTTONPAUSE, ENABLED, TRUE);
  181. pComponent->getToolbar()->SetButtonState(ID_BUTTONSTOP, BUTTONPRESSED, FALSE);
  182. pComponent->getToolbar()->SetButtonState(ID_BUTTONSTOP, ENABLED, TRUE);
  183. break;
  184. case PAUSED:
  185. pComponent->getToolbar()->SetButtonState(ID_BUTTONSTART, BUTTONPRESSED, FALSE);
  186. pComponent->getToolbar()->SetButtonState(ID_BUTTONSTART, ENABLED, TRUE);
  187. pComponent->getToolbar()->SetButtonState(ID_BUTTONPAUSE, BUTTONPRESSED, TRUE);
  188. pComponent->getToolbar()->SetButtonState(ID_BUTTONPAUSE, ENABLED, FALSE);
  189. pComponent->getToolbar()->SetButtonState(ID_BUTTONSTOP, BUTTONPRESSED, FALSE);
  190. pComponent->getToolbar()->SetButtonState(ID_BUTTONSTOP, ENABLED, TRUE);
  191. break;
  192. case STOPPED:
  193. pComponent->getToolbar()->SetButtonState(ID_BUTTONSTART, BUTTONPRESSED, FALSE);
  194. pComponent->getToolbar()->SetButtonState(ID_BUTTONSTART, ENABLED, TRUE);
  195. pComponent->getToolbar()->SetButtonState(ID_BUTTONPAUSE, BUTTONPRESSED, FALSE);
  196. pComponent->getToolbar()->SetButtonState(ID_BUTTONPAUSE, ENABLED, TRUE);
  197. pComponent->getToolbar()->SetButtonState(ID_BUTTONSTOP, BUTTONPRESSED, TRUE);
  198. pComponent->getToolbar()->SetButtonState(ID_BUTTONSTOP, ENABLED, FALSE);
  199. break;
  200. }
  201. return S_OK;
  202. }
  203. HRESULT CRocket::OnSetToolbar(CComponent *pComponent, IControlbar *pControlbar, IToolbar *pToolbar, BOOL bScope, BOOL bSelect)
  204. {
  205. HRESULT hr = S_OK;
  206. if (bSelect) {
  207. // Always make sure the menuButton is attached
  208. hr = pControlbar->Attach(TOOLBAR, pToolbar);
  209. hr = OnSelect(pComponent, bScope, bSelect);
  210. } else {
  211. // Always make sure the toolbar is detached
  212. hr = pControlbar->Detach(pToolbar);
  213. }
  214. return hr;
  215. }
  216. HRESULT CRocket::OnToolbarCommand(CComponent *pComponent, IConsole *pConsole, MMC_CONSOLE_VERB verb)
  217. {
  218. _TCHAR szVehicle[128];
  219. switch (verb)
  220. {
  221. case ID_BUTTONSTART:
  222. iStatus = RUNNING;
  223. break;
  224. case ID_BUTTONPAUSE:
  225. iStatus = PAUSED;
  226. break;
  227. case ID_BUTTONSTOP:
  228. iStatus = STOPPED;
  229. break;
  230. }
  231. wsprintf(szVehicle, _T("Vehicle %s has been %s"), szName,
  232. (long)verb == ID_BUTTONSTART ? _T("started") :
  233. (long)verb == ID_BUTTONPAUSE ? _T("paused") :
  234. (long)verb == ID_BUTTONSTOP ? _T("stopped") : _T("!!!unknown command!!!"));
  235. int ret = 0;
  236. MAKE_WIDEPTR_FROMTSTR_ALLOC(wszVehicle, szVehicle);
  237. pConsole->MessageBox(wszVehicle,
  238. L"Vehicle command", MB_OK | MB_ICONINFORMATION, &ret);
  239. OnButtonClicked(pComponent);
  240. return S_OK;
  241. }