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.

242 lines
5.0 KiB

  1. //-------------------------------------------------------------------------
  2. // File: ColumnMgrDlg.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 "ColumnMgrDlg.h"
  15. CColumnManagerDlg * g_pColumnManagerDlg = NULL;
  16. //-------------------------------------------------------------------------
  17. INT_PTR CALLBACK ColumnManagerDlgProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)
  18. {
  19. if(g_pColumnManagerDlg)
  20. {
  21. return g_pColumnManagerDlg->ColumnManagerDlgProc(hDlg, iMessage, wParam, lParam);
  22. }
  23. return FALSE;
  24. }
  25. //-------------------------------------------------------------------------
  26. CColumnManagerDlg::CColumnManagerDlg(CSimpleArray<CColumnItem*> *pArrayColumns)
  27. {
  28. m_hWnd = NULL;
  29. m_hwndListView = NULL;
  30. m_pArrayColumns = pArrayColumns;
  31. }
  32. //-------------------------------------------------------------------------
  33. CColumnManagerDlg::~CColumnManagerDlg()
  34. {
  35. }
  36. //-------------------------------------------------------------------------
  37. INT_PTR CALLBACK CColumnManagerDlg::ColumnManagerDlgProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)
  38. {
  39. LPPSHNOTIFY lppsn = NULL;
  40. switch(iMessage)
  41. {
  42. case WM_INITDIALOG:
  43. {
  44. m_hWnd = hDlg;
  45. InitializeDialog();
  46. PopulateColumnsList();
  47. break;
  48. }
  49. case WM_DESTROY:
  50. {
  51. //DestroyDialog();
  52. break;
  53. }
  54. case WM_COMMAND:
  55. {
  56. switch(LOWORD(wParam))
  57. {
  58. case IDCANCEL:
  59. EndDialog(m_hWnd, IDCANCEL);
  60. return TRUE;
  61. case IDOK:
  62. OnOK();
  63. return TRUE;
  64. break;
  65. }
  66. break;
  67. }
  68. default:
  69. break;
  70. }
  71. return FALSE;
  72. }
  73. //---------------------------------------------------------------------------
  74. STDMETHODIMP CColumnManagerDlg::InitializeDialog()
  75. {
  76. HRESULT hr;
  77. LVCOLUMN lvColumn;
  78. NTDM_BEGIN_METHOD()
  79. //Initialize the ListView Control
  80. m_hwndListView = GetDlgItem(m_hWnd, IDC_COLUMNS_LIST);
  81. NTDM_ERR_IF_NULL(m_hwndListView);
  82. ListView_SetExtendedListViewStyle(m_hwndListView, LVS_EX_FULLROWSELECT|LVS_EX_CHECKBOXES);
  83. lvColumn.mask = LVCF_FMT;
  84. lvColumn.fmt = LVCFMT_LEFT;
  85. NTDM_ERR_IF_MINUSONE(ListView_InsertColumn(m_hwndListView, 0, &lvColumn));
  86. NTDM_ERR_IF_FALSE(ListView_SetColumnWidth(m_hwndListView, 0, LVSCW_AUTOSIZE_USEHEADER));
  87. NTDM_END_METHOD()
  88. // cleanup
  89. return hr;
  90. }
  91. //---------------------------------------------------------------------------
  92. STDMETHODIMP CColumnManagerDlg::PopulateColumnsList()
  93. {
  94. HRESULT hr;
  95. long i;
  96. NTDM_BEGIN_METHOD()
  97. for(i=0; i<m_pArrayColumns->GetSize(); i++)
  98. {
  99. AddColumnItemToList((*m_pArrayColumns)[i]);
  100. }
  101. NTDM_END_METHOD()
  102. // cleanup
  103. return hr;
  104. }
  105. //---------------------------------------------------------------------------
  106. STDMETHODIMP CColumnManagerDlg::AddColumnItemToList(CColumnItem* pszItem)
  107. {
  108. HRESULT hr;
  109. LVITEM lvItem;
  110. long lIndex = 10000;
  111. static TCHAR test[20] = _T("cool");
  112. NTDM_BEGIN_METHOD()
  113. lvItem.mask = LVIF_TEXT|LVIF_PARAM;
  114. lvItem.iItem = lIndex;
  115. lvItem.iSubItem = 0;
  116. lvItem.pszText = (LPTSTR)pszItem->GetName();
  117. lvItem.lParam = (LPARAM)pszItem;
  118. lIndex = ListView_InsertItem(m_hwndListView, &lvItem);
  119. NTDM_ERR_IF_MINUSONE(lIndex);
  120. ListView_SetCheckState(m_hwndListView, lIndex, pszItem->IsSelected());
  121. NTDM_END_METHOD()
  122. // cleanup
  123. return hr;
  124. }
  125. //---------------------------------------------------------------------------
  126. STDMETHODIMP CColumnManagerDlg::OnOK()
  127. {
  128. HRESULT hr;
  129. LVITEM lvItem;
  130. long lCount;
  131. BOOL bValue;
  132. NTDM_BEGIN_METHOD()
  133. lvItem.mask = LVIF_PARAM;
  134. lvItem.iSubItem = 0;
  135. lCount = ListView_GetItemCount(m_hwndListView);
  136. while(lCount > 0)
  137. {
  138. lCount--;
  139. lvItem.iItem = lCount;
  140. NTDM_ERR_IF_FALSE(ListView_GetItem(m_hwndListView, &lvItem));
  141. bValue = ListView_GetCheckState(m_hwndListView, lCount);
  142. ((CColumnItem *)lvItem.lParam)->SetSelected(bValue);
  143. }
  144. NTDM_END_METHOD()
  145. if SUCCEEDED(hr)
  146. EndDialog(m_hWnd, IDOK);
  147. // cleanup
  148. return hr;
  149. }
  150. //---------------------------------------------------------------------------
  151. // CColumnItem
  152. //---------------------------------------------------------------------------
  153. CColumnItem::CColumnItem(LPCTSTR pcszName, LPCTSTR pcszPropertyName, bool bSelected)
  154. {
  155. m_bstrName = pcszName;
  156. m_bstrPropertyName = pcszPropertyName;
  157. m_bSelected = bSelected;
  158. }
  159. //---------------------------------------------------------------------------
  160. CColumnItem::CColumnItem(const CColumnItem& colItem)
  161. {
  162. m_bstrName = colItem.m_bstrName;
  163. m_bstrPropertyName = colItem.m_bstrPropertyName;
  164. m_bSelected = colItem.m_bSelected;
  165. }
  166. //---------------------------------------------------------------------------
  167. CColumnItem& CColumnItem::operator=(const CColumnItem& colItem)
  168. {
  169. if(this != &colItem)
  170. {
  171. m_bstrName = colItem.m_bstrName;
  172. m_bstrPropertyName = colItem.m_bstrPropertyName;
  173. m_bSelected = colItem.m_bSelected;
  174. }
  175. return *this;
  176. }
  177. //---------------------------------------------------------------------------