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.

334 lines
8.4 KiB

  1. // WmiBrowseDlg.cpp : implementation file
  2. //
  3. // 03/28/00 v-marfin 62468 : Added efficiencies to help queries with thousands of
  4. // records load faster.
  5. // 03/30/00 v-marfin 62469 : If no occurrences, disable the OK button
  6. #include "stdafx.h"
  7. #include "snapin.h"
  8. #include "WmiBrowseDlg.h"
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CWmiBrowseDlg dialog
  16. CWmiBrowseDlg::CWmiBrowseDlg(CWnd* pParent /*=NULL*/)
  17. : CResizeableDialog(CWmiBrowseDlg::IDD, pParent)
  18. {
  19. //{{AFX_DATA_INIT(CWmiBrowseDlg)
  20. m_sTitle = _T("");
  21. //}}AFX_DATA_INIT
  22. }
  23. void CWmiBrowseDlg::DoDataExchange(CDataExchange* pDX)
  24. {
  25. CResizeableDialog::DoDataExchange(pDX);
  26. //{{AFX_DATA_MAP(CWmiBrowseDlg)
  27. DDX_Control(pDX, IDC_LIST_WMI_ITEMS, m_Items);
  28. DDX_Text(pDX, IDC_STATIC_TITLE, m_sTitle);
  29. //}}AFX_DATA_MAP
  30. }
  31. BEGIN_MESSAGE_MAP(CWmiBrowseDlg, CResizeableDialog)
  32. //{{AFX_MSG_MAP(CWmiBrowseDlg)
  33. ON_BN_CLICKED(IDC_BUTTON_HELP, OnButtonHelp)
  34. ON_NOTIFY(NM_DBLCLK, IDC_LIST_WMI_ITEMS, OnDblclkListWmiItems)
  35. //}}AFX_MSG_MAP
  36. END_MESSAGE_MAP()
  37. /////////////////////////////////////////////////////////////////////////////
  38. // CWmiBrowseDlg message handlers
  39. BOOL CWmiBrowseDlg::OnInitDialog()
  40. {
  41. CResizeableDialog::OnInitDialog();
  42. // subclass header control
  43. m_Items.SubclassHeaderCtrl();
  44. // set the extended styles for the list control
  45. m_Items.SetExtendedStyle(LVS_EX_LABELTIP|LVS_EX_FULLROWSELECT|LVS_EX_HEADERDRAGDROP);
  46. // set styles for the header control
  47. CHeaderCtrl* pHdrCtrl = m_Items.GetHeaderCtrl();
  48. DWORD dwStyle = GetWindowLong(pHdrCtrl->GetSafeHwnd(),GWL_STYLE);
  49. dwStyle |= (HDS_DRAGDROP|HDS_BUTTONS);
  50. SetWindowLong(pHdrCtrl->GetSafeHwnd(),GWL_STYLE,dwStyle);
  51. SetControlInfo(IDC_STATIC_TITLE, ANCHOR_LEFT | ANCHOR_TOP | RESIZE_HOR);
  52. SetControlInfo(IDC_LIST_WMI_ITEMS, ANCHOR_LEFT | ANCHOR_TOP | RESIZE_HOR | RESIZE_VER);
  53. SetControlInfo(IDOK, ANCHOR_BOTTOM | ANCHOR_LEFT );
  54. SetControlInfo(IDCANCEL, ANCHOR_BOTTOM | ANCHOR_LEFT );
  55. SetControlInfo(IDC_BUTTON_HELP,ANCHOR_BOTTOM | ANCHOR_LEFT );
  56. SetWindowText(m_sDlgTitle);
  57. return TRUE; // return TRUE unless you set the focus to a control
  58. // EXCEPTION: OCX Property Pages should return FALSE
  59. }
  60. void CWmiBrowseDlg::OnButtonHelp()
  61. {
  62. // TODO: Add your control notification handler code here
  63. }
  64. void CWmiBrowseDlg::OnDblclkListWmiItems(NMHDR* pNMHDR, LRESULT* pResult)
  65. {
  66. OnOK();
  67. *pResult = 0;
  68. }
  69. void CWmiBrowseDlg::OnOK()
  70. {
  71. POSITION pos = m_Items.GetFirstSelectedItemPosition();
  72. if( ! pos )
  73. {
  74. return;
  75. }
  76. int iIndex = m_Items.GetNextSelectedItem(pos);
  77. if( iIndex < 0 )
  78. {
  79. return;
  80. }
  81. m_sSelectedItem = m_Items.GetItemText(iIndex,0);
  82. CResizeableDialog::OnOK();
  83. }
  84. /////////////////////////////////////////////////////////////////////////////
  85. // CWmiNamespaceBrowseDlg dialog
  86. BOOL CWmiNamespaceBrowseDlg::OnInitDialog()
  87. {
  88. CWmiBrowseDlg::OnInitDialog();
  89. CWaitCursor wait;
  90. // add column headers to the list ctrl
  91. CString sColName;
  92. sColName.LoadString(IDS_STRING_NAME);
  93. m_Items.InsertColumn(0,sColName);
  94. m_Items.SetColumnWidth(0,LVSCW_AUTOSIZE);
  95. // insert the root namespace
  96. m_Items.InsertItem(0,_T("ROOT"));
  97. if( m_sTitle.CompareNoCase(_T("ROOT")) == 0 )
  98. {
  99. m_Items.SetItemState(0,LVIS_SELECTED,LVIS_SELECTED);
  100. }
  101. // enumerate all namespaces on the system recursively
  102. EnumerateAllChildNamespaces(_T("ROOT"));
  103. m_sTitle.Format(IDS_STRING_NAMESPACES_ON_SYSTEM,m_ClassObject.GetMachineName());
  104. if( m_Items.GetItemCount() == 0 )
  105. {
  106. m_Items.DeleteColumn(0);
  107. m_Items.InsertColumn(0,_T(""));
  108. CString sNoInstancesFound;
  109. sNoInstancesFound.LoadString(IDS_STRING_NO_ITEMS_FOUND);
  110. m_Items.InsertItem(0,sNoInstancesFound);
  111. m_Items.SetColumnWidth(0,LVSCW_AUTOSIZE);
  112. m_Items.EnableWindow(FALSE);
  113. }
  114. UpdateData(FALSE);
  115. return TRUE;
  116. }
  117. void CWmiNamespaceBrowseDlg::EnumerateAllChildNamespaces(const CString& sNamespace)
  118. {
  119. ULONG ulReturned = 0L;
  120. int i = 0;
  121. CWbemClassObject Namespaces;
  122. Namespaces.Create(m_ClassObject.GetMachineName());
  123. Namespaces.SetNamespace(sNamespace);
  124. CString sTemp = IDS_STRING_MOF_NAMESPACE;
  125. BSTR bsTemp = sTemp.AllocSysString();
  126. if( ! CHECKHRESULT(Namespaces.CreateEnumerator(bsTemp)) )
  127. {
  128. ::SysFreeString(bsTemp);
  129. return;
  130. }
  131. ::SysFreeString(bsTemp);
  132. while( Namespaces.GetNextObject(ulReturned) == S_OK && ulReturned )
  133. {
  134. CString sName;
  135. Namespaces.GetProperty(IDS_STRING_MOF_NAME,sName);
  136. CString sTemp2;
  137. Namespaces.GetProperty(IDS_STRING_MOF_NAMESPACE,sTemp2);
  138. CString sNamespaceFound = sTemp2 + _T("\\") + sName;
  139. int iIndex = m_Items.InsertItem(i++,sNamespaceFound);
  140. if( sNamespaceFound.CompareNoCase(m_sTitle) == 0 )
  141. {
  142. m_Items.SetItemState(iIndex,LVIS_SELECTED,LVIS_SELECTED);
  143. m_Items.EnsureVisible(iIndex,FALSE);
  144. }
  145. EnumerateAllChildNamespaces(sNamespaceFound);
  146. }
  147. m_Items.SetColumnWidth(0,LVSCW_AUTOSIZE);
  148. }
  149. /////////////////////////////////////////////////////////////////////////////
  150. // CWmiClassBrowseDlg dialog
  151. BOOL CWmiClassBrowseDlg::OnInitDialog()
  152. {
  153. CWmiBrowseDlg::OnInitDialog();
  154. CWaitCursor wait;
  155. // add column headers to the list ctrl
  156. CString sColName;
  157. sColName.LoadString(IDS_STRING_NAME);
  158. m_Items.InsertColumn(0,sColName);
  159. m_Items.SetColumnWidth(0,LVSCW_AUTOSIZE);
  160. ULONG ulReturned = 0L;
  161. int i = 0;
  162. while( m_ClassObject.GetNextObject(ulReturned) == S_OK && ulReturned )
  163. {
  164. CString sName;
  165. m_ClassObject.GetProperty(IDS_STRING_MOF_CLASSNAME,sName);
  166. m_Items.InsertItem(i++,sName);
  167. m_Items.SetColumnWidth(0,LVSCW_AUTOSIZE);
  168. }
  169. if( m_Items.GetItemCount() == 0 )
  170. {
  171. m_Items.DeleteColumn(0);
  172. m_Items.InsertColumn(0,_T(""));
  173. CString sNoInstancesFound;
  174. sNoInstancesFound.LoadString(IDS_STRING_NO_ITEMS_FOUND);
  175. m_Items.InsertItem(0,sNoInstancesFound);
  176. m_Items.SetColumnWidth(0,LVSCW_AUTOSIZE);
  177. m_Items.EnableWindow(FALSE);
  178. }
  179. return TRUE;
  180. }
  181. /////////////////////////////////////////////////////////////////////////////
  182. // CWmiInstanceBrowseDlg dialog
  183. BOOL CWmiInstanceBrowseDlg::OnInitDialog()
  184. {
  185. CWmiBrowseDlg::OnInitDialog();
  186. CWaitCursor wait;
  187. // add column headers to the list ctrl
  188. CString sColName;
  189. sColName.LoadString(IDS_STRING_PATH);
  190. m_Items.InsertColumn(0,sColName);
  191. m_Items.SetColumnWidth(0,LVSCW_AUTOSIZE);
  192. sColName.LoadString(IDS_STRING_NAME);
  193. m_Items.InsertColumn(1,sColName);
  194. m_Items.SetColumnWidth(1,LVSCW_AUTOSIZE);
  195. int order[] = { 1,0 };
  196. m_Items.SetColumnOrderArray(2,order);
  197. ULONG ulReturned = 0L;
  198. int i = 0;
  199. bool bNamePropertyExists = true;
  200. // // v-marfin 62468 define CStrings outside of loop for performance purposes
  201. CString sProperty; // v-marfin 62468
  202. CString sNameProperty; // v-marfin 62468
  203. HRESULT hr=0;
  204. int iItemIndex=0;
  205. while( m_ClassObject.GetNextObject(ulReturned) == S_OK && ulReturned )
  206. {
  207. m_ClassObject.GetProperty(IDS_STRING_MOF_RELPATH,sProperty);
  208. iItemIndex = m_Items.InsertItem(i,sProperty);
  209. // v-marfin 62468 : Don't check for this if we know the name doesn't exist.
  210. if (bNamePropertyExists)
  211. {
  212. hr = m_ClassObject.GetProperty(IDS_STRING_MOF_NAME,sNameProperty);
  213. if( !CHECKHRESULT(hr) )
  214. {
  215. bNamePropertyExists = false;
  216. sNameProperty.Empty(); // v-marfin 62468
  217. }
  218. }
  219. m_Items.SetItem(iItemIndex,1,LVIF_TEXT,sNameProperty,-1,-1,-1,0L);
  220. // v-marfin 62468 : m_Items.SetColumnWidth(0,LVSCW_AUTOSIZE);
  221. // v-marfin 62468 : m_Items.SetColumnWidth(1,LVSCW_AUTOSIZE);
  222. i++;
  223. // v-marfin 62468
  224. if (i > 1000)
  225. break;
  226. }
  227. m_Items.SetColumnWidth(0,LVSCW_AUTOSIZE); // v-marfin 62468 :
  228. m_Items.SetColumnWidth(1,LVSCW_AUTOSIZE); // v-marfin 62468
  229. if( ! bNamePropertyExists )
  230. {
  231. m_Items.DeleteColumn(1);
  232. }
  233. int nCount = m_Items.GetItemCount();
  234. if( m_Items.GetItemCount() == 0 )
  235. {
  236. m_Items.DeleteColumn(1);
  237. m_Items.DeleteColumn(0);
  238. m_Items.InsertColumn(0,_T(""));
  239. CString sNoInstancesFound;
  240. sNoInstancesFound.LoadString(IDS_STRING_NO_ITEMS_FOUND);
  241. m_Items.InsertItem(0,sNoInstancesFound);
  242. m_Items.SetColumnWidth(0,LVSCW_AUTOSIZE);
  243. m_Items.EnableWindow(FALSE);
  244. }
  245. else
  246. {
  247. // v-marfin 62469
  248. m_Items.SetItemState(0,LVIS_SELECTED,LVIS_SELECTED);
  249. }
  250. // v-marfin 62469 : If no occurrences, disable the OK button
  251. GetDlgItem(IDOK)->EnableWindow(nCount);
  252. return TRUE;
  253. }