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.

272 lines
7.0 KiB

  1. // ActionScriptPage.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 "ActionScriptPage.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. // CActionScriptPage property page
  16. IMPLEMENT_DYNCREATE(CActionScriptPage, CHMPropertyPage)
  17. CActionScriptPage::CActionScriptPage() : CHMPropertyPage(CActionScriptPage::IDD)
  18. {
  19. //{{AFX_DATA_INIT(CActionScriptPage)
  20. m_sFileName = _T("");
  21. m_iTimeout = 0;
  22. m_iScriptEngine = -1;
  23. //}}AFX_DATA_INIT
  24. m_sHelpTopic = _T("HMon21.chm::/dscrpact.htm");
  25. }
  26. CActionScriptPage::~CActionScriptPage()
  27. {
  28. }
  29. void CActionScriptPage::DoDataExchange(CDataExchange* pDX)
  30. {
  31. CHMPropertyPage::DoDataExchange(pDX);
  32. //{{AFX_DATA_MAP(CActionScriptPage)
  33. DDX_Control(pDX, IDC_COMBO_SCRIPT_ENGINE, m_ScriptEngine);
  34. DDX_Control(pDX, IDC_COMBO_TIMEOUT_UNITS, m_TimeoutUnits);
  35. DDX_Text(pDX, IDC_EDIT_FILE_NAME, m_sFileName);
  36. DDX_Text(pDX, IDC_EDIT_TIMEOUT, m_iTimeout);
  37. DDX_CBIndex(pDX, IDC_COMBO_SCRIPT_ENGINE, m_iScriptEngine);
  38. //}}AFX_DATA_MAP
  39. }
  40. BEGIN_MESSAGE_MAP(CActionScriptPage, CHMPropertyPage)
  41. //{{AFX_MSG_MAP(CActionScriptPage)
  42. ON_BN_CLICKED(IDC_BUTTON_BROWSE_FILE, OnButtonBrowseFile)
  43. ON_BN_CLICKED(IDC_BUTTON_OPEN, OnButtonOpen)
  44. ON_CBN_SELENDOK(IDC_COMBO_SCRIPT_ENGINE, OnSelendokComboScriptEngine)
  45. ON_CBN_SELENDOK(IDC_COMBO_TIMEOUT_UNITS, OnSelendokComboTimeoutUnits)
  46. ON_EN_CHANGE(IDC_EDIT_FILE_NAME, OnChangeEditFileName)
  47. ON_EN_CHANGE(IDC_EDIT_TEXT, OnChangeEditText)
  48. ON_EN_CHANGE(IDC_EDIT_TIMEOUT, OnChangeEditTimeout)
  49. ON_WM_DESTROY()
  50. //}}AFX_MSG_MAP
  51. END_MESSAGE_MAP()
  52. /////////////////////////////////////////////////////////////////////////////
  53. // CActionScriptPage message handlers
  54. BOOL CActionScriptPage::OnInitDialog()
  55. {
  56. // v-marfin : bug 59643 : This will be the default starting page for the property
  57. // sheet so call CnxPropertyPageCreate() to unmarshal the
  58. // connection for this thread. This function must be called
  59. // by the first page of the property sheet. It used to
  60. // be called by the "General" page and its call still remains
  61. // there as well in case the general page is loaded by a
  62. // different code path that does not also load this page.
  63. // The CnxPropertyPageCreate function has been safeguarded
  64. // to simply return if the required call has already been made.
  65. // CnxPropertyPageDestory() must be called from this page's
  66. // OnDestroy function.
  67. // unmarshal connmgr
  68. CnxPropertyPageCreate();
  69. CHMPropertyPage::OnInitDialog();
  70. CWbemClassObject* pConsumerObject = ((CAction*)GetObjectPtr())->GetConsumerClassObject();
  71. if( pConsumerObject )
  72. {
  73. CString sScriptEngine;
  74. pConsumerObject->GetProperty(_T("ScriptingEngine"),sScriptEngine);
  75. sScriptEngine.MakeUpper();
  76. if( sScriptEngine == _T("VBSCRIPT") )
  77. {
  78. m_iScriptEngine = 0;
  79. }
  80. else if( sScriptEngine == _T("JSCRIPT") )
  81. {
  82. m_iScriptEngine = 1;
  83. }
  84. pConsumerObject->GetProperty(_T("ScriptFileName"),m_sFileName);
  85. pConsumerObject->GetProperty(_T("KillTimeout"),m_iTimeout);
  86. m_TimeoutUnits.SetCurSel(0);
  87. delete pConsumerObject;
  88. }
  89. SendDlgItemMessage(IDC_SPIN2,UDM_SETRANGE32,0,9999);
  90. SendDlgItemMessage(IDC_SPIN3,UDM_SETRANGE32,0,9999);
  91. UpdateData(FALSE);
  92. return TRUE; // return TRUE unless you set the focus to a control
  93. // EXCEPTION: OCX Property Pages should return FALSE
  94. }
  95. BOOL CActionScriptPage::OnApply()
  96. {
  97. if( ! CHMPropertyPage::OnApply() )
  98. {
  99. return FALSE;
  100. }
  101. UpdateData();
  102. if( m_sFileName.IsEmpty() )
  103. {
  104. return FALSE;
  105. }
  106. int iOldTimeout = m_iTimeout;
  107. switch( m_TimeoutUnits.GetCurSel() )
  108. {
  109. case 1: // minutes
  110. {
  111. m_iTimeout *= 60;
  112. }
  113. break;
  114. case 2: // hours
  115. {
  116. m_iTimeout *= 360;
  117. }
  118. break;
  119. }
  120. CWbemClassObject* pConsumerObject = ((CAction*)GetObjectPtr())->GetConsumerClassObject();
  121. if( pConsumerObject )
  122. {
  123. CString sScriptEngine;
  124. m_ScriptEngine.GetLBText(m_iScriptEngine,sScriptEngine);
  125. pConsumerObject->SetProperty(_T("ScriptingEngine"),sScriptEngine);
  126. pConsumerObject->SetProperty(_T("ScriptFileName"),m_sFileName);
  127. pConsumerObject->SetProperty(_T("KillTimeout"),m_iTimeout);
  128. pConsumerObject->SaveAllProperties();
  129. delete pConsumerObject;
  130. }
  131. m_iTimeout = iOldTimeout;
  132. SetModified(FALSE);
  133. return TRUE;
  134. }
  135. void CActionScriptPage::OnButtonBrowseFile()
  136. {
  137. UpdateData();
  138. CString sFilter;
  139. CString sTitle;
  140. sFilter.LoadString(IDS_STRING_FILTER);
  141. sTitle.LoadString(IDS_STRING_BROWSE_FILE);
  142. // v-marfin 61030 Change Browse for file dialog to fix default extension
  143. // CFileDialog fdlg(TRUE,_T("*.*"),NULL,OFN_FILEMUSTEXIST|OFN_SHAREAWARE|OFN_HIDEREADONLY,sFilter);
  144. CFileDialog fdlg(TRUE, // Is FILEOPEN dialog?
  145. NULL, // default extension if no extension provided
  146. NULL, // initial filename
  147. OFN_FILEMUSTEXIST|OFN_SHAREAWARE|OFN_HIDEREADONLY, // flags
  148. sFilter); // filter
  149. fdlg.m_ofn.lpstrTitle = sTitle;
  150. if( fdlg.DoModal() == IDOK )
  151. {
  152. m_sFileName = fdlg.GetPathName();
  153. UpdateData(FALSE);
  154. }
  155. SetModified();
  156. }
  157. void CActionScriptPage::OnButtonOpen()
  158. {
  159. if( ! m_sFileName.IsEmpty() )
  160. {
  161. CString sCmdLine = _T("notepad.exe ")+m_sFileName;
  162. USES_CONVERSION;
  163. WinExec(T2A(sCmdLine),SW_SHOW);
  164. }
  165. }
  166. void CActionScriptPage::OnSelendokComboScriptEngine()
  167. {
  168. SetModified();
  169. UpdateData();
  170. }
  171. void CActionScriptPage::OnSelendokComboTimeoutUnits()
  172. {
  173. SetModified();
  174. UpdateData();
  175. }
  176. void CActionScriptPage::OnChangeEditFileName()
  177. {
  178. // TODO: If this is a RICHEDIT control, the control will not
  179. // send this notification unless you override the CHMPropertyPage::OnInitDialog()
  180. // function and call CRichEditCtrl().SetEventMask()
  181. // with the ENM_CHANGE flag ORed into the mask.
  182. SetModified();
  183. if( m_ScriptEngine.GetSafeHwnd() )
  184. {
  185. UpdateData();
  186. }
  187. }
  188. void CActionScriptPage::OnChangeEditText()
  189. {
  190. // TODO: If this is a RICHEDIT control, the control will not
  191. // send this notification unless you override the CHMPropertyPage::OnInitDialog()
  192. // function and call CRichEditCtrl().SetEventMask()
  193. // with the ENM_CHANGE flag ORed into the mask.
  194. SetModified();
  195. if( m_ScriptEngine.GetSafeHwnd() )
  196. {
  197. UpdateData();
  198. }
  199. }
  200. void CActionScriptPage::OnChangeEditTimeout()
  201. {
  202. // TODO: If this is a RICHEDIT control, the control will not
  203. // send this notification unless you override the CHMPropertyPage::OnInitDialog()
  204. // function and call CRichEditCtrl().SetEventMask()
  205. // with the ENM_CHANGE flag ORed into the mask.
  206. SetModified();
  207. if( m_ScriptEngine.GetSafeHwnd() )
  208. {
  209. UpdateData();
  210. }
  211. }
  212. void CActionScriptPage::OnDestroy()
  213. {
  214. CHMPropertyPage::OnDestroy();
  215. // v-marfin : bug 59643 : CnxPropertyPageDestory() must be called from this page's
  216. // OnDestroy function.
  217. CnxPropertyPageDestroy();
  218. }