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.

309 lines
8.6 KiB

  1. // ActionCmdLinePage.cpp : implementation file
  2. //
  3. // 03/05/00 v-marfin bug 59643 : Make this the default starting page.
  4. // 03/28/00 v-marfin 61030 Change Browse for file dialog to fix default extension
  5. #include "stdafx.h"
  6. #include "snapin.h"
  7. #include "ActionCmdLinePage.h"
  8. #include "Action.h"
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CActionCmdLinePage property page
  16. IMPLEMENT_DYNCREATE(CActionCmdLinePage, CHMPropertyPage)
  17. CActionCmdLinePage::CActionCmdLinePage() : CHMPropertyPage(CActionCmdLinePage::IDD)
  18. {
  19. //{{AFX_DATA_INIT(CActionCmdLinePage)
  20. m_sCommandLine = _T("");
  21. m_sFileName = _T("");
  22. m_iTimeout = 0;
  23. m_sWorkingDirectory = _T("");
  24. m_bWindowed = FALSE;
  25. //}}AFX_DATA_INIT
  26. m_sHelpTopic = _T("HMon21.chm::/dcommact.htm");
  27. }
  28. CActionCmdLinePage::~CActionCmdLinePage()
  29. {
  30. }
  31. void CActionCmdLinePage::DoDataExchange(CDataExchange* pDX)
  32. {
  33. CHMPropertyPage::DoDataExchange(pDX);
  34. //{{AFX_DATA_MAP(CActionCmdLinePage)
  35. DDX_Control(pDX, IDC_EDIT_COMMAND_LINE, m_CmdLineWnd);
  36. DDX_Control(pDX, IDC_COMBO_TIMEOUT_UNITS, m_TimeoutUnits);
  37. DDX_Text(pDX, IDC_EDIT_COMMAND_LINE, m_sCommandLine);
  38. DDV_MaxChars(pDX, m_sCommandLine, 1024);
  39. DDX_Text(pDX, IDC_EDIT_FILE_NAME, m_sFileName);
  40. DDV_MaxChars(pDX, m_sFileName, 1024);
  41. DDX_Text(pDX, IDC_EDIT_PROCESS_TIMEOUT, m_iTimeout);
  42. DDX_Text(pDX, IDC_EDIT_WORKING_DIR, m_sWorkingDirectory);
  43. DDX_Check(pDX, IDC_CHECK_WINDOWED, m_bWindowed);
  44. //}}AFX_DATA_MAP
  45. }
  46. BEGIN_MESSAGE_MAP(CActionCmdLinePage, CHMPropertyPage)
  47. //{{AFX_MSG_MAP(CActionCmdLinePage)
  48. ON_WM_DESTROY()
  49. ON_BN_CLICKED(IDC_BUTTON_ADVANCED, OnButtonAdvanced)
  50. ON_BN_CLICKED(IDC_BUTTON_BROWSE_DIRECTORY, OnButtonBrowseDirectory)
  51. ON_BN_CLICKED(IDC_BUTTON_BROWSE_FILE, OnButtonBrowseFile)
  52. ON_EN_CHANGE(IDC_EDIT_COMMAND_LINE, OnChangeEditCommandLine)
  53. ON_EN_CHANGE(IDC_EDIT_FILE_NAME, OnChangeEditFileName)
  54. ON_EN_CHANGE(IDC_EDIT_PROCESS_TIMEOUT, OnChangeEditProcessTimeout)
  55. ON_EN_CHANGE(IDC_EDIT_WORKING_DIR, OnChangeEditWorkingDir)
  56. ON_CBN_SELENDOK(IDC_COMBO_TIMEOUT_UNITS, OnSelendokComboTimeoutUnits)
  57. ON_BN_CLICKED(IDC_BUTTON_INSERTION, OnButtonInsertion)
  58. //}}AFX_MSG_MAP
  59. END_MESSAGE_MAP()
  60. /////////////////////////////////////////////////////////////////////////////
  61. // CActionCmdLinePage message handlers
  62. BOOL CActionCmdLinePage::OnInitDialog()
  63. {
  64. // v-marfin : bug 59643 : This will be the default starting page for the property
  65. // sheet so call CnxPropertyPageCreate() to unmarshal the
  66. // connection for this thread. This function must be called
  67. // by the first page of the property sheet. It used to
  68. // be called by the "General" page and its call still remains
  69. // there as well in case the general page is loaded by a
  70. // different code path that does not also load this page.
  71. // The CnxPropertyPageCreate function has been safeguarded
  72. // to simply return if the required call has already been made.
  73. // CnxPropertyPageDestory() must be called from this page's
  74. // OnDestroy function.
  75. // unmarshal connmgr
  76. CnxPropertyPageCreate();
  77. CHMPropertyPage::OnInitDialog();
  78. if( ! m_InsertionMenu.Create(&m_CmdLineWnd,GetObjectPtr(),false) )
  79. {
  80. GetDlgItem(IDC_BUTTON_INSERTION)->EnableWindow(FALSE);
  81. }
  82. CWbemClassObject* pConsumerObject = ((CAction*)GetObjectPtr())->GetConsumerClassObject();
  83. if( pConsumerObject )
  84. {
  85. pConsumerObject->GetProperty(_T("CommandLineTemplate"),m_sCommandLine);
  86. pConsumerObject->GetProperty(_T("ExecutablePath"),m_sFileName);
  87. if( ! m_sFileName.CompareNoCase(_T("NOOP")) )
  88. {
  89. m_sFileName.Empty();
  90. }
  91. pConsumerObject->GetProperty(_T("KillTimeout"),m_iTimeout);
  92. m_TimeoutUnits.SetCurSel(0);
  93. pConsumerObject->GetProperty(_T("WorkingDirectory"),m_sWorkingDirectory);
  94. int iShowWindow = SW_SHOW;
  95. pConsumerObject->GetProperty(_T("ShowWindowCommand"),iShowWindow);
  96. m_bWindowed = iShowWindow == 1;
  97. delete pConsumerObject;
  98. }
  99. SendDlgItemMessage(IDC_SPIN2,UDM_SETRANGE32,0,99999);
  100. UpdateData(FALSE);
  101. return TRUE; // return TRUE unless you set the focus to a control
  102. // EXCEPTION: OCX Property Pages should return FALSE
  103. }
  104. BOOL CActionCmdLinePage::OnApply()
  105. {
  106. if( ! CHMPropertyPage::OnApply() )
  107. {
  108. return FALSE;
  109. }
  110. UpdateData();
  111. int iOldTimeout = m_iTimeout;
  112. switch( m_TimeoutUnits.GetCurSel() )
  113. {
  114. case 1: // minutes
  115. {
  116. m_iTimeout *= 60;
  117. }
  118. break;
  119. case 2: // hours
  120. {
  121. m_iTimeout *= 360;
  122. }
  123. break;
  124. }
  125. CWbemClassObject* pConsumerObject = ((CAction*)GetObjectPtr())->GetConsumerClassObject();
  126. if( pConsumerObject )
  127. {
  128. pConsumerObject->SetProperty(_T("CommandLineTemplate"),m_sCommandLine);
  129. pConsumerObject->SetProperty(_T("ExecutablePath"),m_sFileName);
  130. pConsumerObject->SetProperty(_T("KillTimeout"),m_iTimeout);
  131. pConsumerObject->SetProperty(_T("WorkingDirectory"),m_sWorkingDirectory);
  132. pConsumerObject->SetProperty(_T("RunInteractively"),true);
  133. pConsumerObject->SetProperty(_T("ShowWindowCommand"),m_bWindowed);
  134. pConsumerObject->SaveAllProperties();
  135. delete pConsumerObject;
  136. }
  137. m_iTimeout = iOldTimeout;
  138. SetModified(FALSE);
  139. return TRUE;
  140. }
  141. void CActionCmdLinePage::OnDestroy()
  142. {
  143. CHMPropertyPage::OnDestroy();
  144. // v-marfin : bug 59643 : CnxPropertyPageDestory() must be called from this page's
  145. // OnDestroy function.
  146. CnxPropertyPageDestroy();
  147. }
  148. void CActionCmdLinePage::OnButtonAdvanced()
  149. {
  150. // TODO: Add your control notification handler code here
  151. }
  152. void CActionCmdLinePage::OnButtonBrowseDirectory()
  153. {
  154. UpdateData(TRUE);
  155. LPMALLOC pMalloc;
  156. if( ::SHGetMalloc(&pMalloc) == NOERROR )
  157. {
  158. BROWSEINFO bi;
  159. TCHAR szBuffer[MAX_PATH];
  160. LPITEMIDLIST pidlDesktop;
  161. LPITEMIDLIST pidl;
  162. if( ::SHGetSpecialFolderLocation(GetSafeHwnd(),CSIDL_DESKTOP,&pidlDesktop) != NOERROR )
  163. return;
  164. CString sResString;
  165. sResString.LoadString(IDS_STRING_BROWSE_FOLDER);
  166. bi.hwndOwner = GetSafeHwnd();
  167. bi.pidlRoot = pidlDesktop;
  168. bi.pszDisplayName = szBuffer;
  169. bi.lpszTitle = LPCTSTR(sResString);
  170. bi.ulFlags = BIF_RETURNONLYFSDIRS;
  171. bi.lpfn = NULL;
  172. bi.lParam = 0;
  173. if( (pidl = ::SHBrowseForFolder(&bi)) != NULL )
  174. {
  175. if (SUCCEEDED(::SHGetPathFromIDList(pidl, szBuffer)))
  176. {
  177. m_sWorkingDirectory = szBuffer;
  178. UpdateData(FALSE);
  179. }
  180. pMalloc->Free(pidl);
  181. }
  182. pMalloc->Free(pidlDesktop);
  183. pMalloc->Release();
  184. }
  185. }
  186. void CActionCmdLinePage::OnButtonBrowseFile()
  187. {
  188. UpdateData(TRUE);
  189. CString sFilter;
  190. CString sTitle;
  191. sFilter.LoadString(IDS_STRING_FILTER);
  192. sTitle.LoadString(IDS_STRING_BROWSE_FILE);
  193. // v-marfin 61030 Change Browse for file dialog to fix default extension
  194. // CFileDialog fdlg(TRUE,_T("*.*"),NULL,OFN_FILEMUSTEXIST|OFN_SHAREAWARE|OFN_HIDEREADONLY,sFilter);
  195. CFileDialog fdlg(TRUE, // Is FILEOPEN dialog?
  196. NULL, // default extension if no extension provided
  197. NULL, // initial filename
  198. OFN_FILEMUSTEXIST|OFN_SHAREAWARE|OFN_HIDEREADONLY, // flags
  199. sFilter); // filter
  200. fdlg.m_ofn.lpstrTitle = sTitle;
  201. if( fdlg.DoModal() == IDOK )
  202. {
  203. m_sFileName = fdlg.GetPathName();
  204. UpdateData(FALSE);
  205. }
  206. }
  207. void CActionCmdLinePage::OnChangeEditCommandLine()
  208. {
  209. // TODO: If this is a RICHEDIT control, the control will not
  210. // send this notification unless you override the CHMPropertyPage::OnInitDialog()
  211. // function and call CRichEditCtrl().SetEventMask()
  212. // with the ENM_CHANGE flag ORed into the mask.
  213. SetModified();
  214. }
  215. void CActionCmdLinePage::OnChangeEditFileName()
  216. {
  217. // TODO: If this is a RICHEDIT control, the control will not
  218. // send this notification unless you override the CHMPropertyPage::OnInitDialog()
  219. // function and call CRichEditCtrl().SetEventMask()
  220. // with the ENM_CHANGE flag ORed into the mask.
  221. SetModified();
  222. }
  223. void CActionCmdLinePage::OnChangeEditProcessTimeout()
  224. {
  225. // TODO: If this is a RICHEDIT control, the control will not
  226. // send this notification unless you override the CHMPropertyPage::OnInitDialog()
  227. // function and call CRichEditCtrl().SetEventMask()
  228. // with the ENM_CHANGE flag ORed into the mask.
  229. SetModified();
  230. }
  231. void CActionCmdLinePage::OnChangeEditWorkingDir()
  232. {
  233. // TODO: If this is a RICHEDIT control, the control will not
  234. // send this notification unless you override the CHMPropertyPage::OnInitDialog()
  235. // function and call CRichEditCtrl().SetEventMask()
  236. // with the ENM_CHANGE flag ORed into the mask.
  237. SetModified();
  238. }
  239. void CActionCmdLinePage::OnSelendokComboTimeoutUnits()
  240. {
  241. SetModified();
  242. }
  243. void CActionCmdLinePage::OnButtonInsertion()
  244. {
  245. CPoint pt;
  246. GetCursorPos(&pt);
  247. m_InsertionMenu.DisplayMenu(pt);
  248. UpdateData();
  249. SetModified();
  250. }