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.

476 lines
9.9 KiB

  1. //____________________________________________________________________________
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 1996.
  5. //
  6. // File: dlg.cxx
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 3/4/1996 RaviR Created
  15. //
  16. //____________________________________________________________________________
  17. #include "..\pch\headers.hxx"
  18. #pragma hdrstop
  19. #include "..\inc\dll.hxx"
  20. #include "dlg.hxx"
  21. #include "..\inc\misc.hxx"
  22. #include "..\inc\sadat.hxx"
  23. #include "..\folderui\dbg.h"
  24. #include "..\folderui\util.hxx"
  25. //
  26. // extern EXTERN_C
  27. //
  28. extern HINSTANCE g_hInstance;
  29. extern HANDLE g_hActCtx;
  30. CPropPage::CPropPage(
  31. LPCTSTR szTmplt,
  32. LPTSTR ptszTaskPath):
  33. m_hPage(NULL),
  34. m_fTaskInTasksFolder(FALSE),
  35. m_fSupportsSystemRequired(FALSE),
  36. m_bPlatformId(0),
  37. m_fDirty(FALSE),
  38. m_fInInit(FALSE)
  39. {
  40. Win4Assert(ptszTaskPath != NULL && *ptszTaskPath);
  41. lstrcpyn(m_ptszTaskPath, ptszTaskPath, ARRAY_LEN(m_ptszTaskPath));
  42. SecureZeroMemory(&m_psp, sizeof(m_psp));
  43. m_psp.dwSize = sizeof(PROPSHEETPAGE);
  44. m_psp.dwFlags = PSP_USECALLBACK | PSP_USEFUSIONCONTEXT;
  45. m_psp.hInstance = g_hInstance;
  46. m_psp.pszTemplate = szTmplt;
  47. m_psp.pfnDlgProc = StaticDlgProc;
  48. m_psp.pfnCallback = PageRelease;
  49. m_psp.pcRefParent = NULL; // do not set PSP_USEREFPARENT
  50. m_psp.lParam = (LPARAM) this;
  51. m_psp.hActCtx = g_hActCtx;
  52. }
  53. CPropPage::~CPropPage()
  54. {
  55. }
  56. INT_PTR CALLBACK
  57. CPropPage::StaticDlgProc(
  58. HWND hDlg,
  59. UINT uMsg,
  60. WPARAM wParam,
  61. LPARAM lParam)
  62. {
  63. CPropPage *pThis = (CPropPage *)GetWindowLongPtr(hDlg, DWLP_USER);
  64. if (uMsg == WM_INITDIALOG)
  65. {
  66. LPPROPSHEETPAGE ppsp = (LPPROPSHEETPAGE)lParam;
  67. pThis = (CPropPage *) ppsp->lParam;
  68. pThis->m_hPage = hDlg;
  69. SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR)pThis);
  70. }
  71. if (pThis != NULL)
  72. {
  73. return pThis->DlgProc(uMsg, wParam, lParam);
  74. }
  75. else
  76. {
  77. return DefWindowProc(hDlg, uMsg, wParam, lParam);
  78. }
  79. }
  80. LRESULT
  81. CPropPage::DlgProc(
  82. UINT uMsg,
  83. WPARAM wParam,
  84. LPARAM lParam)
  85. {
  86. LRESULT lr;
  87. switch (uMsg)
  88. {
  89. case WM_INITDIALOG:
  90. m_fInInit = TRUE;
  91. _BaseInit();
  92. lr = _OnInitDialog(lParam);
  93. m_fInInit = FALSE;
  94. return lr;
  95. case PSM_QUERYSIBLINGS:
  96. return _OnPSMQuerySibling(wParam, lParam);
  97. case WM_NOTIFY:
  98. return _OnNotify(uMsg, (UINT)wParam, lParam);
  99. case WM_WININICHANGE:
  100. return _OnWinIniChange(wParam, lParam);
  101. case WM_SETFOCUS:
  102. return _OnSetFocus((HWND)wParam);
  103. case WM_TIMER:
  104. return _OnTimer((UINT)wParam);
  105. case WM_HELP:
  106. return _OnHelp(((LPHELPINFO) lParam)->hItemHandle,
  107. HELP_WM_HELP);
  108. case WM_CONTEXTMENU:
  109. return _OnHelp((HANDLE) wParam, HELP_CONTEXTMENU);
  110. case WM_COMMAND:
  111. if (m_fInInit)
  112. {
  113. return TRUE;
  114. }
  115. return(_OnCommand(GET_WM_COMMAND_ID(wParam, lParam),
  116. GET_WM_COMMAND_HWND(wParam, lParam),
  117. GET_WM_COMMAND_CMD(wParam, lParam)));
  118. case WM_DESTROY:
  119. return _OnDestroy();
  120. default:
  121. return(FALSE);
  122. }
  123. return(TRUE);
  124. }
  125. LRESULT
  126. CPropPage::_OnNotify(
  127. UINT uMessage,
  128. UINT uParam,
  129. LPARAM lParam)
  130. {
  131. switch (((LPNMHDR)lParam)->code)
  132. {
  133. case PSN_APPLY:
  134. return _OnApply();
  135. case PSN_RESET:
  136. _OnCancel();
  137. return FALSE; // allow the property sheet to be destroyed.
  138. case PSN_SETACTIVE:
  139. return _OnPSNSetActive(lParam);
  140. case PSN_KILLACTIVE:
  141. return _OnPSNKillActive(lParam);
  142. case DTN_DATETIMECHANGE:
  143. return _OnDateTimeChange(lParam);
  144. case UDN_DELTAPOS:
  145. return _OnSpinDeltaPos((NM_UPDOWN *)lParam);
  146. default:
  147. return _ProcessListViewNotifications(uMessage, uParam, lParam);
  148. }
  149. return TRUE;
  150. }
  151. LRESULT
  152. CPropPage::_OnPSMQuerySibling(
  153. WPARAM wParam,
  154. LPARAM lParam)
  155. {
  156. SetWindowLongPtr(Hwnd(), DWLP_MSGRESULT, 0);
  157. return 0;
  158. }
  159. LRESULT
  160. CPropPage::_OnSpinDeltaPos(
  161. NM_UPDOWN * pnmud)
  162. {
  163. _EnableApplyButton();
  164. // Return FALSE to allow the change in the control's position.
  165. return FALSE;
  166. }
  167. LRESULT
  168. CPropPage::_OnCommand(
  169. int id,
  170. HWND hwndCtl,
  171. UINT codeNotify)
  172. {
  173. return FALSE;
  174. }
  175. LRESULT
  176. CPropPage::_OnWinIniChange(
  177. WPARAM wParam,
  178. LPARAM lParam)
  179. {
  180. return FALSE;
  181. }
  182. LRESULT
  183. CPropPage::_OnApply(void)
  184. {
  185. return FALSE;
  186. }
  187. LRESULT
  188. CPropPage::_OnCancel(void)
  189. {
  190. return FALSE;
  191. }
  192. LRESULT
  193. CPropPage::_OnSetFocus(
  194. HWND hwndLoseFocus)
  195. {
  196. // An application should return zero if it processes this message.
  197. return 1;
  198. }
  199. LRESULT
  200. CPropPage::_OnPSNSetActive(
  201. LPARAM lParam)
  202. {
  203. SetWindowLongPtr(m_hPage, DWLP_MSGRESULT, 0);
  204. return TRUE;
  205. }
  206. LRESULT
  207. CPropPage::_OnPSNKillActive(
  208. LPARAM lParam)
  209. {
  210. SetWindowLongPtr(m_hPage, DWLP_MSGRESULT, 0);
  211. return TRUE;
  212. }
  213. LRESULT
  214. CPropPage::_OnDateTimeChange(
  215. LPARAM lParam)
  216. {
  217. SetWindowLongPtr(m_hPage, DWLP_MSGRESULT, 0);
  218. return TRUE;
  219. }
  220. LRESULT
  221. CPropPage::_OnDestroy(void)
  222. {
  223. // If an application processes this message, it should return zero.
  224. return 1;
  225. }
  226. LRESULT
  227. CPropPage::_OnTimer(
  228. UINT idTimer)
  229. {
  230. // If an application processes this message, it should return zero.
  231. return 1;
  232. }
  233. BOOL
  234. CPropPage::_ProcessListViewNotifications(
  235. UINT uMsg,
  236. WPARAM wParam,
  237. LPARAM lParam)
  238. {
  239. return FALSE;
  240. }
  241. UINT CALLBACK
  242. CPropPage::PageRelease(
  243. HWND hwnd,
  244. UINT uMsg,
  245. LPPROPSHEETPAGE ppsp)
  246. {
  247. if (uMsg == PSPCB_RELEASE)
  248. {
  249. //
  250. // Determine instance that invoked this static function
  251. //
  252. CPropPage *pThis = (CPropPage *) ppsp->lParam;
  253. //
  254. // If page was created using an indirect dialog template, delete
  255. // that.
  256. //
  257. if (pThis->m_psp.dwFlags & PSP_DLGINDIRECT)
  258. {
  259. delete [] (BYTE *)pThis->m_psp.pResource;
  260. }
  261. delete pThis;
  262. }
  263. return TRUE;
  264. }
  265. //+---------------------------------------------------------------------------
  266. //
  267. // Member: CPropPage::_BaseInit, private
  268. //
  269. // Synopsis: Initialize scheduling-agent specific private data members,
  270. // m_fTaskInTasksFolder & m_bPlatformId. Do so by reading SA.DAT
  271. // in the folder containing the task.
  272. //
  273. // Arguments: None.
  274. //
  275. // Returns: None.
  276. //
  277. // Notes: None.
  278. //
  279. //----------------------------------------------------------------------------
  280. void
  281. CPropPage::_BaseInit(void)
  282. {
  283. TCHAR tszFolder[MAX_PATH + 1];
  284. ::GetParentDirectory(m_ptszTaskPath, tszFolder, MAX_PATH + 1);
  285. //
  286. // If running on the local system, we can determine whether resume
  287. // timers are supported directly instead of by checking sa.dat, which
  288. // might be stale.
  289. //
  290. BOOL fLocal = IsLocalFilename(m_ptszTaskPath);
  291. if (fLocal)
  292. {
  293. CheckSaDat(tszFolder);
  294. }
  295. //
  296. // Read sa.dat on target machine
  297. //
  298. HRESULT hr;
  299. DWORD dwVersion;
  300. BYTE bSvcFlags;
  301. hr = SADatGetData(tszFolder, &dwVersion, &m_bPlatformId, &bSvcFlags);
  302. if (SUCCEEDED(hr))
  303. {
  304. m_fTaskInTasksFolder = TRUE;
  305. if (fLocal)
  306. {
  307. m_fSupportsSystemRequired = ResumeTimersSupported();
  308. }
  309. else
  310. {
  311. m_fSupportsSystemRequired =
  312. bSvcFlags & SA_DAT_SVCFLAG_RESUME_TIMERS;
  313. }
  314. }
  315. else
  316. {
  317. //
  318. // Default on error (the file doesn't exist or the read failed).
  319. // Assume the task is external to the task folder and it exists
  320. // on a non-NT machine that doesn't support the system required
  321. // flag.
  322. //
  323. m_fTaskInTasksFolder = FALSE;
  324. m_bPlatformId = VER_PLATFORM_WIN32_WINDOWS;
  325. m_fSupportsSystemRequired = FALSE;
  326. }
  327. }
  328. //____________________________________________________________________________
  329. //____________________________________________________________________________
  330. //________________ _________________________________________
  331. //________________ class CDlg _________________________________________
  332. //________________ _________________________________________
  333. //____________________________________________________________________________
  334. //____________________________________________________________________________
  335. INT_PTR
  336. CDlg::RealDlgProc(
  337. UINT uMsg,
  338. WPARAM wParam,
  339. LPARAM lParam)
  340. {
  341. return(FALSE);
  342. }
  343. INT_PTR CALLBACK CDlg::DlgProc(
  344. HWND hDlg,
  345. UINT uMsg,
  346. WPARAM wParam,
  347. LPARAM lParam)
  348. {
  349. CDlg *pThis = (CDlg *)GetWindowLongPtr(hDlg, DWLP_USER);
  350. if (uMsg == WM_INITDIALOG)
  351. {
  352. pThis = (CDlg *)lParam;
  353. pThis->m_hDlg = hDlg;
  354. SetWindowLongPtr(hDlg, DWLP_USER, lParam);
  355. }
  356. if (pThis != NULL)
  357. {
  358. return pThis->RealDlgProc(uMsg, wParam, lParam);
  359. }
  360. else
  361. {
  362. return DefWindowProc(hDlg, uMsg, wParam, lParam);
  363. }
  364. }
  365. INT_PTR
  366. CDlg::DoModal(
  367. UINT idRes,
  368. HWND hParent)
  369. {
  370. return(DialogBoxParam(g_hInstance, MAKEINTRESOURCE(idRes),
  371. hParent, DlgProc, (LPARAM)this));
  372. }
  373. HWND
  374. CDlg::DoModeless(
  375. UINT idRes,
  376. HWND hParent)
  377. {
  378. return(CreateDialogParam(g_hInstance, MAKEINTRESOURCE(idRes),
  379. hParent, DlgProc, (LPARAM)this));
  380. }