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.

166 lines
4.7 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. const GUID CSpaceVehicle::thisGuid = { 0x29743810, 0x4c4b, 0x11d2, { 0x89, 0xd8, 0x0, 0x0, 0x21, 0x47, 0x31, 0x28 } };
  22. const GUID CRocket::thisGuid = { 0x29743811, 0x4c4b, 0x11d2, { 0x89, 0xd8, 0x0, 0x0, 0x21, 0x47, 0x31, 0x28 } };
  23. //==============================================================
  24. //
  25. // CSpaceVehicle implementation
  26. //
  27. //
  28. CSpaceVehicle::CSpaceVehicle(CComponentData *pComponentData)
  29. {
  30. m_pComponentData = pComponentData;
  31. for (int n = 0; n < NUMBER_OF_CHILDREN; n++) {
  32. children[n] = new CRocket(pComponentData);
  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::Show(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. // CSpaceVehicle::CRocket implementation
  91. //
  92. //
  93. CRocket::CRocket(CComponentData *pComponentData)
  94. : szName(NULL), lWeight(0), lHeight(0), lPayload(0), iStatus(STOPPED)
  95. {
  96. m_pComponentData = pComponentData;
  97. }
  98. CRocket::~CRocket()
  99. {
  100. if (szName)
  101. delete [] szName;
  102. }
  103. void CRocket::Initialize(_TCHAR *szName, LONG lWeight, LONG lHeight, LONG lPayload)
  104. {
  105. if (szName) {
  106. this->szName = new _TCHAR[_tcslen(szName) + 1];
  107. _tcscpy(this->szName, szName);
  108. }
  109. this->lWeight = lWeight;
  110. this->lHeight = lHeight;
  111. this->lPayload = lPayload;
  112. }
  113. const _TCHAR *CRocket::GetDisplayName(int nCol)
  114. {
  115. static _TCHAR buf[128];
  116. switch (nCol) {
  117. case 0:
  118. _tcscpy(buf, szName ? szName : _T(""));
  119. break;
  120. case 1:
  121. _stprintf(buf, _T("%ld metric tons"), lWeight);
  122. break;
  123. case 2:
  124. _stprintf(buf, _T("%ld meters"), lHeight);
  125. break;
  126. case 3:
  127. _stprintf(buf, _T("%ld kilos"), lPayload);
  128. break;
  129. case 4:
  130. _stprintf(buf, _T("%s"),
  131. iStatus == RUNNING ? _T("running") :
  132. iStatus == PAUSED ? _T("paused") :
  133. iStatus == STOPPED ? _T("stopped") : _T("unknown"));
  134. break;
  135. }
  136. return buf;
  137. }