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.

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