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.

213 lines
5.8 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 "People.h"
  21. #include <initguid.h>
  22. // for vb component
  23. //#include "vb\mmcsample.h"
  24. const GUID CPeoplePoweredVehicle::thisGuid = { 0x2974380d, 0x4c4b, 0x11d2, { 0x89, 0xd8, 0x0, 0x0, 0x21, 0x47, 0x31, 0x28 } };
  25. const GUID CPerson::thisGuid = { 0xd41ef043, 0x8bc5, 0x11d2, { 0x8a, 0xb, 0x0, 0x0, 0x21, 0x47, 0x31, 0x28 } };
  26. //==============================================================
  27. //
  28. // CPeoplePoweredVehicle implementation
  29. //
  30. //
  31. CPeoplePoweredVehicle::CPeoplePoweredVehicle(CComponentData *pComponentData)
  32. {
  33. m_pComponentData = pComponentData;
  34. for (int n = 0; n < NUMBER_OF_CHILDREN; n++) {
  35. children[n] = new CPerson(n, pComponentData);
  36. children[n]->Initialize(_T("Fred"), 6, 2, 115, n % 2 == 0 ? TRUE : FALSE);
  37. }
  38. }
  39. CPeoplePoweredVehicle::~CPeoplePoweredVehicle()
  40. {
  41. for (int n = 0; n < NUMBER_OF_CHILDREN; n++)
  42. if (children[n]) {
  43. delete children[n];
  44. }
  45. }
  46. HRESULT CPeoplePoweredVehicle::Expand(IConsoleNameSpace *pConsoleNameSpace, IConsole *pConsole, HSCOPEITEM parent)
  47. {
  48. SCOPEDATAITEM sdi;
  49. if (!bExpanded) {
  50. // create the child nodes, then expand them
  51. for (int n = 0; n < NUMBER_OF_CHILDREN; n++) {
  52. ZeroMemory(&sdi, sizeof(SCOPEDATAITEM) );
  53. sdi.mask = SDI_STR | // Displayname is valid
  54. SDI_PARAM | // lParam is valid
  55. SDI_IMAGE | // nImage is valid
  56. SDI_OPENIMAGE | // nOpenImage is valid
  57. SDI_PARENT |
  58. SDI_CHILDREN;
  59. sdi.relativeID = (HSCOPEITEM)parent;
  60. sdi.nImage = children[n]->GetBitmapIndex();
  61. sdi.nOpenImage = children[n]->GetBitmapIndex();
  62. sdi.displayname = MMC_CALLBACK;
  63. sdi.lParam = (LPARAM)children[n]; // The cookie
  64. sdi.cChildren = 0;
  65. HRESULT hr = pConsoleNameSpace->InsertItem( &sdi );
  66. _ASSERT( SUCCEEDED(hr) );
  67. }
  68. }
  69. return S_OK;
  70. }
  71. //==============================================================
  72. //
  73. // CPeopleVehicle::CPerson implementation
  74. //
  75. //
  76. CPerson::CPerson(int id, CComponentData *pComponentData)
  77. : m_id(id)
  78. {
  79. m_pComponentData = pComponentData;
  80. m_pUnknown = NULL;
  81. szName = NULL;
  82. lSpeed = 0;
  83. lHeight = 0;
  84. lWeight = 0;
  85. fAnimating = FALSE;
  86. }
  87. CPerson::~CPerson()
  88. {
  89. if (szName)
  90. delete [] szName;
  91. if (m_pUnknown)
  92. m_pUnknown->Release();
  93. }
  94. void CPerson::Initialize(_TCHAR *szName, LONG lSpeed, LONG lHeight, LONG lWeight, BOOL fAnimating)
  95. {
  96. if (szName) {
  97. this->szName = new _TCHAR[_tcslen(szName) + 20];
  98. _tcscpy(this->szName, szName);
  99. _tcscat(this->szName, _T(" "));
  100. if (m_id % 2)
  101. _tcscat(this->szName, _T("(new control)"));
  102. else
  103. _tcscat(this->szName, _T("(share control)"));
  104. }
  105. this->lSpeed = lSpeed;
  106. this->lHeight = lHeight;
  107. this->lWeight = lWeight;
  108. this->fAnimating = fAnimating;
  109. return;
  110. }
  111. const _TCHAR *CPerson::GetDisplayName(int nCol)
  112. {
  113. static _TCHAR buf[128];
  114. switch (nCol) {
  115. case 0:
  116. _tcscpy(buf, szName ? szName : _T(""));
  117. break;
  118. case 1:
  119. _stprintf(buf, _T("%ld m/s"), lSpeed);
  120. break;
  121. case 2:
  122. _stprintf(buf, _T("%ld meters"), lHeight);
  123. break;
  124. case 3:
  125. _stprintf(buf, _T("%ld kilos"), lWeight);
  126. break;
  127. }
  128. return buf;
  129. }
  130. HRESULT CPerson::GetResultViewType(LPOLESTR *ppViewType, long *pViewOptions)
  131. {
  132. // for vb component
  133. // LPOLESTR lpOleStr;
  134. // HRESULT hr = StringFromCLSID(CLSID_VBComponent, &lpOleStr);
  135. // *ppViewType = lpOleStr;
  136. // for atl component
  137. LPOLESTR lpOleStr = L"{9A12FB62-C754-11D2-952C-00C04FB92EC2}";
  138. *ppViewType = static_cast<LPOLESTR>(CoTaskMemAlloc((wcslen(lpOleStr) + 1) * sizeof(WCHAR)));
  139. wcscpy(*ppViewType, lpOleStr);
  140. if (m_id % 2) {
  141. // create new control
  142. *pViewOptions = MMC_VIEW_OPTIONS_CREATENEW;
  143. } else {
  144. // share control
  145. *pViewOptions = MMC_VIEW_OPTIONS_NONE;
  146. }
  147. return S_OK;
  148. }
  149. HRESULT CPerson::ShowContextHelp(IConsole *pConsole, IDisplayHelp *m_ipDisplayHelp, LPOLESTR helpFile)
  150. {
  151. HRESULT hr = S_OK;
  152. IUnknown *pUnk = NULL;
  153. if (SUCCEEDED(hr = pConsole->QueryResultView(&pUnk))) {
  154. IDispatch *pDispatch = NULL;
  155. if (SUCCEEDED(hr = pUnk->QueryInterface(IID_IDispatch, (void **)&pDispatch))) {
  156. DISPID dispID;
  157. DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
  158. EXCEPINFO exInfo;
  159. OLECHAR *pszName = L"DoHelp";
  160. UINT uErr;
  161. hr = pDispatch->GetIDsOfNames(IID_NULL, &pszName, 1, LOCALE_SYSTEM_DEFAULT, &dispID);
  162. if (SUCCEEDED(hr)) {
  163. hr = pDispatch->Invoke(
  164. dispID,
  165. IID_NULL,
  166. LOCALE_USER_DEFAULT,
  167. DISPATCH_METHOD,
  168. &dispparamsNoArgs, NULL, &exInfo, &uErr);
  169. }
  170. pDispatch->Release();
  171. }
  172. pUnk->Release();
  173. }
  174. _ASSERT(SUCCEEDED(hr));
  175. return hr;
  176. }