Source code of Windows XP (NT5)
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.

2456 lines
54 KiB

  1. //-------------------------------------------------------------------------
  2. // File: EditPropertyDlgs.cpp
  3. //
  4. // Author : Kishnan Nedungadi
  5. //
  6. // created : 3/27/2000
  7. //-------------------------------------------------------------------------
  8. #include "stdafx.h"
  9. #include <wbemidl.h>
  10. #include <commctrl.h>
  11. #include "resource.h"
  12. #include "defines.h"
  13. #include "ntdmutils.h"
  14. #include "EditPropertyDlgs.h"
  15. CEditStringPropertyDlg * g_pEditStringPropertyDlg = NULL;
  16. INT_PTR CALLBACK EditStringPropertyDlgProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam);
  17. CEditNumberPropertyDlg * g_pEditNumberPropertyDlg = NULL;
  18. INT_PTR CALLBACK EditNumberPropertyDlgProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam);
  19. CEditRulesPropertyDlg * g_pEditRulesPropertyDlg = NULL;
  20. INT_PTR CALLBACK EditRulesPropertyDlgProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam);
  21. CEditRulePropertyDlg * g_pEditRulePropertyDlg = NULL;
  22. INT_PTR CALLBACK EditRulePropertyDlgProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam);
  23. CEditRangeParametersPropertyDlg * g_pEditRangeParametersPropertyDlg = NULL;
  24. INT_PTR CALLBACK EditRangeParametersPropertyDlgProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam);
  25. CEditRangeParameterPropertyDlg * g_pEditRangeParameterPropertyDlg = NULL;
  26. INT_PTR CALLBACK EditRangeParameterPropertyDlgProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam);
  27. //-------------------------------------------------------------------------
  28. // CEditPropertyDlg
  29. //-------------------------------------------------------------------------
  30. CEditProperty::CEditProperty(HWND hWndParent, LPCTSTR pszName, LPCTSTR pszType, VARIANT *pvValue, IWbemServices *pIWbemServices, long lSpecialCaseProperty)
  31. {
  32. _ASSERT(pvValue);
  33. m_hWnd = hWndParent;
  34. pvSrcValue = pvValue;
  35. m_bstrName = pszName;
  36. m_bstrType = pszType;
  37. m_lSpecialCaseProperty = lSpecialCaseProperty;
  38. m_pIWbemServices = pIWbemServices;
  39. }
  40. //-------------------------------------------------------------------------
  41. CEditProperty::~CEditProperty()
  42. {
  43. }
  44. //---------------------------------------------------------------------------
  45. long CEditProperty::Run()
  46. {
  47. HRESULT hr;
  48. long lRetVal = IDCANCEL;
  49. VARIANT * pvTemp = NULL;
  50. long vtType;
  51. NTDM_BEGIN_METHOD()
  52. vtType = V_VT(pvSrcValue);
  53. if(VT_EMPTY == vtType || VT_NULL == vtType)
  54. {
  55. CNTDMUtils::GetVariantTypeFromString(m_bstrType, &vtType);
  56. }
  57. else if(m_lSpecialCaseProperty == psc_rule)
  58. {
  59. CComPtr<IWbemClassObject>pIWbemClassObject;
  60. CEditRulePropertyDlg * pOld = g_pEditRulePropertyDlg;
  61. NTDM_ERR_MSG_IF_FAIL((V_UNKNOWN(pvSrcValue))->QueryInterface(IID_IWbemClassObject, (void **)&pIWbemClassObject));
  62. NTDM_ERR_IF_NULL((g_pEditRulePropertyDlg = new CEditRulePropertyDlg(pIWbemClassObject)));
  63. lRetVal = DialogBox(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDD_EDIT_RULE), (HWND)m_hWnd, EditRulePropertyDlgProc);
  64. NTDM_DELETE_OBJECT(g_pEditRulePropertyDlg);
  65. g_pEditRulePropertyDlg = pOld;
  66. }
  67. else if(m_lSpecialCaseProperty == psc_range)
  68. {
  69. CComPtr<IWbemClassObject>pIWbemClassObject;
  70. CEditRangeParameterPropertyDlg * pOld = g_pEditRangeParameterPropertyDlg;
  71. NTDM_ERR_MSG_IF_FAIL((V_UNKNOWN(pvSrcValue))->QueryInterface(IID_IWbemClassObject, (void **)&pIWbemClassObject));
  72. NTDM_ERR_IF_NULL((g_pEditRangeParameterPropertyDlg = new CEditRangeParameterPropertyDlg(pIWbemClassObject, m_pIWbemServices)));
  73. lRetVal = DialogBox(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDD_EDIT_RANGE_PARAMETER), (HWND)m_hWnd, EditRangeParameterPropertyDlgProc);
  74. if(IDOK == lRetVal)
  75. {
  76. VariantClear(pvSrcValue);
  77. VariantCopy(pvSrcValue, &g_pEditRangeParameterPropertyDlg->m_vValue);
  78. }
  79. NTDM_DELETE_OBJECT(g_pEditRangeParameterPropertyDlg);
  80. g_pEditRangeParameterPropertyDlg = pOld;
  81. }
  82. else if(VT_BSTR == vtType)
  83. {
  84. // string
  85. CEditStringPropertyDlg * pOld = g_pEditStringPropertyDlg;
  86. NTDM_ERR_IF_NULL((g_pEditStringPropertyDlg = new CEditStringPropertyDlg(m_bstrName, m_bstrType, pvSrcValue)));
  87. lRetVal = DialogBox(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDD_EDIT_STRING_PROPERTY), (HWND)m_hWnd, EditStringPropertyDlgProc);
  88. if(IDOK == lRetVal)
  89. {
  90. VariantClear(pvSrcValue);
  91. VariantCopy(pvSrcValue, &g_pEditStringPropertyDlg->m_vValue);
  92. }
  93. NTDM_DELETE_OBJECT(g_pEditStringPropertyDlg);
  94. g_pEditStringPropertyDlg = pOld;
  95. }
  96. else if(VT_ARRAY & V_VT(pvSrcValue))
  97. {
  98. if(m_lSpecialCaseProperty == psc_rules)
  99. {
  100. // Rules
  101. CEditRulesPropertyDlg * pOld = g_pEditRulesPropertyDlg;
  102. NTDM_ERR_IF_NULL((g_pEditRulesPropertyDlg = new CEditRulesPropertyDlg(m_bstrName, m_bstrType, pvSrcValue, m_pIWbemServices)));
  103. lRetVal = DialogBox(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDD_EDIT_RULES_PROPERTY), (HWND)m_hWnd, EditRulesPropertyDlgProc);
  104. if(IDOK == lRetVal)
  105. {
  106. VariantClear(pvSrcValue);
  107. VariantCopy(pvSrcValue, &g_pEditRulesPropertyDlg->m_vValue);
  108. }
  109. NTDM_DELETE_OBJECT(g_pEditRulesPropertyDlg);
  110. g_pEditRulesPropertyDlg = pOld;
  111. }
  112. else if(m_lSpecialCaseProperty == psc_ranges)
  113. {
  114. // Ranges
  115. CEditRangeParametersPropertyDlg * pOld = g_pEditRangeParametersPropertyDlg;
  116. NTDM_ERR_IF_NULL((g_pEditRangeParametersPropertyDlg = new CEditRangeParametersPropertyDlg(m_bstrName, m_bstrType, pvSrcValue, m_pIWbemServices)));
  117. lRetVal = DialogBox(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDD_EDIT_RANGE_PARAMETERS_PROPERTY), (HWND)m_hWnd, EditRangeParametersPropertyDlgProc);
  118. if(IDOK == lRetVal)
  119. {
  120. VariantClear(pvSrcValue);
  121. VariantCopy(pvSrcValue, &g_pEditRangeParametersPropertyDlg->m_vValue);
  122. }
  123. NTDM_DELETE_OBJECT(g_pEditRangeParametersPropertyDlg);
  124. g_pEditRangeParametersPropertyDlg = pOld;
  125. }
  126. }
  127. NTDM_END_METHOD()
  128. // cleanup
  129. return lRetVal;
  130. }
  131. //-------------------------------------------------------------------------
  132. // CEditPropertyDlg
  133. //-------------------------------------------------------------------------
  134. CEditPropertyDlg::CEditPropertyDlg(LPCTSTR pszName, LPCTSTR pszType, VARIANT * pvValue)
  135. {
  136. _ASSERT(pvValue);
  137. m_hWnd = NULL;
  138. pvSrcValue = pvValue;
  139. m_vValue = *pvValue;
  140. m_bstrName = pszName;
  141. m_bstrType = pszType;
  142. }
  143. //-------------------------------------------------------------------------
  144. CEditPropertyDlg::~CEditPropertyDlg()
  145. {
  146. }
  147. //---------------------------------------------------------------------------
  148. STDMETHODIMP CEditPropertyDlg::InitializeDialog()
  149. {
  150. HRESULT hr;
  151. NTDM_BEGIN_METHOD()
  152. SetDlgItemText(m_hWnd, IDC_NAME, m_bstrName);
  153. SetDlgItemText(m_hWnd, IDC_TYPE, m_bstrType);
  154. NTDM_END_METHOD()
  155. // cleanup
  156. return hr;
  157. }
  158. //---------------------------------------------------------------------------
  159. STDMETHODIMP CEditPropertyDlg::DestroyDialog()
  160. {
  161. HRESULT hr;
  162. NTDM_BEGIN_METHOD()
  163. NTDM_END_METHOD()
  164. // cleanup
  165. return hr;
  166. }
  167. //-------------------------------------------------------------------------
  168. // CEditStringPropertyDlg
  169. //-------------------------------------------------------------------------
  170. INT_PTR CALLBACK EditStringPropertyDlgProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)
  171. {
  172. if(g_pEditStringPropertyDlg)
  173. {
  174. return g_pEditStringPropertyDlg->EditStringPropertyDlgProc(hDlg, iMessage, wParam, lParam);
  175. }
  176. return FALSE;
  177. }
  178. //-------------------------------------------------------------------------
  179. CEditStringPropertyDlg::CEditStringPropertyDlg(LPCTSTR pszName, LPCTSTR pszType, VARIANT * pvValue)
  180. :CEditPropertyDlg(pszName, pszType, pvValue)
  181. {
  182. }
  183. //-------------------------------------------------------------------------
  184. CEditStringPropertyDlg::~CEditStringPropertyDlg()
  185. {
  186. }
  187. //-------------------------------------------------------------------------
  188. INT_PTR CALLBACK CEditStringPropertyDlg::EditStringPropertyDlgProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)
  189. {
  190. LPPSHNOTIFY lppsn = NULL;
  191. switch(iMessage)
  192. {
  193. case WM_INITDIALOG:
  194. {
  195. m_hWnd = hDlg;
  196. InitializeDialog();
  197. break;
  198. }
  199. case WM_DESTROY:
  200. {
  201. DestroyDialog();
  202. break;
  203. }
  204. case WM_COMMAND:
  205. {
  206. switch(LOWORD(wParam))
  207. {
  208. case IDOK:
  209. {
  210. OnOK();
  211. return TRUE;
  212. break;
  213. }
  214. case IDCANCEL:
  215. {
  216. EndDialog(m_hWnd, IDCANCEL);
  217. return TRUE;
  218. break;
  219. }
  220. }
  221. break;
  222. }
  223. }
  224. return FALSE;
  225. }
  226. //---------------------------------------------------------------------------
  227. STDMETHODIMP CEditStringPropertyDlg::InitializeDialog()
  228. {
  229. HRESULT hr;
  230. NTDM_BEGIN_METHOD()
  231. CEditPropertyDlg::InitializeDialog();
  232. // Set the string property
  233. SetDlgItemText(m_hWnd, IDC_VALUE, V_BSTR(&m_vValue));
  234. NTDM_END_METHOD()
  235. // cleanup
  236. return hr;
  237. }
  238. //---------------------------------------------------------------------------
  239. STDMETHODIMP CEditStringPropertyDlg::DestroyDialog()
  240. {
  241. HRESULT hr;
  242. NTDM_BEGIN_METHOD()
  243. CEditPropertyDlg::DestroyDialog();
  244. NTDM_END_METHOD()
  245. // cleanup
  246. return hr;
  247. }
  248. //---------------------------------------------------------------------------
  249. STDMETHODIMP CEditStringPropertyDlg::OnOK()
  250. {
  251. HRESULT hr;
  252. long lLength;
  253. TCHAR *pszTemp = NULL;
  254. NTDM_BEGIN_METHOD()
  255. lLength = GetWindowTextLength(GetDlgItem(m_hWnd, IDC_VALUE));
  256. if(lLength < 0)
  257. {
  258. NTDM_EXIT(E_FAIL);
  259. }
  260. else if(0 == lLength)
  261. {
  262. m_vValue = _T("");
  263. }
  264. else
  265. {
  266. pszTemp = new TCHAR[lLength+1];
  267. if(!pszTemp)
  268. {
  269. NTDM_EXIT(E_OUTOFMEMORY);
  270. }
  271. NTDM_ERR_GETLASTERROR_IF_NULL(GetDlgItemText(m_hWnd, IDC_VALUE, pszTemp, lLength+1));
  272. m_vValue = pszTemp;
  273. NTDM_DELETE_OBJECT(pszTemp);
  274. }
  275. hr = S_OK;
  276. NTDM_END_METHOD()
  277. // cleanup
  278. NTDM_DELETE_OBJECT(pszTemp);
  279. if(SUCCEEDED(hr))
  280. {
  281. EndDialog(m_hWnd, IDOK);
  282. }
  283. return hr;
  284. }
  285. //-------------------------------------------------------------------------
  286. // CEditNumberPropertyDlg
  287. //-------------------------------------------------------------------------
  288. INT_PTR CALLBACK EditNumberPropertyDlgProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)
  289. {
  290. if(g_pEditNumberPropertyDlg)
  291. {
  292. return g_pEditNumberPropertyDlg->EditNumberPropertyDlgProc(hDlg, iMessage, wParam, lParam);
  293. }
  294. return FALSE;
  295. }
  296. //-------------------------------------------------------------------------
  297. CEditNumberPropertyDlg::CEditNumberPropertyDlg(LPCTSTR pszName, LPCTSTR pszType, VARIANT * pvValue)
  298. :CEditPropertyDlg(pszName, pszType, pvValue)
  299. {
  300. }
  301. //-------------------------------------------------------------------------
  302. CEditNumberPropertyDlg::~CEditNumberPropertyDlg()
  303. {
  304. }
  305. //-------------------------------------------------------------------------
  306. INT_PTR CALLBACK CEditNumberPropertyDlg::EditNumberPropertyDlgProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)
  307. {
  308. LPPSHNOTIFY lppsn = NULL;
  309. switch(iMessage)
  310. {
  311. case WM_INITDIALOG:
  312. {
  313. m_hWnd = hDlg;
  314. InitializeDialog();
  315. break;
  316. }
  317. case WM_DESTROY:
  318. {
  319. DestroyDialog();
  320. break;
  321. }
  322. case WM_COMMAND:
  323. {
  324. switch(LOWORD(wParam))
  325. {
  326. case IDOK:
  327. {
  328. OnOK();
  329. return TRUE;
  330. break;
  331. }
  332. case IDCANCEL:
  333. {
  334. EndDialog(m_hWnd, IDCANCEL);
  335. return TRUE;
  336. break;
  337. }
  338. }
  339. break;
  340. }
  341. }
  342. return FALSE;
  343. }
  344. //---------------------------------------------------------------------------
  345. STDMETHODIMP CEditNumberPropertyDlg::InitializeDialog()
  346. {
  347. HRESULT hr;
  348. NTDM_BEGIN_METHOD()
  349. CEditPropertyDlg::InitializeDialog();
  350. // Set the number property
  351. NTDM_ERR_GETLASTERROR_IF_NULL(SetDlgItemInt(m_hWnd, IDC_VALUE, V_I4(&m_vValue), FALSE));
  352. NTDM_END_METHOD()
  353. // cleanup
  354. return hr;
  355. }
  356. //---------------------------------------------------------------------------
  357. STDMETHODIMP CEditNumberPropertyDlg::DestroyDialog()
  358. {
  359. HRESULT hr;
  360. NTDM_BEGIN_METHOD()
  361. CEditPropertyDlg::DestroyDialog();
  362. NTDM_END_METHOD()
  363. // cleanup
  364. return hr;
  365. }
  366. //---------------------------------------------------------------------------
  367. STDMETHODIMP CEditNumberPropertyDlg::OnOK()
  368. {
  369. HRESULT hr;
  370. long lValue;
  371. BOOL bTranslated;
  372. NTDM_BEGIN_METHOD()
  373. lValue = GetDlgItemInt(m_hWnd, IDC_VALUE, &bTranslated, FALSE);
  374. NTDM_ERR_GETLASTERROR_IF_FALSE(bTranslated);
  375. m_vValue = lValue;
  376. hr = S_OK;
  377. NTDM_END_METHOD()
  378. // cleanup
  379. if(SUCCEEDED(hr))
  380. {
  381. EndDialog(m_hWnd, IDOK);
  382. }
  383. return hr;
  384. }
  385. //-------------------------------------------------------------------------
  386. // CEditRulesPropertyDlg
  387. //-------------------------------------------------------------------------
  388. INT_PTR CALLBACK EditRulesPropertyDlgProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)
  389. {
  390. if(g_pEditRulesPropertyDlg)
  391. {
  392. return g_pEditRulesPropertyDlg->EditRulesPropertyDlgProc(hDlg, iMessage, wParam, lParam);
  393. }
  394. return FALSE;
  395. }
  396. //-------------------------------------------------------------------------
  397. CEditRulesPropertyDlg::CEditRulesPropertyDlg(LPCTSTR pszName, LPCTSTR pszType, VARIANT * pvValue, IWbemServices *pIWbemServices)
  398. :CEditPropertyDlg(pszName, pszType, pvValue)
  399. {
  400. m_pIWbemServices = pIWbemServices;
  401. }
  402. //-------------------------------------------------------------------------
  403. CEditRulesPropertyDlg::~CEditRulesPropertyDlg()
  404. {
  405. }
  406. //-------------------------------------------------------------------------
  407. INT_PTR CALLBACK CEditRulesPropertyDlg::EditRulesPropertyDlgProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)
  408. {
  409. LPPSHNOTIFY lppsn = NULL;
  410. switch(iMessage)
  411. {
  412. case WM_INITDIALOG:
  413. {
  414. m_hWnd = hDlg;
  415. InitializeDialog();
  416. break;
  417. }
  418. case WM_DESTROY:
  419. {
  420. DestroyDialog();
  421. break;
  422. }
  423. case WM_COMMAND:
  424. {
  425. switch(LOWORD(wParam))
  426. {
  427. case IDOK:
  428. {
  429. OnOK();
  430. return TRUE;
  431. break;
  432. }
  433. case IDCANCEL:
  434. {
  435. EndDialog(m_hWnd, IDCANCEL);
  436. return TRUE;
  437. break;
  438. }
  439. }
  440. if(BN_CLICKED == HIWORD(wParam) && IDC_ADD == LOWORD(wParam))
  441. {
  442. OnAdd();
  443. return TRUE;
  444. }
  445. if(BN_CLICKED == HIWORD(wParam) && IDC_EDIT == LOWORD(wParam))
  446. {
  447. OnEdit();
  448. return TRUE;
  449. }
  450. if(BN_CLICKED == HIWORD(wParam) && IDC_DELETE == LOWORD(wParam))
  451. {
  452. OnDelete();
  453. return TRUE;
  454. }
  455. break;
  456. }
  457. case WM_NOTIFY:
  458. {
  459. LPNMHDR lpnm = (LPNMHDR) lParam;
  460. switch (lpnm->code)
  461. {
  462. case NM_DBLCLK :
  463. {
  464. if(lpnm->idFrom == IDC_FILTER_ELEMENTS_LIST)
  465. {
  466. OnEdit();
  467. return TRUE;
  468. }
  469. break;
  470. }
  471. default :
  472. break;
  473. }
  474. }
  475. }
  476. return FALSE;
  477. }
  478. //---------------------------------------------------------------------------
  479. STDMETHODIMP CEditRulesPropertyDlg::InitializeDialog()
  480. {
  481. HRESULT hr;
  482. LVCOLUMN lvColumn;
  483. CComBSTR bstrName;
  484. NTDM_BEGIN_METHOD()
  485. CEditPropertyDlg::InitializeDialog();
  486. bstrName.LoadString(_Module.GetResourceInstance(), IDS_NAME);
  487. m_hwndListView = GetDlgItem(m_hWnd, IDC_FILTER_ELEMENTS_LIST);
  488. NTDM_ERR_IF_NULL(m_hwndListView);
  489. ListView_SetExtendedListViewStyle(m_hwndListView, LVS_EX_FULLROWSELECT);
  490. lvColumn.mask = LVCF_TEXT|LVCF_FMT;
  491. lvColumn.fmt = LVCFMT_LEFT;
  492. lvColumn.pszText = bstrName;
  493. NTDM_ERR_IF_MINUSONE(ListView_InsertColumn(m_hwndListView, 0, &lvColumn));
  494. NTDM_ERR_IF_FALSE(ListView_SetColumnWidth(m_hwndListView, 0, LVSCW_AUTOSIZE_USEHEADER));
  495. NTDM_ERR_IF_FAIL(PopulateItems());
  496. NTDM_END_METHOD()
  497. // cleanup
  498. return hr;
  499. }
  500. //---------------------------------------------------------------------------
  501. STDMETHODIMP CEditRulesPropertyDlg::ClearItems()
  502. {
  503. HRESULT hr;
  504. LVITEM lvItem;
  505. long lCount;
  506. NTDM_BEGIN_METHOD()
  507. //Release each item in the ListView Control
  508. lvItem.mask = LVIF_PARAM;
  509. lvItem.iSubItem = 0;
  510. lCount = ListView_GetItemCount(m_hwndListView);
  511. while(lCount > 0)
  512. {
  513. lCount--;
  514. lvItem.iItem = lCount;
  515. NTDM_ERR_IF_FALSE(ListView_GetItem(m_hwndListView, &lvItem));
  516. if(lvItem.lParam)
  517. {
  518. ((IWbemClassObject *)lvItem.lParam)->Release();
  519. }
  520. }
  521. ListView_DeleteAllItems(m_hwndListView);
  522. NTDM_END_METHOD()
  523. // cleanup
  524. return hr;
  525. }
  526. //---------------------------------------------------------------------------
  527. STDMETHODIMP CEditRulesPropertyDlg::PopulateItems()
  528. {
  529. HRESULT hr;
  530. CComVariant vValue;
  531. SAFEARRAY *psaRules = NULL;
  532. long lLower, lUpper, i;
  533. NTDM_BEGIN_METHOD()
  534. NTDM_ERR_IF_FAIL(ClearItems());
  535. // Set the Rules property
  536. psaRules = V_ARRAY(&m_vValue);
  537. NTDM_ERR_MSG_IF_FAIL(SafeArrayGetUBound(psaRules, 1, &lUpper));
  538. NTDM_ERR_MSG_IF_FAIL(SafeArrayGetLBound(psaRules, 1, &lLower));
  539. for(i=lLower; i<=lUpper; i++)
  540. {
  541. if(V_VT(&m_vValue) & VT_UNKNOWN)
  542. {
  543. // Rules or UNKNOWNS (i.e. IWbemClassObjects)
  544. IUnknown * pUnk = NULL;
  545. CComPtr<IWbemClassObject> pIWbemClassObject;
  546. NTDM_ERR_MSG_IF_FAIL(SafeArrayGetElement(psaRules, &i, (void *)&pUnk));
  547. NTDM_ERR_MSG_IF_FAIL(pUnk->QueryInterface(IID_IWbemClassObject, (void **)&pIWbemClassObject));
  548. // Show Properties of this object
  549. NTDM_ERR_IF_FAIL(AddItemToList(pIWbemClassObject));
  550. }
  551. }
  552. NTDM_END_METHOD()
  553. // cleanup
  554. return hr;
  555. }
  556. //---------------------------------------------------------------------------
  557. STDMETHODIMP CEditRulesPropertyDlg::AddItemToList(IWbemClassObject * pIWbemClassObject, long lIndex)
  558. {
  559. HRESULT hr;
  560. CComVariant vValue;
  561. CIMTYPE cimType;
  562. LVITEM lvItem;
  563. NTDM_BEGIN_METHOD()
  564. NTDM_ERR_MSG_IF_FAIL(pIWbemClassObject->Get(_T("Query"), 0, &vValue, &cimType, NULL));
  565. lvItem.iItem = lIndex;
  566. lvItem.mask = LVIF_TEXT|LVIF_PARAM;
  567. lvItem.iSubItem = 0;
  568. lvItem.pszText = vValue.bstrVal;
  569. lvItem.lParam = (LPARAM)pIWbemClassObject;
  570. lvItem.iItem = ListView_InsertItem(m_hwndListView, &lvItem);
  571. NTDM_ERR_IF_MINUSONE(lvItem.iItem);
  572. pIWbemClassObject->AddRef();
  573. NTDM_END_METHOD()
  574. // cleanup
  575. return hr;
  576. }
  577. //---------------------------------------------------------------------------
  578. STDMETHODIMP CEditRulesPropertyDlg::DestroyDialog()
  579. {
  580. HRESULT hr;
  581. NTDM_BEGIN_METHOD()
  582. CEditPropertyDlg::DestroyDialog();
  583. NTDM_ERR_IF_FAIL(ClearItems());
  584. NTDM_END_METHOD()
  585. // cleanup
  586. return hr;
  587. }
  588. //---------------------------------------------------------------------------
  589. STDMETHODIMP CEditRulesPropertyDlg::OnEdit()
  590. {
  591. HRESULT hr;
  592. long lSelectionMark;
  593. NTDM_BEGIN_METHOD()
  594. lSelectionMark = ListView_GetSelectionMark(m_hwndListView);
  595. if(-1 == lSelectionMark)
  596. {
  597. CNTDMUtils::DisplayMessage(m_hWnd, IDS_ERR_NO_RULE_SELECTED);
  598. goto error;
  599. }
  600. else
  601. {
  602. // get a pointer to the IWbemClassObject
  603. LVITEM lvItem;
  604. lvItem.mask = LVIF_PARAM;
  605. lvItem.iSubItem = 0;
  606. lvItem.iItem = lSelectionMark;
  607. NTDM_ERR_IF_FALSE(ListView_GetItem(m_hwndListView, &lvItem));
  608. if(lvItem.lParam)
  609. {
  610. VARIANT vValue;
  611. VariantInit(&vValue);
  612. IWbemClassObject *pIWbemClassObject;
  613. pIWbemClassObject = (IWbemClassObject *)lvItem.lParam;
  614. V_VT(&vValue) = VT_UNKNOWN;
  615. pIWbemClassObject->QueryInterface(IID_IUnknown, (void **)&V_UNKNOWN(&vValue));
  616. CEditProperty editProp(m_hWnd, _T(""), _T(""), &vValue, m_pIWbemServices, CEditProperty::psc_rule);
  617. if(IDOK == editProp.Run())
  618. {
  619. ListView_DeleteItem(m_hwndListView, lSelectionMark);
  620. AddItemToList(pIWbemClassObject, lSelectionMark);
  621. pIWbemClassObject->Release();
  622. }
  623. }
  624. }
  625. NTDM_END_METHOD()
  626. // cleanup
  627. return hr;
  628. }
  629. //---------------------------------------------------------------------------
  630. STDMETHODIMP CEditRulesPropertyDlg::OnAdd()
  631. {
  632. HRESULT hr;
  633. CComPtr<IWbemClassObject>pIWbemClassObject;
  634. CComPtr<IWbemClassObject>pIWbemNewInstance;
  635. VARIANT vValue;
  636. CComBSTR bstrTemp;
  637. NTDM_BEGIN_METHOD()
  638. bstrTemp = _T("MSFT_Rule");
  639. NTDM_ERR_MSG_IF_FAIL(m_pIWbemServices->GetObject(bstrTemp, 0, NULL, &pIWbemClassObject, NULL));
  640. NTDM_ERR_MSG_IF_FAIL(pIWbemClassObject->SpawnInstance(0, &pIWbemNewInstance));
  641. VariantInit(&vValue);
  642. V_VT(&vValue) = VT_UNKNOWN;
  643. pIWbemNewInstance->QueryInterface(IID_IUnknown, (void **)&V_UNKNOWN(&vValue));
  644. CEditProperty editProp(m_hWnd, _T(""), _T(""), &vValue, m_pIWbemServices, CEditProperty::psc_rule);
  645. if(IDOK == editProp.Run())
  646. {
  647. AddItemToList(pIWbemNewInstance);
  648. }
  649. NTDM_END_METHOD()
  650. // cleanup
  651. return hr;
  652. }
  653. //---------------------------------------------------------------------------
  654. STDMETHODIMP CEditRulesPropertyDlg::OnDelete()
  655. {
  656. HRESULT hr;
  657. long lSelectionMark;
  658. NTDM_BEGIN_METHOD()
  659. lSelectionMark = ListView_GetSelectionMark(m_hwndListView);
  660. if(-1 == lSelectionMark)
  661. {
  662. CNTDMUtils::DisplayMessage(m_hWnd, IDS_ERR_NO_RULE_SELECTED);
  663. goto error;
  664. }
  665. else
  666. {
  667. // get a pointer to the IWbemClassObject
  668. LVITEM lvItem;
  669. lvItem.mask = LVIF_PARAM;
  670. lvItem.iSubItem = 0;
  671. lvItem.iItem = lSelectionMark;
  672. NTDM_ERR_IF_FALSE(ListView_GetItem(m_hwndListView, &lvItem));
  673. if(lvItem.lParam)
  674. {
  675. IWbemClassObject *pIWbemClassObject = NULL;
  676. pIWbemClassObject = (IWbemClassObject *)lvItem.lParam;
  677. pIWbemClassObject->Release();
  678. ListView_DeleteItem(m_hwndListView, lSelectionMark);
  679. }
  680. }
  681. NTDM_END_METHOD()
  682. // cleanup
  683. return hr;
  684. }
  685. //---------------------------------------------------------------------------
  686. STDMETHODIMP CEditRulesPropertyDlg::OnOK()
  687. {
  688. HRESULT hr;
  689. VARIANT vValue;
  690. SAFEARRAY *psaRules = NULL;
  691. long lCount = 0;
  692. SAFEARRAYBOUND rgsaBound[1];
  693. long rgIndices[1];
  694. long i;
  695. LVITEM lvItem;
  696. NTDM_BEGIN_METHOD()
  697. VariantInit(&vValue);
  698. // Get the size of the array
  699. lCount = ListView_GetItemCount(m_hwndListView);
  700. rgsaBound[0].lLbound = 0;
  701. rgsaBound[0].cElements = lCount;
  702. psaRules = SafeArrayCreate(VT_UNKNOWN, 1, rgsaBound);
  703. //Release each item in the ListView Control
  704. lvItem.mask = LVIF_PARAM;
  705. lvItem.iSubItem = 0;
  706. lCount = ListView_GetItemCount(m_hwndListView);
  707. i=0;
  708. while(i < lCount)
  709. {
  710. IUnknown * pUnk = NULL;
  711. lvItem.iItem = i;
  712. NTDM_ERR_IF_FALSE(ListView_GetItem(m_hwndListView, &lvItem));
  713. if(lvItem.lParam)
  714. {
  715. NTDM_ERR_MSG_IF_FAIL(((IWbemClassObject *)lvItem.lParam)->QueryInterface(IID_IUnknown, (void**)&pUnk));
  716. rgIndices[0] = i;
  717. NTDM_ERR_MSG_IF_FAIL(SafeArrayPutElement(psaRules, rgIndices, pUnk));
  718. pUnk->Release();
  719. }
  720. i++;
  721. }
  722. VariantClear(&vValue);
  723. V_VT(&vValue) = VT_ARRAY|VT_UNKNOWN;
  724. V_ARRAY(&vValue) = psaRules;
  725. m_vValue.Clear();
  726. m_vValue.Copy(&vValue);
  727. //m_vValue = vValue;
  728. hr = S_OK;
  729. NTDM_END_METHOD()
  730. // cleanup
  731. VariantClear(&vValue);
  732. if(SUCCEEDED(hr))
  733. {
  734. EndDialog(m_hWnd, IDOK);
  735. }
  736. return hr;
  737. }
  738. //-------------------------------------------------------------------------
  739. // CEditRulePropertyDlg
  740. //-------------------------------------------------------------------------
  741. INT_PTR CALLBACK EditRulePropertyDlgProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)
  742. {
  743. if(g_pEditRulePropertyDlg)
  744. {
  745. return g_pEditRulePropertyDlg->EditRulePropertyDlgProc(hDlg, iMessage, wParam, lParam);
  746. }
  747. return FALSE;
  748. }
  749. //-------------------------------------------------------------------------
  750. CEditRulePropertyDlg::CEditRulePropertyDlg(IWbemClassObject* pIWbemClassObject)
  751. {
  752. m_pIWbemClassObject = pIWbemClassObject;
  753. }
  754. //-------------------------------------------------------------------------
  755. CEditRulePropertyDlg::~CEditRulePropertyDlg()
  756. {
  757. }
  758. //-------------------------------------------------------------------------
  759. INT_PTR CALLBACK CEditRulePropertyDlg::EditRulePropertyDlgProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)
  760. {
  761. LPPSHNOTIFY lppsn = NULL;
  762. switch(iMessage)
  763. {
  764. case WM_INITDIALOG:
  765. {
  766. m_hWnd = hDlg;
  767. InitializeDialog();
  768. break;
  769. }
  770. case WM_DESTROY:
  771. {
  772. DestroyDialog();
  773. break;
  774. }
  775. case WM_COMMAND:
  776. {
  777. switch(LOWORD(wParam))
  778. {
  779. case IDOK:
  780. {
  781. OnOK();
  782. return TRUE;
  783. break;
  784. }
  785. case IDCANCEL:
  786. {
  787. EndDialog(m_hWnd, IDCANCEL);
  788. return TRUE;
  789. break;
  790. }
  791. }
  792. break;
  793. }
  794. }
  795. return FALSE;
  796. }
  797. //---------------------------------------------------------------------------
  798. STDMETHODIMP CEditRulePropertyDlg::InitializeDialog()
  799. {
  800. HRESULT hr;
  801. CComVariant vValue;
  802. CIMTYPE cimType;
  803. NTDM_BEGIN_METHOD()
  804. NTDM_ERR_MSG_IF_FAIL(m_pIWbemClassObject->Get(_T("QueryLanguage"), 0, &vValue, &cimType, NULL));
  805. if(vValue.bstrVal)
  806. {
  807. SetDlgItemText(m_hWnd, IDC_QUERY_LANGUAGE, vValue.bstrVal);
  808. }
  809. vValue.Clear();
  810. NTDM_ERR_MSG_IF_FAIL(m_pIWbemClassObject->Get(_T("TargetNamespace"), 0, &vValue, &cimType, NULL));
  811. if(vValue.bstrVal)
  812. {
  813. SetDlgItemText(m_hWnd, IDC_TARGET_NAMESPACE, vValue.bstrVal);
  814. }
  815. vValue.Clear();
  816. NTDM_ERR_MSG_IF_FAIL(m_pIWbemClassObject->Get(_T("Query"), 0, &vValue, &cimType, NULL));
  817. if(vValue.bstrVal)
  818. {
  819. SetDlgItemText(m_hWnd, IDC_QUERY, vValue.bstrVal);
  820. }
  821. vValue.Clear();
  822. NTDM_END_METHOD()
  823. // cleanup
  824. return hr;
  825. }
  826. //---------------------------------------------------------------------------
  827. STDMETHODIMP CEditRulePropertyDlg::DestroyDialog()
  828. {
  829. HRESULT hr;
  830. NTDM_BEGIN_METHOD()
  831. NTDM_END_METHOD()
  832. // cleanup
  833. return hr;
  834. }
  835. //---------------------------------------------------------------------------
  836. STDMETHODIMP CEditRulePropertyDlg::OnOK()
  837. {
  838. HRESULT hr;
  839. NTDM_BEGIN_METHOD()
  840. // Set the Properties
  841. NTDM_ERR_IF_FAIL(CNTDMUtils::SetStringProperty(m_pIWbemClassObject, _T("QueryLanguage"), m_hWnd, IDC_QUERY_LANGUAGE));
  842. NTDM_ERR_IF_FAIL(CNTDMUtils::SetStringProperty(m_pIWbemClassObject, _T("TargetNamespace"), m_hWnd, IDC_TARGET_NAMESPACE));
  843. NTDM_ERR_IF_FAIL(CNTDMUtils::SetStringProperty(m_pIWbemClassObject, _T("Query"), m_hWnd, IDC_QUERY));
  844. NTDM_END_METHOD()
  845. // cleanup
  846. if(SUCCEEDED(hr))
  847. {
  848. EndDialog(m_hWnd, IDOK);
  849. }
  850. return hr;
  851. }
  852. //-------------------------------------------------------------------------
  853. // CEditRangeParametersPropertyDlg
  854. //-------------------------------------------------------------------------
  855. INT_PTR CALLBACK EditRangeParametersPropertyDlgProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)
  856. {
  857. if(g_pEditRangeParametersPropertyDlg)
  858. {
  859. return g_pEditRangeParametersPropertyDlg->EditRangeParametersPropertyDlgProc(hDlg, iMessage, wParam, lParam);
  860. }
  861. return FALSE;
  862. }
  863. //-------------------------------------------------------------------------
  864. CEditRangeParametersPropertyDlg::CEditRangeParametersPropertyDlg(LPCTSTR pszName, LPCTSTR pszType, VARIANT * pvValue, IWbemServices *pIWbemServices)
  865. :CEditPropertyDlg(pszName, pszType, pvValue)
  866. {
  867. m_pIWbemServices = pIWbemServices;
  868. }
  869. //-------------------------------------------------------------------------
  870. CEditRangeParametersPropertyDlg::~CEditRangeParametersPropertyDlg()
  871. {
  872. }
  873. //-------------------------------------------------------------------------
  874. INT_PTR CALLBACK CEditRangeParametersPropertyDlg::EditRangeParametersPropertyDlgProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)
  875. {
  876. LPPSHNOTIFY lppsn = NULL;
  877. switch(iMessage)
  878. {
  879. case WM_INITDIALOG:
  880. {
  881. m_hWnd = hDlg;
  882. InitializeDialog();
  883. break;
  884. }
  885. case WM_DESTROY:
  886. {
  887. DestroyDialog();
  888. break;
  889. }
  890. case WM_COMMAND:
  891. {
  892. switch(LOWORD(wParam))
  893. {
  894. case IDOK:
  895. {
  896. OnOK();
  897. return TRUE;
  898. break;
  899. }
  900. case IDCANCEL:
  901. {
  902. EndDialog(m_hWnd, IDCANCEL);
  903. return TRUE;
  904. break;
  905. }
  906. }
  907. if(BN_CLICKED == HIWORD(wParam) && IDC_ADD == LOWORD(wParam))
  908. {
  909. OnAdd();
  910. return TRUE;
  911. }
  912. if(BN_CLICKED == HIWORD(wParam) && IDC_EDIT == LOWORD(wParam))
  913. {
  914. OnEdit();
  915. return TRUE;
  916. }
  917. if(BN_CLICKED == HIWORD(wParam) && IDC_DELETE == LOWORD(wParam))
  918. {
  919. OnDelete();
  920. return TRUE;
  921. }
  922. break;
  923. }
  924. case WM_NOTIFY:
  925. {
  926. LPNMHDR lpnm = (LPNMHDR) lParam;
  927. switch (lpnm->code)
  928. {
  929. case NM_DBLCLK :
  930. {
  931. if(lpnm->idFrom == IDC_RANGE_PARAMETER_LIST)
  932. {
  933. OnEdit();
  934. return TRUE;
  935. }
  936. break;
  937. }
  938. default :
  939. break;
  940. }
  941. }
  942. }
  943. return FALSE;
  944. }
  945. //---------------------------------------------------------------------------
  946. STDMETHODIMP CEditRangeParametersPropertyDlg::InitializeDialog()
  947. {
  948. HRESULT hr;
  949. LVCOLUMN lvColumn;
  950. CComBSTR bstrName;
  951. NTDM_BEGIN_METHOD()
  952. CEditPropertyDlg::InitializeDialog();
  953. bstrName.LoadString(_Module.GetResourceInstance(), IDS_NAME);
  954. m_hwndListView = GetDlgItem(m_hWnd, IDC_RANGE_PARAMETER_LIST);
  955. NTDM_ERR_IF_NULL(m_hwndListView);
  956. ListView_SetExtendedListViewStyle(m_hwndListView, LVS_EX_FULLROWSELECT);
  957. lvColumn.mask = LVCF_TEXT|LVCF_FMT;
  958. lvColumn.fmt = LVCFMT_LEFT;
  959. lvColumn.pszText = bstrName;
  960. NTDM_ERR_IF_MINUSONE(ListView_InsertColumn(m_hwndListView, 0, &lvColumn));
  961. NTDM_ERR_IF_FALSE(ListView_SetColumnWidth(m_hwndListView, 0, LVSCW_AUTOSIZE_USEHEADER));
  962. NTDM_ERR_IF_FAIL(PopulateItems());
  963. NTDM_END_METHOD()
  964. // cleanup
  965. return hr;
  966. }
  967. //---------------------------------------------------------------------------
  968. STDMETHODIMP CEditRangeParametersPropertyDlg::ClearItems()
  969. {
  970. HRESULT hr;
  971. LVITEM lvItem;
  972. long lCount;
  973. NTDM_BEGIN_METHOD()
  974. //Release each item in the ListView Control
  975. lvItem.mask = LVIF_PARAM;
  976. lvItem.iSubItem = 0;
  977. lCount = ListView_GetItemCount(m_hwndListView);
  978. while(lCount > 0)
  979. {
  980. lCount--;
  981. lvItem.iItem = lCount;
  982. NTDM_ERR_IF_FALSE(ListView_GetItem(m_hwndListView, &lvItem));
  983. if(lvItem.lParam)
  984. {
  985. ((IWbemClassObject *)lvItem.lParam)->Release();
  986. }
  987. }
  988. ListView_DeleteAllItems(m_hwndListView);
  989. NTDM_END_METHOD()
  990. // cleanup
  991. return hr;
  992. }
  993. //---------------------------------------------------------------------------
  994. STDMETHODIMP CEditRangeParametersPropertyDlg::PopulateItems()
  995. {
  996. HRESULT hr;
  997. CComVariant vValue;
  998. SAFEARRAY *psaRangeParameters = NULL;
  999. long lLower, lUpper, i;
  1000. NTDM_BEGIN_METHOD()
  1001. NTDM_ERR_IF_FAIL(ClearItems());
  1002. // Set the RangeParameters property
  1003. psaRangeParameters = V_ARRAY(&m_vValue);
  1004. NTDM_ERR_MSG_IF_FAIL(SafeArrayGetUBound(psaRangeParameters, 1, &lUpper));
  1005. NTDM_ERR_MSG_IF_FAIL(SafeArrayGetLBound(psaRangeParameters, 1, &lLower));
  1006. for(i=lLower; i<=lUpper; i++)
  1007. {
  1008. if(V_VT(&m_vValue) & VT_UNKNOWN)
  1009. {
  1010. // RangeParameters or UNKNOWNS (i.e. IWbemClassObjects)
  1011. IUnknown * pUnk = NULL;
  1012. CComPtr<IWbemClassObject> pIWbemClassObject;
  1013. NTDM_ERR_MSG_IF_FAIL(SafeArrayGetElement(psaRangeParameters, &i, (void *)&pUnk));
  1014. NTDM_ERR_MSG_IF_FAIL(pUnk->QueryInterface(IID_IWbemClassObject, (void **)&pIWbemClassObject));
  1015. // Show Properties of this object
  1016. NTDM_ERR_IF_FAIL(AddItemToList(pIWbemClassObject));
  1017. }
  1018. }
  1019. NTDM_END_METHOD()
  1020. // cleanup
  1021. return hr;
  1022. }
  1023. //---------------------------------------------------------------------------
  1024. STDMETHODIMP CEditRangeParametersPropertyDlg::AddItemToList(IWbemClassObject * pIWbemClassObject, long lIndex)
  1025. {
  1026. HRESULT hr;
  1027. CComVariant vValue;
  1028. CIMTYPE cimType;
  1029. LVITEM lvItem;
  1030. NTDM_BEGIN_METHOD()
  1031. NTDM_ERR_MSG_IF_FAIL(pIWbemClassObject->Get(_T("PropertyName"), 0, &vValue, &cimType, NULL));
  1032. lvItem.iItem = lIndex;
  1033. lvItem.mask = LVIF_TEXT|LVIF_PARAM;
  1034. lvItem.iSubItem = 0;
  1035. lvItem.pszText = vValue.bstrVal;
  1036. lvItem.lParam = (LPARAM)pIWbemClassObject;
  1037. lvItem.iItem = ListView_InsertItem(m_hwndListView, &lvItem);
  1038. NTDM_ERR_IF_MINUSONE(lvItem.iItem);
  1039. pIWbemClassObject->AddRef();
  1040. NTDM_END_METHOD()
  1041. // cleanup
  1042. return hr;
  1043. }
  1044. //---------------------------------------------------------------------------
  1045. STDMETHODIMP CEditRangeParametersPropertyDlg::DestroyDialog()
  1046. {
  1047. HRESULT hr;
  1048. NTDM_BEGIN_METHOD()
  1049. CEditPropertyDlg::DestroyDialog();
  1050. NTDM_ERR_IF_FAIL(ClearItems());
  1051. NTDM_END_METHOD()
  1052. // cleanup
  1053. return hr;
  1054. }
  1055. //---------------------------------------------------------------------------
  1056. STDMETHODIMP CEditRangeParametersPropertyDlg::OnEdit()
  1057. {
  1058. HRESULT hr;
  1059. long lSelectionMark;
  1060. VARIANT vValue;
  1061. NTDM_BEGIN_METHOD()
  1062. VariantInit(&vValue);
  1063. lSelectionMark = ListView_GetSelectionMark(m_hwndListView);
  1064. if(-1 == lSelectionMark)
  1065. {
  1066. CNTDMUtils::DisplayMessage(m_hWnd, IDS_ERR_NO_RANGE_SELECTED);
  1067. goto error;
  1068. }
  1069. else
  1070. {
  1071. // get a pointer to the IWbemClassObject
  1072. LVITEM lvItem;
  1073. lvItem.mask = LVIF_PARAM;
  1074. lvItem.iSubItem = 0;
  1075. lvItem.iItem = lSelectionMark;
  1076. NTDM_ERR_IF_FALSE(ListView_GetItem(m_hwndListView, &lvItem));
  1077. if(lvItem.lParam)
  1078. {
  1079. IWbemClassObject *pIWbemClassObject;
  1080. pIWbemClassObject = (IWbemClassObject *)lvItem.lParam;
  1081. V_VT(&vValue) = VT_UNKNOWN;
  1082. pIWbemClassObject->QueryInterface(IID_IUnknown, (void **)&V_UNKNOWN(&vValue));
  1083. CEditProperty editProp(m_hWnd, _T(""), _T(""), &vValue, m_pIWbemServices, CEditProperty::psc_range);
  1084. if(IDOK == editProp.Run())
  1085. {
  1086. NTDM_ERR_IF_FAIL(V_UNKNOWN(&vValue)->QueryInterface(IID_IWbemClassObject, (void **)&pIWbemClassObject));
  1087. ListView_DeleteItem(m_hwndListView, lSelectionMark);
  1088. AddItemToList(pIWbemClassObject, lSelectionMark);
  1089. pIWbemClassObject->Release();
  1090. }
  1091. }
  1092. }
  1093. NTDM_END_METHOD()
  1094. // cleanup
  1095. VariantClear(&vValue);
  1096. return hr;
  1097. }
  1098. //---------------------------------------------------------------------------
  1099. STDMETHODIMP CEditRangeParametersPropertyDlg::OnAdd()
  1100. {
  1101. HRESULT hr;
  1102. long lSelectionMark;
  1103. VARIANT vValue;
  1104. VARIANT vValue2;
  1105. CComPtr<IWbemClassObject>pIWbemClassObject;
  1106. CComPtr<IWbemClassObject>pIWbemInstanceObject;
  1107. CComBSTR bstrTemp;
  1108. CIMTYPE cimType;
  1109. NTDM_BEGIN_METHOD()
  1110. VariantInit(&vValue);
  1111. bstrTemp = _T("MSFT_SintRangeParam");
  1112. NTDM_ERR_MSG_IF_FAIL(m_pIWbemServices->GetObject(bstrTemp, 0, NULL, &pIWbemClassObject, NULL));
  1113. NTDM_ERR_MSG_IF_FAIL(pIWbemClassObject->SpawnInstance(0, &pIWbemInstanceObject));
  1114. // Set some default values
  1115. cimType = CIM_SINT32;
  1116. VariantInit(&vValue2);
  1117. V_VT(&vValue2) = VT_I4;
  1118. V_I4(&vValue2) = 5;
  1119. NTDM_ERR_MSG_IF_FAIL(pIWbemInstanceObject->Put(_T("Default"), 0, &vValue2, cimType));
  1120. V_I4(&vValue2) = 0;
  1121. NTDM_ERR_MSG_IF_FAIL(pIWbemInstanceObject->Put(_T("Min"), 0, &vValue2, cimType));
  1122. V_I4(&vValue2) = 10;
  1123. NTDM_ERR_MSG_IF_FAIL(pIWbemInstanceObject->Put(_T("Max"), 0, &vValue2, cimType));
  1124. cimType = CIM_UINT8;
  1125. V_VT(&vValue2) = VT_UI1;
  1126. V_UI1(&vValue2) = 0;
  1127. NTDM_ERR_MSG_IF_FAIL(pIWbemInstanceObject->Put(_T("TargetType"), 0, &vValue2, cimType));
  1128. V_VT(&vValue) = VT_UNKNOWN;
  1129. pIWbemInstanceObject->QueryInterface(IID_IUnknown, (void **)&V_UNKNOWN(&vValue));
  1130. CEditProperty editProp(m_hWnd, _T(""), _T(""), &vValue, m_pIWbemServices, CEditProperty::psc_range);
  1131. if(IDOK == editProp.Run())
  1132. {
  1133. NTDM_ERR_IF_FAIL(V_UNKNOWN(&vValue)->QueryInterface(IID_IWbemClassObject, (void **)&pIWbemInstanceObject));
  1134. AddItemToList(pIWbemInstanceObject);
  1135. }
  1136. NTDM_END_METHOD()
  1137. // cleanup
  1138. VariantClear(&vValue);
  1139. VariantClear(&vValue2);
  1140. return hr;
  1141. }
  1142. //---------------------------------------------------------------------------
  1143. STDMETHODIMP CEditRangeParametersPropertyDlg::OnDelete()
  1144. {
  1145. HRESULT hr;
  1146. long lSelectionMark;
  1147. NTDM_BEGIN_METHOD()
  1148. lSelectionMark = ListView_GetSelectionMark(m_hwndListView);
  1149. if(-1 == lSelectionMark)
  1150. {
  1151. CNTDMUtils::DisplayMessage(m_hWnd, IDS_ERR_NO_RULE_SELECTED);
  1152. goto error;
  1153. }
  1154. else
  1155. {
  1156. // get a pointer to the IWbemClassObject
  1157. LVITEM lvItem;
  1158. lvItem.mask = LVIF_PARAM;
  1159. lvItem.iSubItem = 0;
  1160. lvItem.iItem = lSelectionMark;
  1161. NTDM_ERR_IF_FALSE(ListView_GetItem(m_hwndListView, &lvItem));
  1162. if(lvItem.lParam)
  1163. {
  1164. IWbemClassObject *pIWbemClassObject = NULL;
  1165. pIWbemClassObject = (IWbemClassObject *)lvItem.lParam;
  1166. pIWbemClassObject->Release();
  1167. ListView_DeleteItem(m_hwndListView, lSelectionMark);
  1168. }
  1169. }
  1170. NTDM_END_METHOD()
  1171. // cleanup
  1172. return hr;
  1173. }
  1174. //---------------------------------------------------------------------------
  1175. STDMETHODIMP CEditRangeParametersPropertyDlg::OnOK()
  1176. {
  1177. HRESULT hr;
  1178. VARIANT vValue;
  1179. SAFEARRAY *psaRangeParameters = NULL;
  1180. long lCount = 0;
  1181. SAFEARRAYBOUND rgsaBound[1];
  1182. long rgIndices[1];
  1183. long i;
  1184. LVITEM lvItem;
  1185. NTDM_BEGIN_METHOD()
  1186. VariantInit(&vValue);
  1187. // Get the size of the array
  1188. lCount = ListView_GetItemCount(m_hwndListView);
  1189. rgsaBound[0].lLbound = 0;
  1190. rgsaBound[0].cElements = lCount;
  1191. psaRangeParameters = SafeArrayCreate(VT_UNKNOWN, 1, rgsaBound);
  1192. //Release each item in the ListView Control
  1193. lvItem.mask = LVIF_PARAM;
  1194. lvItem.iSubItem = 0;
  1195. lCount = ListView_GetItemCount(m_hwndListView);
  1196. i=0;
  1197. while(i < lCount)
  1198. {
  1199. IUnknown * pUnk = NULL;
  1200. lvItem.iItem = i;
  1201. NTDM_ERR_IF_FALSE(ListView_GetItem(m_hwndListView, &lvItem));
  1202. if(lvItem.lParam)
  1203. {
  1204. NTDM_ERR_MSG_IF_FAIL(((IWbemClassObject *)lvItem.lParam)->QueryInterface(IID_IUnknown, (void**)&pUnk));
  1205. rgIndices[0] = i;
  1206. NTDM_ERR_MSG_IF_FAIL(SafeArrayPutElement(psaRangeParameters, rgIndices, pUnk));
  1207. pUnk->Release();
  1208. }
  1209. i++;
  1210. }
  1211. VariantClear(&vValue);
  1212. V_VT(&vValue) = VT_ARRAY|VT_UNKNOWN;
  1213. V_ARRAY(&vValue) = psaRangeParameters;
  1214. m_vValue.Clear();
  1215. m_vValue.Copy(&vValue);
  1216. //m_vValue = vValue;
  1217. hr = S_OK;
  1218. NTDM_END_METHOD()
  1219. // cleanup
  1220. VariantClear(&vValue);
  1221. if(SUCCEEDED(hr))
  1222. {
  1223. EndDialog(m_hWnd, IDOK);
  1224. }
  1225. return hr;
  1226. }
  1227. //-------------------------------------------------------------------------
  1228. // CEditRangeParameterPropertyDlg
  1229. //-------------------------------------------------------------------------
  1230. INT_PTR CALLBACK EditRangeParameterPropertyDlgProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)
  1231. {
  1232. if(g_pEditRangeParameterPropertyDlg)
  1233. {
  1234. return g_pEditRangeParameterPropertyDlg->EditRangeParameterPropertyDlgProc(hDlg, iMessage, wParam, lParam);
  1235. }
  1236. return FALSE;
  1237. }
  1238. //-------------------------------------------------------------------------
  1239. CEditRangeParameterPropertyDlg::CEditRangeParameterPropertyDlg(IWbemClassObject* pIWbemClassObject, IWbemServices* pIWbemServices)
  1240. {
  1241. m_pIWbemClassObject = pIWbemClassObject;
  1242. m_pIWbemServices = pIWbemServices;
  1243. }
  1244. //-------------------------------------------------------------------------
  1245. CEditRangeParameterPropertyDlg::~CEditRangeParameterPropertyDlg()
  1246. {
  1247. }
  1248. //-------------------------------------------------------------------------
  1249. INT_PTR CALLBACK CEditRangeParameterPropertyDlg::EditRangeParameterPropertyDlgProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)
  1250. {
  1251. LPPSHNOTIFY lppsn = NULL;
  1252. switch(iMessage)
  1253. {
  1254. case WM_INITDIALOG:
  1255. {
  1256. m_hWnd = hDlg;
  1257. InitializeDialog();
  1258. break;
  1259. }
  1260. case WM_DESTROY:
  1261. {
  1262. DestroyDialog();
  1263. break;
  1264. }
  1265. case WM_COMMAND:
  1266. {
  1267. switch(LOWORD(wParam))
  1268. {
  1269. case IDOK:
  1270. {
  1271. OnOK();
  1272. return TRUE;
  1273. break;
  1274. }
  1275. case IDCANCEL:
  1276. {
  1277. EndDialog(m_hWnd, IDCANCEL);
  1278. return TRUE;
  1279. break;
  1280. }
  1281. }
  1282. if(BN_CLICKED == HIWORD(wParam) && IDC_ADD == LOWORD(wParam))
  1283. {
  1284. OnAdd();
  1285. return TRUE;
  1286. }
  1287. if(BN_CLICKED == HIWORD(wParam) && IDC_EDIT == LOWORD(wParam))
  1288. {
  1289. OnEdit();
  1290. return TRUE;
  1291. }
  1292. if(BN_CLICKED == HIWORD(wParam) && IDC_DELETE == LOWORD(wParam))
  1293. {
  1294. OnDelete();
  1295. return TRUE;
  1296. }
  1297. if(CBN_SELCHANGE == HIWORD(wParam) && IDC_PARAMETER_TYPE == LOWORD(wParam))
  1298. {
  1299. ShowControls();
  1300. return TRUE;
  1301. }
  1302. break;
  1303. }
  1304. case WM_NOTIFY:
  1305. {
  1306. LPNMHDR lpnm = (LPNMHDR) lParam;
  1307. switch (lpnm->code)
  1308. {
  1309. case NM_DBLCLK :
  1310. {
  1311. if(lpnm->idFrom == IDC_RANGE_PARAMETER_LIST)
  1312. {
  1313. OnEdit();
  1314. return TRUE;
  1315. }
  1316. break;
  1317. }
  1318. default :
  1319. break;
  1320. }
  1321. }
  1322. }
  1323. return FALSE;
  1324. }
  1325. //---------------------------------------------------------------------------
  1326. STDMETHODIMP CEditRangeParameterPropertyDlg::InitializeDialog()
  1327. {
  1328. HRESULT hr;
  1329. CComBSTR bstrName;
  1330. CComVariant vValue;
  1331. CIMTYPE cimType;
  1332. CSimpleArray<BSTR> bstrArrayRangeTypes;
  1333. long lIndex;
  1334. NTDM_BEGIN_METHOD()
  1335. bstrName.LoadString(_Module.GetResourceInstance(), IDS_NAME);
  1336. m_hwndListView = GetDlgItem(m_hWnd, IDC_VALUES_SET_LIST);
  1337. NTDM_ERR_IF_NULL(m_hwndListView);
  1338. ListView_SetExtendedListViewStyle(m_hwndListView, LVS_EX_FULLROWSELECT);
  1339. // Set the standard props for all types of ranges
  1340. NTDM_ERR_MSG_IF_FAIL(m_pIWbemClassObject->Get(_T("PropertyName"), 0, &vValue, &cimType, NULL));
  1341. if(vValue.bstrVal)
  1342. {
  1343. SetDlgItemText(m_hWnd, IDC_PROPERTY_NAME, vValue.bstrVal);
  1344. }
  1345. vValue.Clear();
  1346. NTDM_ERR_MSG_IF_FAIL(m_pIWbemClassObject->Get(_T("TargetClass"), 0, &vValue, &cimType, NULL));
  1347. if(vValue.bstrVal)
  1348. {
  1349. SetDlgItemText(m_hWnd, IDC_TARGET_CLASS, vValue.bstrVal);
  1350. }
  1351. vValue.Clear();
  1352. NTDM_ERR_MSG_IF_FAIL(m_pIWbemClassObject->Get(_T("TargetType"), 0, &vValue, &cimType, NULL));
  1353. SetDlgItemInt(m_hWnd, IDC_TARGET_TYPE, V_UI1(&vValue), FALSE);
  1354. vValue.Clear();
  1355. NTDM_ERR_IF_FAIL(CNTDMUtils::GetValuesInList((long)IDS_RANGE_NAMES, bstrArrayRangeTypes));
  1356. lIndex = SendDlgItemMessage(m_hWnd, IDC_PARAMETER_TYPE, CB_ADDSTRING, 0, (LPARAM)bstrArrayRangeTypes[0]);
  1357. NTDM_CHECK_CB_ERR(lIndex);
  1358. NTDM_CHECK_CB_ERR(SendDlgItemMessage(m_hWnd, IDC_PARAMETER_TYPE, CB_SETITEMDATA, lIndex, (LPARAM)rt_sintrange));
  1359. lIndex = SendDlgItemMessage(m_hWnd, IDC_PARAMETER_TYPE, CB_ADDSTRING, 0, (LPARAM)bstrArrayRangeTypes[1]);
  1360. NTDM_CHECK_CB_ERR(lIndex);
  1361. NTDM_CHECK_CB_ERR(SendDlgItemMessage(m_hWnd, IDC_PARAMETER_TYPE, CB_SETITEMDATA, lIndex, (LPARAM)rt_uintrange));
  1362. lIndex = SendDlgItemMessage(m_hWnd, IDC_PARAMETER_TYPE, CB_ADDSTRING, 0, (LPARAM)bstrArrayRangeTypes[2]);
  1363. NTDM_CHECK_CB_ERR(lIndex);
  1364. NTDM_CHECK_CB_ERR(SendDlgItemMessage(m_hWnd, IDC_PARAMETER_TYPE, CB_SETITEMDATA, lIndex, (LPARAM)rt_realrange));
  1365. lIndex = SendDlgItemMessage(m_hWnd, IDC_PARAMETER_TYPE, CB_ADDSTRING, 0, (LPARAM)bstrArrayRangeTypes[3]);
  1366. NTDM_CHECK_CB_ERR(lIndex);
  1367. NTDM_CHECK_CB_ERR(SendDlgItemMessage(m_hWnd, IDC_PARAMETER_TYPE, CB_SETITEMDATA, lIndex, (LPARAM)rt_sintset));
  1368. lIndex = SendDlgItemMessage(m_hWnd, IDC_PARAMETER_TYPE, CB_ADDSTRING, 0, (LPARAM)bstrArrayRangeTypes[4]);
  1369. NTDM_CHECK_CB_ERR(lIndex);
  1370. NTDM_CHECK_CB_ERR(SendDlgItemMessage(m_hWnd, IDC_PARAMETER_TYPE, CB_SETITEMDATA, lIndex, (LPARAM)rt_uintset));
  1371. lIndex = SendDlgItemMessage(m_hWnd, IDC_PARAMETER_TYPE, CB_ADDSTRING, 0, (LPARAM)bstrArrayRangeTypes[5]);
  1372. NTDM_CHECK_CB_ERR(lIndex);
  1373. NTDM_CHECK_CB_ERR(SendDlgItemMessage(m_hWnd, IDC_PARAMETER_TYPE, CB_SETITEMDATA, lIndex, (LPARAM)rt_stringset));
  1374. NTDM_ERR_MSG_IF_FAIL(m_pIWbemClassObject->Get(_T("__CLASS"), 0, &vValue, &cimType, NULL));
  1375. if(_tcscmp(_T("MSFT_SintRangeParam"), vValue.bstrVal) == 0)
  1376. {
  1377. SendDlgItemMessage(m_hWnd, IDC_PARAMETER_TYPE, CB_SETCURSEL, 0, 0);
  1378. GetSintRangeValues();
  1379. }
  1380. else if(_tcscmp(_T("MSFT_UintRangeParam"), vValue.bstrVal) == 0)
  1381. {
  1382. SendDlgItemMessage(m_hWnd, IDC_PARAMETER_TYPE, CB_SETCURSEL, 1, 0);
  1383. GetUintRangeValues();
  1384. }
  1385. else if(_tcscmp(_T("MSFT_RealRangeParam"), vValue.bstrVal) == 0)
  1386. {
  1387. SendDlgItemMessage(m_hWnd, IDC_PARAMETER_TYPE, CB_SETCURSEL, 2, 0);
  1388. GetRealRangeValues();
  1389. }
  1390. else if(_tcscmp(_T("MSFT_SintSetParam"), vValue.bstrVal) == 0)
  1391. {
  1392. SendDlgItemMessage(m_hWnd, IDC_PARAMETER_TYPE, CB_SETCURSEL, 3, 0);
  1393. GetSintSetValues();
  1394. }
  1395. else if(_tcscmp(_T("MSFT_UintSetParam"), vValue.bstrVal) == 0)
  1396. {
  1397. SendDlgItemMessage(m_hWnd, IDC_PARAMETER_TYPE, CB_SETCURSEL, 4, 0);
  1398. GetUintSetValues();
  1399. }
  1400. else
  1401. {
  1402. SendDlgItemMessage(m_hWnd, IDC_PARAMETER_TYPE, CB_SETCURSEL, 5, 0);
  1403. GetStringSetValues();
  1404. }
  1405. ShowControls();
  1406. NTDM_ERR_IF_FAIL(PopulateItems());
  1407. NTDM_END_METHOD()
  1408. // cleanup
  1409. return hr;
  1410. }
  1411. //---------------------------------------------------------------------------
  1412. STDMETHODIMP CEditRangeParameterPropertyDlg::ClearItems()
  1413. {
  1414. HRESULT hr;
  1415. NTDM_BEGIN_METHOD()
  1416. ListView_DeleteAllItems(m_hwndListView);
  1417. NTDM_END_METHOD()
  1418. // cleanup
  1419. return hr;
  1420. }
  1421. //---------------------------------------------------------------------------
  1422. STDMETHODIMP CEditRangeParameterPropertyDlg::PopulateItems()
  1423. {
  1424. HRESULT hr;
  1425. NTDM_BEGIN_METHOD()
  1426. NTDM_ERR_IF_FAIL(ClearItems());
  1427. NTDM_END_METHOD()
  1428. // cleanup
  1429. return hr;
  1430. }
  1431. //---------------------------------------------------------------------------
  1432. STDMETHODIMP CEditRangeParameterPropertyDlg::AddItemToList(IWbemClassObject * pIWbemClassObject, long lIndex)
  1433. {
  1434. HRESULT hr;
  1435. CComVariant vValue;
  1436. CIMTYPE cimType;
  1437. LVITEM lvItem;
  1438. NTDM_BEGIN_METHOD()
  1439. NTDM_ERR_MSG_IF_FAIL(pIWbemClassObject->Get(_T("PropertyName"), 0, &vValue, &cimType, NULL));
  1440. lvItem.iItem = lIndex;
  1441. lvItem.mask = LVIF_TEXT|LVIF_PARAM;
  1442. lvItem.iSubItem = 0;
  1443. lvItem.pszText = vValue.bstrVal;
  1444. lvItem.lParam = (LPARAM)pIWbemClassObject;
  1445. lvItem.iItem = ListView_InsertItem(m_hwndListView, &lvItem);
  1446. NTDM_ERR_IF_MINUSONE(lvItem.iItem);
  1447. pIWbemClassObject->AddRef();
  1448. NTDM_END_METHOD()
  1449. // cleanup
  1450. return hr;
  1451. }
  1452. //---------------------------------------------------------------------------
  1453. STDMETHODIMP CEditRangeParameterPropertyDlg::DestroyDialog()
  1454. {
  1455. HRESULT hr;
  1456. NTDM_BEGIN_METHOD()
  1457. NTDM_ERR_IF_FAIL(ClearItems());
  1458. NTDM_END_METHOD()
  1459. // cleanup
  1460. return hr;
  1461. }
  1462. //---------------------------------------------------------------------------
  1463. STDMETHODIMP CEditRangeParameterPropertyDlg::OnEdit()
  1464. {
  1465. HRESULT hr;
  1466. long lSelectionMark;
  1467. NTDM_BEGIN_METHOD()
  1468. lSelectionMark = ListView_GetSelectionMark(m_hwndListView);
  1469. if(-1 == lSelectionMark)
  1470. {
  1471. CNTDMUtils::DisplayMessage(m_hWnd, IDS_ERR_NO_RANGE_SELECTED);
  1472. goto error;
  1473. }
  1474. else
  1475. {
  1476. }
  1477. NTDM_END_METHOD()
  1478. // cleanup
  1479. return hr;
  1480. }
  1481. //---------------------------------------------------------------------------
  1482. STDMETHODIMP CEditRangeParameterPropertyDlg::OnAdd()
  1483. {
  1484. HRESULT hr;
  1485. NTDM_BEGIN_METHOD()
  1486. NTDM_END_METHOD()
  1487. // cleanup
  1488. return hr;
  1489. }
  1490. //---------------------------------------------------------------------------
  1491. STDMETHODIMP CEditRangeParameterPropertyDlg::OnDelete()
  1492. {
  1493. HRESULT hr;
  1494. long lSelectionMark;
  1495. NTDM_BEGIN_METHOD()
  1496. lSelectionMark = ListView_GetSelectionMark(m_hwndListView);
  1497. ListView_DeleteItem(m_hwndListView, lSelectionMark);
  1498. NTDM_END_METHOD()
  1499. // cleanup
  1500. return hr;
  1501. }
  1502. //---------------------------------------------------------------------------
  1503. STDMETHODIMP CEditRangeParameterPropertyDlg::OnOK()
  1504. {
  1505. HRESULT hr;
  1506. CComVariant vValue;
  1507. CIMTYPE cimType;
  1508. CComBSTR bstrTemp;
  1509. long lIndex;
  1510. long lValue;
  1511. CComPtr<IWbemClassObject>pIWbemClassObject;
  1512. NTDM_BEGIN_METHOD()
  1513. // TODO: check values to make sure all are valid
  1514. // delete the old instance : no need to do this just replace the element in the array
  1515. //NTDM_ERR_MSG_IF_FAIL(m_pIWbemClassObject->Get(_T("__PATH"), 0, &vValue, &cimType, NULL));
  1516. //NTDM_ERR_MSG_IF_FAIL(m_pIWbemServices->DeleteInstance(V_BSTR(&vValue), 0, NULL, NULL));
  1517. m_pIWbemClassObject = NULL;
  1518. // create a new instance of the range parameter based on the Range Type combo box selection
  1519. lIndex = SendDlgItemMessage(m_hWnd, IDC_PARAMETER_TYPE, CB_GETCURSEL, 0, 0);
  1520. NTDM_CHECK_CB_ERR(lIndex);
  1521. lValue = SendDlgItemMessage(m_hWnd, IDC_PARAMETER_TYPE, CB_GETITEMDATA, lIndex, 0);
  1522. if(lValue == rt_sintrange)
  1523. {
  1524. bstrTemp = _T("MSFT_SintRangeParam");
  1525. }
  1526. else if(lValue == rt_uintrange)
  1527. {
  1528. bstrTemp = _T("MSFT_UintRangeParam");
  1529. }
  1530. else if(lValue == rt_realrange)
  1531. {
  1532. bstrTemp = _T("MSFT_RealRangeParam");
  1533. }
  1534. else if(lValue == rt_sintset)
  1535. {
  1536. bstrTemp = _T("MSFT_SintSetParam");
  1537. }
  1538. else if(lValue == rt_uintset)
  1539. {
  1540. bstrTemp = _T("MSFT_UintSetParam");
  1541. }
  1542. else if(lValue == rt_stringset)
  1543. {
  1544. bstrTemp = _T("MSFT_StringSetParam");
  1545. }
  1546. NTDM_ERR_MSG_IF_FAIL(m_pIWbemServices->GetObject(bstrTemp, 0, NULL, &pIWbemClassObject, NULL));
  1547. NTDM_ERR_MSG_IF_FAIL(pIWbemClassObject->SpawnInstance(0, &m_pIWbemClassObject));
  1548. NTDM_ERR_IF_FAIL(SetRangeParamValues());
  1549. if(lValue == rt_sintrange)
  1550. {
  1551. SetSintRangeValues();
  1552. }
  1553. else if(lValue == rt_uintrange)
  1554. {
  1555. SetUintRangeValues();
  1556. }
  1557. else if(lValue == rt_realrange)
  1558. {
  1559. SetRealRangeValues();
  1560. }
  1561. else if(lValue == rt_sintset)
  1562. {
  1563. SetSintSetValues();
  1564. }
  1565. else if(lValue == rt_uintset)
  1566. {
  1567. SetSintSetValues();
  1568. }
  1569. else if(lValue == rt_stringset)
  1570. {
  1571. SetStringSetValues();
  1572. }
  1573. m_vValue.Clear();
  1574. V_VT(&m_vValue) = VT_UNKNOWN;
  1575. NTDM_ERR_IF_FAIL(m_pIWbemClassObject->QueryInterface(IID_IUnknown, (void **)&V_UNKNOWN(&m_vValue)));
  1576. NTDM_END_METHOD()
  1577. // cleanup
  1578. if(SUCCEEDED(hr))
  1579. {
  1580. EndDialog(m_hWnd, IDOK);
  1581. }
  1582. return hr;
  1583. }
  1584. //---------------------------------------------------------------------------
  1585. STDMETHODIMP CEditRangeParameterPropertyDlg::ShowControls()
  1586. {
  1587. HRESULT hr;
  1588. bool bShowMinMax;
  1589. long lIndex;
  1590. long lVal;
  1591. lIndex = SendDlgItemMessage(m_hWnd, IDC_PARAMETER_TYPE, CB_GETCURSEL, 0, 0);
  1592. NTDM_CHECK_CB_ERR(lIndex);
  1593. lVal = SendDlgItemMessage(m_hWnd, IDC_PARAMETER_TYPE, CB_GETITEMDATA, lIndex, 0);
  1594. if(lVal == rt_sintrange || lVal == rt_uintrange || lVal == rt_realrange)
  1595. bShowMinMax = true;
  1596. else
  1597. bShowMinMax = false;
  1598. NTDM_BEGIN_METHOD()
  1599. CNTDMUtils::DisplayDlgItem(m_hWnd, IDC_DEFAULT_RANGE_TEXT, bShowMinMax);
  1600. CNTDMUtils::DisplayDlgItem(m_hWnd, IDC_DEFAULT_RANGE_VALUE, bShowMinMax);
  1601. CNTDMUtils::DisplayDlgItem(m_hWnd, IDC_MIN_RANGE_TEXT, bShowMinMax);
  1602. CNTDMUtils::DisplayDlgItem(m_hWnd, IDC_MIN_RANGE_VALUE, bShowMinMax);
  1603. CNTDMUtils::DisplayDlgItem(m_hWnd, IDC_MAX_RANGE_TEXT, bShowMinMax);
  1604. CNTDMUtils::DisplayDlgItem(m_hWnd, IDC_MAX_RANGE_VALUE, bShowMinMax);
  1605. CNTDMUtils::DisplayDlgItem(m_hWnd, IDC_DEFAULT_SET_TEXT, !bShowMinMax);
  1606. CNTDMUtils::DisplayDlgItem(m_hWnd, IDC_DEFAULT_SET_VALUE, !bShowMinMax);
  1607. CNTDMUtils::DisplayDlgItem(m_hWnd, IDC_VALUES_SET_TEXT, !bShowMinMax);
  1608. CNTDMUtils::DisplayDlgItem(m_hWnd, IDC_VALUES_SET_LIST, !bShowMinMax);
  1609. CNTDMUtils::DisplayDlgItem(m_hWnd, IDC_ADD, !bShowMinMax);
  1610. CNTDMUtils::DisplayDlgItem(m_hWnd, IDC_EDIT, !bShowMinMax);
  1611. CNTDMUtils::DisplayDlgItem(m_hWnd, IDC_DELETE, !bShowMinMax);
  1612. NTDM_END_METHOD()
  1613. return hr;
  1614. }
  1615. //---------------------------------------------------------------------------
  1616. STDMETHODIMP CEditRangeParameterPropertyDlg::GetSintRangeValues()
  1617. {
  1618. HRESULT hr;
  1619. CComVariant vValue;
  1620. CIMTYPE cimType;
  1621. NTDM_BEGIN_METHOD()
  1622. NTDM_ERR_MSG_IF_FAIL(m_pIWbemClassObject->Get(_T("Default"), 0, &vValue, &cimType, NULL));
  1623. SetDlgItemInt(m_hWnd, IDC_DEFAULT_RANGE_VALUE, vValue.intVal, FALSE);
  1624. NTDM_ERR_MSG_IF_FAIL(m_pIWbemClassObject->Get(_T("Min"), 0, &vValue, &cimType, NULL));
  1625. SetDlgItemInt(m_hWnd, IDC_MIN_RANGE_VALUE, vValue.intVal, FALSE);
  1626. NTDM_ERR_MSG_IF_FAIL(m_pIWbemClassObject->Get(_T("Max"), 0, &vValue, &cimType, NULL));
  1627. SetDlgItemInt(m_hWnd, IDC_MAX_RANGE_VALUE, vValue.intVal, FALSE);
  1628. NTDM_END_METHOD()
  1629. return hr;
  1630. }
  1631. //---------------------------------------------------------------------------
  1632. STDMETHODIMP CEditRangeParameterPropertyDlg::SetSintRangeValues()
  1633. {
  1634. HRESULT hr;
  1635. CComVariant vValue;
  1636. CIMTYPE cimType;
  1637. long lValue;
  1638. BOOL bTranslated;
  1639. NTDM_BEGIN_METHOD()
  1640. cimType = CIM_SINT32;
  1641. V_VT(&vValue) = VT_I4;
  1642. lValue = GetDlgItemInt(m_hWnd, IDC_DEFAULT_RANGE_VALUE, &bTranslated, FALSE);
  1643. NTDM_ERR_GETLASTERROR_IF_FALSE(bTranslated);
  1644. vValue.intVal = lValue;
  1645. NTDM_ERR_MSG_IF_FAIL(m_pIWbemClassObject->Put(_T("Default"), 0, &vValue, cimType));
  1646. lValue = GetDlgItemInt(m_hWnd, IDC_MIN_RANGE_VALUE, &bTranslated, FALSE);
  1647. NTDM_ERR_GETLASTERROR_IF_FALSE(bTranslated);
  1648. vValue.intVal = lValue;
  1649. NTDM_ERR_MSG_IF_FAIL(m_pIWbemClassObject->Put(_T("Min"), 0, &vValue, cimType));
  1650. lValue = GetDlgItemInt(m_hWnd, IDC_MAX_RANGE_VALUE, &bTranslated, FALSE);
  1651. NTDM_ERR_GETLASTERROR_IF_FALSE(bTranslated);
  1652. vValue.intVal = lValue;
  1653. NTDM_ERR_MSG_IF_FAIL(m_pIWbemClassObject->Put(_T("Max"), 0, &vValue, cimType));
  1654. NTDM_END_METHOD()
  1655. return hr;
  1656. }
  1657. //---------------------------------------------------------------------------
  1658. STDMETHODIMP CEditRangeParameterPropertyDlg::GetUintRangeValues()
  1659. {
  1660. HRESULT hr;
  1661. CComVariant vValue;
  1662. CIMTYPE cimType;
  1663. NTDM_BEGIN_METHOD()
  1664. NTDM_ERR_MSG_IF_FAIL(m_pIWbemClassObject->Get(_T("Default"), 0, &vValue, &cimType, NULL));
  1665. SetDlgItemInt(m_hWnd, IDC_DEFAULT_RANGE_VALUE, vValue.uiVal, FALSE);
  1666. NTDM_ERR_MSG_IF_FAIL(m_pIWbemClassObject->Get(_T("Min"), 0, &vValue, &cimType, NULL));
  1667. SetDlgItemInt(m_hWnd, IDC_MIN_RANGE_VALUE, vValue.uiVal, FALSE);
  1668. NTDM_ERR_MSG_IF_FAIL(m_pIWbemClassObject->Get(_T("Max"), 0, &vValue, &cimType, NULL));
  1669. SetDlgItemInt(m_hWnd, IDC_MAX_RANGE_VALUE, vValue.uiVal, FALSE);
  1670. NTDM_END_METHOD()
  1671. return hr;
  1672. }
  1673. //---------------------------------------------------------------------------
  1674. STDMETHODIMP CEditRangeParameterPropertyDlg::SetUintRangeValues()
  1675. {
  1676. HRESULT hr;
  1677. CComVariant vValue;
  1678. CIMTYPE cimType;
  1679. long lValue;
  1680. BOOL bTranslated;
  1681. NTDM_BEGIN_METHOD()
  1682. cimType = CIM_UINT32;
  1683. lValue = GetDlgItemInt(m_hWnd, IDC_DEFAULT_RANGE_VALUE, &bTranslated, FALSE);
  1684. NTDM_ERR_GETLASTERROR_IF_FALSE(bTranslated);
  1685. vValue.uiVal = lValue;
  1686. NTDM_ERR_MSG_IF_FAIL(m_pIWbemClassObject->Put(_T("Default"), 0, &vValue, cimType));
  1687. lValue = GetDlgItemInt(m_hWnd, IDC_MIN_RANGE_VALUE, &bTranslated, FALSE);
  1688. NTDM_ERR_GETLASTERROR_IF_FALSE(bTranslated);
  1689. vValue.uiVal = lValue;
  1690. NTDM_ERR_MSG_IF_FAIL(m_pIWbemClassObject->Put(_T("Min"), 0, &vValue, cimType));
  1691. lValue = GetDlgItemInt(m_hWnd, IDC_MAX_RANGE_VALUE, &bTranslated, FALSE);
  1692. NTDM_ERR_GETLASTERROR_IF_FALSE(bTranslated);
  1693. vValue.uiVal = lValue;
  1694. NTDM_ERR_MSG_IF_FAIL(m_pIWbemClassObject->Put(_T("Max"), 0, &vValue, cimType));
  1695. NTDM_END_METHOD()
  1696. return hr;
  1697. }
  1698. //---------------------------------------------------------------------------
  1699. STDMETHODIMP CEditRangeParameterPropertyDlg::GetRealRangeValues()
  1700. {
  1701. HRESULT hr;
  1702. NTDM_BEGIN_METHOD()
  1703. NTDM_END_METHOD()
  1704. return hr;
  1705. }
  1706. //---------------------------------------------------------------------------
  1707. STDMETHODIMP CEditRangeParameterPropertyDlg::SetRealRangeValues()
  1708. {
  1709. HRESULT hr;
  1710. NTDM_BEGIN_METHOD()
  1711. NTDM_END_METHOD()
  1712. return hr;
  1713. }
  1714. //---------------------------------------------------------------------------
  1715. STDMETHODIMP CEditRangeParameterPropertyDlg::GetSintSetValues()
  1716. {
  1717. HRESULT hr;
  1718. NTDM_BEGIN_METHOD()
  1719. NTDM_END_METHOD()
  1720. return hr;
  1721. }
  1722. //---------------------------------------------------------------------------
  1723. STDMETHODIMP CEditRangeParameterPropertyDlg::SetSintSetValues()
  1724. {
  1725. HRESULT hr;
  1726. NTDM_BEGIN_METHOD()
  1727. NTDM_END_METHOD()
  1728. return hr;
  1729. }
  1730. //---------------------------------------------------------------------------
  1731. STDMETHODIMP CEditRangeParameterPropertyDlg::GetUintSetValues()
  1732. {
  1733. HRESULT hr;
  1734. NTDM_BEGIN_METHOD()
  1735. NTDM_END_METHOD()
  1736. return hr;
  1737. }
  1738. //---------------------------------------------------------------------------
  1739. STDMETHODIMP CEditRangeParameterPropertyDlg::SetUintSetValues()
  1740. {
  1741. HRESULT hr;
  1742. NTDM_BEGIN_METHOD()
  1743. NTDM_END_METHOD()
  1744. return hr;
  1745. }
  1746. //---------------------------------------------------------------------------
  1747. STDMETHODIMP CEditRangeParameterPropertyDlg::GetStringSetValues()
  1748. {
  1749. HRESULT hr;
  1750. NTDM_BEGIN_METHOD()
  1751. NTDM_END_METHOD()
  1752. return hr;
  1753. }
  1754. //---------------------------------------------------------------------------
  1755. STDMETHODIMP CEditRangeParameterPropertyDlg::SetStringSetValues()
  1756. {
  1757. HRESULT hr;
  1758. NTDM_BEGIN_METHOD()
  1759. NTDM_END_METHOD()
  1760. return hr;
  1761. }
  1762. //---------------------------------------------------------------------------
  1763. STDMETHODIMP CEditRangeParameterPropertyDlg::SetRangeParamValues()
  1764. {
  1765. HRESULT hr;
  1766. CComVariant vValue;
  1767. CIMTYPE cimType;
  1768. long lValue;
  1769. BOOL bTranslated;
  1770. NTDM_BEGIN_METHOD()
  1771. NTDM_ERR_IF_FAIL(CNTDMUtils::SetStringProperty(m_pIWbemClassObject, _T("PropertyName"), m_hWnd, IDC_PROPERTY_NAME));
  1772. NTDM_ERR_IF_FAIL(CNTDMUtils::SetStringProperty(m_pIWbemClassObject, _T("TargetClass"), m_hWnd, IDC_TARGET_CLASS));
  1773. cimType = CIM_UINT8;
  1774. lValue = GetDlgItemInt(m_hWnd, IDC_TARGET_TYPE, &bTranslated, FALSE);
  1775. NTDM_ERR_GETLASTERROR_IF_FALSE(bTranslated);
  1776. V_VT(&vValue) = VT_UI1;
  1777. V_UI1(&vValue) = lValue;
  1778. NTDM_ERR_MSG_IF_FAIL(m_pIWbemClassObject->Put(_T("TargetType"), 0, &vValue, cimType));
  1779. NTDM_END_METHOD()
  1780. return hr;
  1781. }