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.

348 lines
11 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 <windows.h>
  21. #include "Space.h"
  22. #include "Comp.h"
  23. #include "resource.h"
  24. const GUID CSpaceVehicle::thisGuid = { 0x29743810, 0x4c4b, 0x11d2, { 0x89, 0xd8, 0x0, 0x0, 0x21, 0x47, 0x31, 0x28 } };
  25. const GUID CRocket::thisGuid = { 0x29743811, 0x4c4b, 0x11d2, { 0x89, 0xd8, 0x0, 0x0, 0x21, 0x47, 0x31, 0x28 } };
  26. //==============================================================
  27. //
  28. // CSpaceVehicle implementation
  29. //
  30. //
  31. CSpaceVehicle::CSpaceVehicle()
  32. {
  33. for (int n = 0; n < NUMBER_OF_CHILDREN; n++) {
  34. children[n] = new CRocket(_T("Rocket"), n+1, 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(_TCHAR *szName, int id, LONG lWeight, LONG lHeight, LONG lPayload)
  95. : szName(NULL), lWeight(0), lHeight(0), lPayload(0), iStatus(STOPPED)
  96. {
  97. if (szName) {
  98. this->szName = new _TCHAR[(_tcslen(szName) + 1) * sizeof(_TCHAR)];
  99. _tcscpy(this->szName, szName);
  100. }
  101. this->nId = id;
  102. this->lWeight = lWeight;
  103. this->lHeight = lHeight;
  104. this->lPayload = lPayload;
  105. m_ppHandle = 0;
  106. }
  107. CRocket::~CRocket()
  108. {
  109. if (szName)
  110. delete [] szName;
  111. }
  112. const _TCHAR *CRocket::GetDisplayName(int nCol)
  113. {
  114. static _TCHAR buf[128];
  115. switch (nCol) {
  116. case 0:
  117. _stprintf(buf, _T("%s (#%d)"), szName ? szName : _T(""), nId);
  118. break;
  119. case 1:
  120. _stprintf(buf, _T("%ld metric tons"), lWeight);
  121. break;
  122. case 2:
  123. _stprintf(buf, _T("%ld meters"), lHeight);
  124. break;
  125. case 3:
  126. _stprintf(buf, _T("%ld kilos"), lPayload);
  127. break;
  128. case 4:
  129. _stprintf(buf, _T("%s"),
  130. iStatus == RUNNING ? _T("running") :
  131. iStatus == PAUSED ? _T("paused") :
  132. iStatus == STOPPED ? _T("stopped") : _T("unknown"));
  133. break;
  134. }
  135. return buf;
  136. }
  137. HRESULT CRocket::OnRename(LPOLESTR pszNewName)
  138. {
  139. if (szName) {
  140. delete [] szName;
  141. szName = NULL;
  142. }
  143. MAKE_TSTRPTR_FROMWIDE(ptrname, pszNewName);
  144. szName = new _TCHAR[(_tcslen(ptrname) + 1) * sizeof(_TCHAR)];
  145. _tcscpy(szName, ptrname);
  146. return S_OK;
  147. }
  148. // handle anything special when the user clicks Apply or Ok
  149. // on the property sheet. This sample directly accesses the
  150. // operated-on object, so there's nothing special to do when the user presses Ok.
  151. // when the user presses Apply, we update the currently selected result item
  152. HRESULT CRocket::OnPropertyChange(IConsole *pConsole)
  153. {
  154. //redraw the item
  155. IResultData *pResultData = NULL;
  156. HRESULT hr;
  157. hr = pConsole->QueryInterface(IID_IResultData, (void **)&pResultData);
  158. _ASSERT( SUCCEEDED(hr) );
  159. HRESULTITEM myhresultitem;
  160. //lparam == this. See CSpaceVehicle::OnShow
  161. hr = pResultData->FindItemByLParam( (LPARAM)this, &myhresultitem );
  162. _ASSERT( SUCCEEDED(hr) );
  163. hr = pResultData->UpdateItem( myhresultitem );
  164. _ASSERT( SUCCEEDED(hr) );
  165. pResultData->Release();
  166. return S_OK;
  167. }
  168. HRESULT CRocket::OnSelect(IConsole *pConsole, BOOL bScope, BOOL bSelect)
  169. {
  170. IConsoleVerb *pConsoleVerb;
  171. HRESULT hr = pConsole->QueryConsoleVerb(&pConsoleVerb);
  172. _ASSERT(SUCCEEDED(hr));
  173. hr = pConsoleVerb->SetVerbState(MMC_VERB_RENAME, ENABLED, TRUE);
  174. // can't get to properties (via the standard methods) unless
  175. // we tell MMC to display the Properties menu item and
  176. // toolbar button, this wil give the user a visual cue that
  177. // there's "something" to do
  178. hr = pConsoleVerb->SetVerbState(MMC_VERB_PROPERTIES, ENABLED, TRUE);
  179. pConsoleVerb->Release();
  180. return S_OK;
  181. }
  182. // Implement the dialog proc
  183. BOOL CALLBACK CRocket::DialogProc(
  184. HWND hwndDlg, // handle to dialog box
  185. UINT uMsg, // message
  186. WPARAM wParam, // first message parameter
  187. LPARAM lParam // second message parameter
  188. )
  189. {
  190. static CRocket *pRocket = NULL;
  191. switch (uMsg) {
  192. case WM_INITDIALOG:
  193. // catch the "this" pointer so we can actually operate on the object
  194. pRocket = reinterpret_cast<CRocket *>(reinterpret_cast<PROPSHEETPAGE *>(lParam)->lParam);
  195. SetDlgItemText(hwndDlg, IDC_ROCKET_NAME, pRocket->szName);
  196. SetDlgItemInt(hwndDlg, IDC_ROCKET_HEIGHT, pRocket->lHeight, FALSE);
  197. SetDlgItemInt(hwndDlg, IDC_ROCKET_WEIGHT, pRocket->lWeight, FALSE);
  198. SetDlgItemInt(hwndDlg, IDC_ROCKET_PAYLOAD, pRocket->lPayload, FALSE);
  199. _ASSERT( CB_ERR != SendDlgItemMessage(hwndDlg, IDC_ROCKET_STATUS, CB_INSERTSTRING, 0, (LPARAM)_T("Running")) );
  200. _ASSERT( CB_ERR != SendDlgItemMessage(hwndDlg, IDC_ROCKET_STATUS, CB_INSERTSTRING, 1, (LPARAM)_T("Paused")) );
  201. _ASSERT( CB_ERR != SendDlgItemMessage(hwndDlg, IDC_ROCKET_STATUS, CB_INSERTSTRING, 2, (LPARAM)_T("Stopped")) );
  202. SendDlgItemMessage(hwndDlg, IDC_ROCKET_STATUS, CB_SETCURSEL, (WPARAM)pRocket->iStatus, 0);
  203. break;
  204. case WM_COMMAND:
  205. // turn the Apply button on
  206. if (HIWORD(wParam) == EN_CHANGE ||
  207. HIWORD(wParam) == CBN_SELCHANGE)
  208. SendMessage(GetParent(hwndDlg), PSM_CHANGED, (WPARAM)hwndDlg, 0);
  209. break;
  210. case WM_DESTROY:
  211. // tell MMC that we're done with the property sheet (we got this
  212. // handle in CreatePropertyPages
  213. MMCFreeNotifyHandle(pRocket->m_ppHandle);
  214. break;
  215. case WM_NOTIFY:
  216. switch (((NMHDR *) lParam)->code) {
  217. case PSN_APPLY:
  218. // update the information
  219. if (pRocket->szName) {
  220. delete [] pRocket->szName;
  221. pRocket->szName = NULL;
  222. }
  223. {
  224. int n = SendDlgItemMessage(hwndDlg, IDC_ROCKET_NAME, WM_GETTEXTLENGTH, 0, 0);
  225. if (n != 0) {
  226. pRocket->szName = new _TCHAR[n + 1];
  227. GetDlgItemText(hwndDlg, IDC_ROCKET_NAME, pRocket->szName, n + 1);
  228. }
  229. }
  230. pRocket->lHeight = GetDlgItemInt(hwndDlg, IDC_ROCKET_HEIGHT, NULL, FALSE);
  231. pRocket->lWeight = GetDlgItemInt(hwndDlg, IDC_ROCKET_WEIGHT, NULL, FALSE);
  232. pRocket->lPayload = GetDlgItemInt(hwndDlg, IDC_ROCKET_PAYLOAD, NULL, FALSE);
  233. pRocket->iStatus = (ROCKET_STATUS)SendDlgItemMessage(hwndDlg, IDC_ROCKET_STATUS, CB_GETCURSEL, 0, 0);
  234. // ask MMC to send us a message (on the main thread) so
  235. // we know the Apply button was clicked.
  236. HRESULT hr = MMCPropertyChangeNotify(pRocket->m_ppHandle, (long)pRocket);
  237. _ASSERT(SUCCEEDED(hr));
  238. return PSNRET_NOERROR;
  239. }
  240. break;
  241. }
  242. return DefWindowProc(hwndDlg, uMsg, wParam, lParam);
  243. }
  244. HRESULT CRocket::HasPropertySheets()
  245. {
  246. // say "yes" when MMC asks if we have pages
  247. return S_OK;
  248. }
  249. HRESULT CRocket::CreatePropertyPages(IPropertySheetCallback *lpProvider, LONG_PTR handle)
  250. {
  251. PROPSHEETPAGE psp;
  252. HPROPSHEETPAGE hPage = NULL;
  253. // cache this handle so we can call MMCPropertyChangeNotify
  254. m_ppHandle = handle;
  255. // create the property page for this node.
  256. // NOTE: if your node has multiple pages, put the following
  257. // in a loop and create multiple pages calling
  258. // lpProvider->AddPage() for each page.
  259. psp.dwSize = sizeof(PROPSHEETPAGE);
  260. psp.dwFlags = PSP_DEFAULT | PSP_USETITLE | PSP_USEICONID;
  261. psp.hInstance = g_hinst;
  262. psp.pszTemplate = MAKEINTRESOURCE(IDD_PROPPAGE_LARGE);
  263. psp.pfnDlgProc = DialogProc;
  264. psp.lParam = reinterpret_cast<LPARAM>(this);
  265. psp.pszTitle = MAKEINTRESOURCE(IDS_PST_ROCKET);
  266. psp.pszIcon = MAKEINTRESOURCE(IDI_PSI_ROCKET);
  267. hPage = CreatePropertySheetPage(&psp);
  268. _ASSERT(hPage);
  269. return lpProvider->AddPage(hPage);
  270. }
  271. HRESULT CRocket::GetWatermarks(HBITMAP *lphWatermark,
  272. HBITMAP *lphHeader,
  273. HPALETTE *lphPalette,
  274. BOOL *bStretch)
  275. {
  276. return S_FALSE;
  277. }