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.

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