Leaked source code of windows server 2003
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.

324 lines
8.5 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 1996.
  5. //
  6. // File: selprog.cxx
  7. //
  8. // Contents: Task wizard trigger selection property page implementation.
  9. //
  10. // Classes: CSelectTriggerPage
  11. //
  12. // History: 4-28-1997 DavidMun Created
  13. //
  14. //---------------------------------------------------------------------------
  15. #include "..\pch\headers.hxx"
  16. #pragma hdrstop
  17. #include "myheaders.hxx"
  18. //
  19. // Constants
  20. //
  21. // ILLEGAL_FILENAME_CHARS - characters to reject in task name edit control
  22. //
  23. #define ILLEGAL_FILENAME_CHARS TEXT("<>:/\\|")
  24. #define ARRAY_LEN(a) (sizeof(a)/sizeof(a[0]))
  25. //+--------------------------------------------------------------------------
  26. //
  27. // Member: CSelectTriggerPage::CSelectTriggerPage
  28. //
  29. // Synopsis: ctor
  30. //
  31. // Arguments: [ptszFolderPath] - full path to tasks folder with dummy
  32. // filename appended
  33. // [phPSP] - filled with prop page handle
  34. //
  35. // History: 4-28-1997 DavidMun Created
  36. //
  37. //---------------------------------------------------------------------------
  38. CSelectTriggerPage::CSelectTriggerPage(
  39. CTaskWizard *pParent,
  40. LPTSTR ptszFolderPath,
  41. HPROPSHEETPAGE *phPSP):
  42. _pParent(pParent),
  43. CWizPage(MAKEINTRESOURCE(IDD_SELECT_TRIGGER), ptszFolderPath)
  44. {
  45. TRACE_CONSTRUCTOR(CSelectTriggerPage);
  46. DEBUG_ASSERT(pParent);
  47. _tszDisplayName[0] = TCHAR('\0');
  48. _tszJobObjectFullPath[0] = TCHAR('\0');
  49. _idSelectedTrigger = 0;
  50. _CreatePage(IDS_SELTRIG_HDR1, IDS_SELTRIG_HDR2, phPSP);
  51. }
  52. //+--------------------------------------------------------------------------
  53. //
  54. // Member: CSelectTriggerPage::~CSelectTriggerPage
  55. //
  56. // Synopsis: dtor
  57. //
  58. // History: 4-28-1997 DavidMun Created
  59. //
  60. //---------------------------------------------------------------------------
  61. CSelectTriggerPage::~CSelectTriggerPage()
  62. {
  63. TRACE_DESTRUCTOR(CSelectTriggerPage);
  64. }
  65. //===========================================================================
  66. //
  67. // CPropPage overrides
  68. //
  69. //===========================================================================
  70. LRESULT
  71. CSelectTriggerPage::_OnCommand(
  72. INT id,
  73. HWND hwndCtl,
  74. UINT codeNotify)
  75. {
  76. TRACE_METHOD(CSelectTriggerPage, _OnCommand);
  77. LRESULT lr = 1;
  78. if (codeNotify == BN_CLICKED &&
  79. id >= seltrig_first_rb && id <= seltrig_last_rb)
  80. {
  81. lr = 0;
  82. if (!_idSelectedTrigger && *_tszDisplayName)
  83. {
  84. _SetWizButtons(PSWIZB_BACK | PSWIZB_NEXT);
  85. }
  86. _idSelectedTrigger = id;
  87. }
  88. else if (codeNotify == EN_UPDATE)
  89. {
  90. Edit_GetText(_hCtrl(seltrig_taskname_edit),
  91. _tszDisplayName,
  92. ARRAYLEN(_tszDisplayName));
  93. StripLeadTrailSpace(_tszDisplayName);
  94. if (!*_tszDisplayName)
  95. {
  96. _SetWizButtons(PSWIZB_BACK);
  97. }
  98. else if (_idSelectedTrigger)
  99. {
  100. _SetWizButtons(PSWIZB_BACK | PSWIZB_NEXT);
  101. }
  102. }
  103. return lr;
  104. }
  105. //===========================================================================
  106. //
  107. // CWizPage overrides
  108. //
  109. //===========================================================================
  110. //+--------------------------------------------------------------------------
  111. //
  112. // Member: CSelectTriggerPage::_OnInitDialog
  113. //
  114. // Synopsis: Initialize the controls on this page, only called once.
  115. //
  116. // Arguments: [lParam] - LPPROPSHEETPAGE
  117. //
  118. // Returns: TRUE (let windows set focus)
  119. //
  120. // History: 5-16-1997 DavidMun Created
  121. //
  122. //---------------------------------------------------------------------------
  123. LRESULT
  124. CSelectTriggerPage::_OnInitDialog(
  125. LPARAM lParam)
  126. {
  127. TRACE_METHOD(CSelectTriggerPage, _OnInitDialog);
  128. HWND hwndEdit = _hCtrl(seltrig_taskname_edit);
  129. Edit_LimitText(hwndEdit,
  130. ARRAYLEN(_tszDisplayName)
  131. - 1 // null terminator
  132. - lstrlen(GetTaskPath()) // path to tasks folder
  133. - 1 // backslash
  134. - (ARRAY_LEN(TSZ_DOTJOB) - 1)); // extension
  135. return TRUE;
  136. }
  137. //+--------------------------------------------------------------------------
  138. //
  139. // Member: CSelectTriggerPage::_OnPSNSetActive
  140. //
  141. // Synopsis: Init wizard buttons and other controls, called whenever
  142. // this page becomes the current page.
  143. //
  144. // Arguments: [lParam] - unused
  145. //
  146. // Returns: TRUE
  147. //
  148. // History: 5-16-1997 DavidMun Created
  149. //
  150. //---------------------------------------------------------------------------
  151. LRESULT
  152. CSelectTriggerPage::_OnPSNSetActive(
  153. LPARAM lParam)
  154. {
  155. if (_idSelectedTrigger)
  156. {
  157. _SetWizButtons(PSWIZB_BACK | PSWIZB_NEXT);
  158. }
  159. else
  160. {
  161. _SetWizButtons(PSWIZB_BACK);
  162. }
  163. if (!*_tszDisplayName)
  164. {
  165. CSelectProgramPage *pSelProg = GetSelectProgramPage(_pParent);
  166. pSelProg->GetDefaultDisplayName(_tszDisplayName,
  167. ARRAYLEN(_tszDisplayName));
  168. Edit_SetText(_hCtrl(seltrig_taskname_edit), _tszDisplayName);
  169. }
  170. return CPropPage::_OnPSNSetActive(lParam);
  171. }
  172. //+--------------------------------------------------------------------------
  173. //
  174. // Member: CSelectTriggerPage::_OnWizBack
  175. //
  176. // Synopsis: Handle the user's selection of the 'Back' button.
  177. //
  178. // History: 5-16-1997 DavidMun Created
  179. //
  180. //---------------------------------------------------------------------------
  181. LRESULT
  182. CSelectTriggerPage::_OnWizBack()
  183. {
  184. *_tszDisplayName = TEXT('\0');
  185. return 0;
  186. }
  187. //+--------------------------------------------------------------------------
  188. //
  189. // Member: CSelectTriggerPage::_OnWizNext
  190. //
  191. // Synopsis: Handle the user's selection of the 'Next' button
  192. //
  193. // Returns: -1 (DWLP_MSGRESULT contains next page number)
  194. //
  195. // History: 5-16-1997 DavidMun Created
  196. //
  197. //---------------------------------------------------------------------------
  198. LRESULT
  199. CSelectTriggerPage::_OnWizNext()
  200. {
  201. TRACE_METHOD(CSelectTriggerPage, _OnWizNext);
  202. LONG lNextPage;
  203. do
  204. {
  205. //
  206. // Check the filename for invalid characters
  207. //
  208. if (_tcspbrk(_tszDisplayName, ILLEGAL_FILENAME_CHARS))
  209. {
  210. SchedUIErrorDialog(Hwnd(), IDS_BAD_FILENAME, (LPTSTR) NULL);
  211. lNextPage = IDD_SELECT_TRIGGER; // stay on this page
  212. break;
  213. }
  214. //
  215. // Build the full pathname to the .job object
  216. //
  217. ULONG cchPath = lstrlen(GetTaskPath());
  218. StringCchCopy(_tszJobObjectFullPath, MAX_PATH +1, GetTaskPath());
  219. lstrcpyn(&_tszJobObjectFullPath[cchPath],
  220. GetTaskName(),
  221. ARRAYLEN(_tszJobObjectFullPath) - (cchPath + ARRAY_LEN(TSZ_DOTJOB) - 1));
  222. StringCchCat(_tszJobObjectFullPath, MAX_PATH +1, TSZ_DOTJOB);
  223. DeleteQuotes(_tszJobObjectFullPath);
  224. //
  225. // If the name collides with an existing task, get the user's
  226. // confirmation before proceeding to next page
  227. //
  228. if (FileExists(_tszJobObjectFullPath, MAX_PATH))
  229. {
  230. INT iAnswer = SchedUIMessageDialog(Hwnd(),
  231. IDS_TASK_ALREADY_EXISTS,
  232. MB_APPLMODAL |
  233. MB_SETFOREGROUND |
  234. MB_ICONQUESTION |
  235. MB_YESNO,
  236. _tszDisplayName);
  237. if (iAnswer != IDYES)
  238. {
  239. lNextPage = IDD_SELECT_TRIGGER;
  240. break;
  241. }
  242. }
  243. //
  244. // If the selected trigger type doesn't have its own page,
  245. // go directly to the end
  246. //
  247. if (_idSelectedTrigger == seltrig_startup_rb ||
  248. _idSelectedTrigger == seltrig_logon_rb)
  249. {
  250. lNextPage = IDD_PASSWORD;
  251. break;
  252. }
  253. lNextPage = IDD_DAILY + (_idSelectedTrigger - seltrig_first_rb);
  254. } while (0);
  255. SetWindowLongPtr(Hwnd(), DWLP_MSGRESULT, lNextPage);
  256. return -1;
  257. }