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.

203 lines
4.3 KiB

  1. /*++
  2. Copyright (C) 1997-2001 Microsoft Corporation
  3. Module Name:
  4. Abstract:
  5. History:
  6. --*/
  7. // ExecMethodDlg.cpp : implementation file
  8. //
  9. #include "stdafx.h"
  10. #include "wmitest.h"
  11. #include "WMITestDoc.h"
  12. #include "OpView.h"
  13. #include "OpWrap.h"
  14. #include "ExecMethodDlg.h"
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CExecMethodDlg dialog
  22. CExecMethodDlg::CExecMethodDlg(CWnd* pParent /*=NULL*/)
  23. : CDialog(CExecMethodDlg::IDD, pParent)
  24. {
  25. //{{AFX_DATA_INIT(CExecMethodDlg)
  26. //}}AFX_DATA_INIT
  27. }
  28. void CExecMethodDlg::DoDataExchange(CDataExchange* pDX)
  29. {
  30. CDialog::DoDataExchange(pDX);
  31. //{{AFX_DATA_MAP(CExecMethodDlg)
  32. DDX_Control(pDX, IDC_METHOD, m_ctlMethods);
  33. //}}AFX_DATA_MAP
  34. }
  35. BEGIN_MESSAGE_MAP(CExecMethodDlg, CDialog)
  36. //{{AFX_MSG_MAP(CExecMethodDlg)
  37. ON_BN_CLICKED(IDC_EDIT_INPUT, OnEditInput)
  38. ON_BN_CLICKED(IDC_EDIT_OUT, OnEditOut)
  39. ON_BN_CLICKED(IDC_CLEAR_IN, OnClearIn)
  40. ON_BN_CLICKED(IDOK, OnExecute)
  41. ON_CBN_SELCHANGE(IDC_METHOD, OnSelchangeMethod)
  42. //}}AFX_MSG_MAP
  43. END_MESSAGE_MAP()
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CExecMethodDlg message handlers
  46. void CExecMethodDlg::OnEditInput()
  47. {
  48. CWMITestDoc::EditGenericObject(IDS_EDIT_IN_PARAMS, m_pObjIn);
  49. }
  50. void CExecMethodDlg::OnEditOut()
  51. {
  52. CWMITestDoc::EditGenericObject(IDS_EDIT_OUT_PARAMS, m_pObjOut);
  53. }
  54. void CExecMethodDlg::OnClearIn()
  55. {
  56. //m_pObjIn = NULL;
  57. //UpdateButtons();
  58. OnSelchangeMethod();
  59. }
  60. void CExecMethodDlg::OnExecute()
  61. {
  62. CString strMethod;
  63. int iItem = m_ctlMethods.GetCurSel();
  64. HRESULT hr;
  65. m_ctlMethods.GetLBText(iItem, strMethod);
  66. hr =
  67. g_pOpView->GetDocument()->m_pNamespace->ExecMethod(
  68. _bstr_t(m_strObjPath),
  69. _bstr_t(strMethod),
  70. 0,
  71. NULL,
  72. m_pObjIn,
  73. &m_pObjOut,
  74. NULL);
  75. if (SUCCEEDED(hr))
  76. AfxMessageBox(IDS_EXEC_SUCCEEDED, MB_ICONINFORMATION | MB_OK);
  77. else
  78. CWMITestDoc::DisplayWMIErrorBox(hr);
  79. UpdateButtons();
  80. }
  81. void CExecMethodDlg::OnSelchangeMethod()
  82. {
  83. LoadParams();
  84. m_pObjOut = NULL;
  85. UpdateButtons();
  86. }
  87. void CExecMethodDlg::UpdateButtons()
  88. {
  89. GetDlgItem(IDC_EDIT_INPUT)->EnableWindow(m_pObjIn != NULL);
  90. GetDlgItem(IDC_CLEAR_IN)->EnableWindow(m_pObjIn != NULL);
  91. GetDlgItem(IDC_EDIT_OUT)->EnableWindow(m_pObjOut != NULL);
  92. }
  93. void CExecMethodDlg::LoadParams()
  94. {
  95. CString strMethod;
  96. int iItem = m_ctlMethods.GetCurSel();
  97. HRESULT hr;
  98. // Clear these out.
  99. m_pObjIn = NULL;
  100. m_pObjOut = NULL;
  101. if (iItem != -1)
  102. {
  103. m_ctlMethods.GetLBText(iItem, strMethod);
  104. hr =
  105. m_pClass->GetMethod(
  106. _bstr_t(strMethod),
  107. 0,
  108. &m_pObjIn,
  109. NULL);
  110. if (FAILED(hr))
  111. CWMITestDoc::DisplayWMIErrorBox(hr);
  112. }
  113. UpdateButtons();
  114. }
  115. BOOL CExecMethodDlg::OnInitDialog()
  116. {
  117. CDialog::OnInitDialog();
  118. CString strClass = m_pInfo->GetStringPropValue(L"__CLASS");
  119. HRESULT hr;
  120. // Setup the controls.
  121. m_strObjPath = m_pInfo->GetObjText();
  122. SetDlgItemText(IDC_NAME, m_strObjPath);
  123. // Setup the combo box.
  124. CPropInfoArray *pProps = m_pInfo->GetProps();
  125. POSITION pos = pProps->m_listMethods.GetHeadPosition();
  126. while (pos)
  127. {
  128. CMethodInfo &info = pProps->m_listMethods.GetNext(pos);
  129. m_ctlMethods.AddString(info.m_strName);
  130. }
  131. if (m_ctlMethods.SelectString(-1, m_strDefaultMethod) == -1)
  132. m_ctlMethods.SetCurSel(0);
  133. // Get the class definition.
  134. hr =
  135. g_pOpView->GetDocument()->m_pNamespace->GetObject(
  136. _bstr_t(strClass),
  137. WBEM_FLAG_RETURN_WBEM_COMPLETE,
  138. NULL,
  139. &m_pClass,
  140. NULL);
  141. if (SUCCEEDED(hr))
  142. {
  143. // Fake a selchange.
  144. OnSelchangeMethod();
  145. }
  146. else
  147. {
  148. CWMITestDoc::DisplayWMIErrorBox(hr);
  149. GetDlgItem(IDC_METHOD)->EnableWindow(FALSE);
  150. GetDlgItem(IDOK)->EnableWindow(FALSE);
  151. UpdateButtons();
  152. }
  153. return TRUE; // return TRUE unless you set the focus to a control
  154. // EXCEPTION: OCX Property Pages should return FALSE
  155. }