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.

194 lines
5.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()
  30. {
  31. for (int n = 0; n < NUMBER_OF_CHILDREN; n++) {
  32. children[n] = new CRocket(_T("Rocket"), n+1, 500000, 265, 75000);
  33. }
  34. }
  35. CSpaceVehicle::~CSpaceVehicle()
  36. {
  37. for (int n = 0; n < NUMBER_OF_CHILDREN; n++)
  38. if (children[n]) {
  39. delete children[n];
  40. }
  41. }
  42. HRESULT CSpaceVehicle::OnShow(IConsole *pConsole, BOOL bShow, HSCOPEITEM scopeitem)
  43. {
  44. HRESULT hr = S_OK;
  45. IHeaderCtrl *pHeaderCtrl = NULL;
  46. IResultData *pResultData = NULL;
  47. if (bShow) {
  48. hr = pConsole->QueryInterface(IID_IHeaderCtrl, (void **)&pHeaderCtrl);
  49. _ASSERT( SUCCEEDED(hr) );
  50. hr = pConsole->QueryInterface(IID_IResultData, (void **)&pResultData);
  51. _ASSERT( SUCCEEDED(hr) );
  52. // Set the column headers in the results pane
  53. hr = pHeaderCtrl->InsertColumn( 0, L"Rocket Class", 0, MMCLV_AUTO );
  54. _ASSERT( S_OK == hr );
  55. hr = pHeaderCtrl->InsertColumn( 1, L"Rocket Weight", 0, MMCLV_AUTO );
  56. _ASSERT( S_OK == hr );
  57. hr = pHeaderCtrl->InsertColumn( 2, L"Rocket Height", 0, MMCLV_AUTO );
  58. _ASSERT( S_OK == hr );
  59. hr = pHeaderCtrl->InsertColumn( 3, L"Rocket Payload", 0, MMCLV_AUTO );
  60. _ASSERT( S_OK == hr );
  61. hr = pHeaderCtrl->InsertColumn( 4, L"Status", 0, MMCLV_AUTO );
  62. _ASSERT( S_OK == hr );
  63. // insert items here
  64. RESULTDATAITEM rdi;
  65. hr = pResultData->DeleteAllRsltItems();
  66. _ASSERT( SUCCEEDED(hr) );
  67. if (!bExpanded) {
  68. // create the child nodes, then expand them
  69. for (int n = 0; n < NUMBER_OF_CHILDREN; n++) {
  70. ZeroMemory(&rdi, sizeof(RESULTDATAITEM) );
  71. rdi.mask = RDI_STR | // Displayname is valid
  72. RDI_IMAGE |
  73. RDI_PARAM; // nImage is valid
  74. rdi.nImage = children[n]->GetBitmapIndex();
  75. rdi.str = MMC_CALLBACK;
  76. rdi.nCol = 0;
  77. rdi.lParam = (LPARAM)children[n];
  78. hr = pResultData->InsertItem( &rdi );
  79. _ASSERT( SUCCEEDED(hr) );
  80. }
  81. }
  82. pHeaderCtrl->Release();
  83. pResultData->Release();
  84. }
  85. return hr;
  86. }
  87. //==============================================================
  88. //
  89. // CRocket implementation
  90. //
  91. //
  92. CRocket::CRocket(_TCHAR *szName, int id, LONG lWeight, LONG lHeight, LONG lPayload)
  93. : szName(NULL), lWeight(0), lHeight(0), lPayload(0), iStatus(STOPPED)
  94. {
  95. if (szName) {
  96. this->szName = new _TCHAR[(_tcslen(szName) + 1) * sizeof(_TCHAR)];
  97. _tcscpy(this->szName, szName);
  98. }
  99. this->nId = id;
  100. this->lWeight = lWeight;
  101. this->lHeight = lHeight;
  102. this->lPayload = lPayload;
  103. }
  104. CRocket::~CRocket()
  105. {
  106. if (szName)
  107. delete [] szName;
  108. }
  109. const _TCHAR *CRocket::GetDisplayName(int nCol)
  110. {
  111. static _TCHAR buf[128];
  112. switch (nCol) {
  113. case 0:
  114. _stprintf(buf, _T("%s (#%d)"), szName ? szName : _T(""), nId);
  115. break;
  116. case 1:
  117. _stprintf(buf, _T("%ld metric tons"), lWeight);
  118. break;
  119. case 2:
  120. _stprintf(buf, _T("%ld meters"), lHeight);
  121. break;
  122. case 3:
  123. _stprintf(buf, _T("%ld kilos"), lPayload);
  124. break;
  125. case 4:
  126. _stprintf(buf, _T("%s"),
  127. iStatus == RUNNING ? _T("running") :
  128. iStatus == PAUSED ? _T("paused") :
  129. iStatus == STOPPED ? _T("stopped") : _T("unknown"));
  130. break;
  131. }
  132. return buf;
  133. }
  134. HRESULT CRocket::OnRename(LPOLESTR pszNewName)
  135. {
  136. if (szName) {
  137. delete [] szName;
  138. szName = NULL;
  139. }
  140. MAKE_TSTRPTR_FROMWIDE(ptrname, pszNewName);
  141. szName = new _TCHAR[(_tcslen(ptrname) + 1) * sizeof(_TCHAR)];
  142. _tcscpy(szName, ptrname);
  143. return S_OK;
  144. }
  145. HRESULT CRocket::OnSelect(IConsole *pConsole, BOOL bScope, BOOL bSelect)
  146. {
  147. IConsoleVerb *pConsoleVerb;
  148. HRESULT hr = pConsole->QueryConsoleVerb(&pConsoleVerb);
  149. _ASSERT(SUCCEEDED(hr));
  150. hr = pConsoleVerb->SetVerbState(MMC_VERB_RENAME, HIDDEN, FALSE);
  151. hr = pConsoleVerb->SetVerbState(MMC_VERB_RENAME, ENABLED, TRUE);
  152. hr = pConsoleVerb->SetVerbState(MMC_VERB_PROPERTIES, HIDDEN, FALSE);
  153. hr = pConsoleVerb->SetVerbState(MMC_VERB_PROPERTIES, ENABLED, TRUE);
  154. pConsoleVerb->Release();
  155. return S_OK;
  156. }