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.

1940 lines
56 KiB

  1. /*======================================================================================//
  2. | Process Control //
  3. | //
  4. |Copyright (c) 1998 Sequent Computer Systems, Incorporated. All rights reserved. //
  5. | //
  6. |File Name: ManagementPages.cpp //
  7. | //
  8. |Description: Implementation of Management Property pages //
  9. | Affinity, Priority, Workingset, Scheduling, Process Count //
  10. | //
  11. |Created: Paul Skoglund 09-1998 //
  12. | //
  13. |Notes: //
  14. | 9/9/1999 Paul Skoglund //
  15. | On the up-down controls even though the controls are configured not to wrap //
  16. | there appears to be a bug in the control that allows wrapping to occur if an //
  17. | arrow is held down and is accelating. The control appears to fails to accout //
  18. | for acceleration when range checking. Note the wizard dialogs are affected //
  19. | by the same bug if a workaround is constructed. //
  20. | //
  21. |Rev History: //
  22. | //
  23. |=======================================================================================*/
  24. #include "stdafx.h"
  25. #include "ManagementPages.h"
  26. #if _MSC_VER >= 1200
  27. #pragma warning( push )
  28. #endif
  29. #pragma warning( disable : 4800 ) //warning C4800: 'unsigned long' : forcing value to bool 'true' or 'false' (performance warning)
  30. void SetMGMTFlag(PC_MGMT_FLAGS &flag, PCMgmtFlags bit, BOOL bOn)
  31. {
  32. if (bOn) flag |= bit;
  33. else flag &= ~bit;
  34. }
  35. BOOL GetValue(TCHAR *const str, __int64 &value, __int64 &max);
  36. BOOL GetValue(TCHAR *const str, __int64 &value, __int64 &max)
  37. {
  38. TCHAR *pos = str;
  39. value = 0;
  40. while (*pos && *pos == _T('0') ) pos++;
  41. while (*pos)
  42. {
  43. if (value > (max/10) ||
  44. (*pos - _T('0')) > (max - (10 * value))
  45. )
  46. {
  47. value = 0;
  48. return FALSE;
  49. }
  50. value = 10 * value + *pos - _T('0');
  51. pos++;
  52. }
  53. return TRUE;
  54. }
  55. ///////////////////////////////////////////////////////////////////////////
  56. // some formating helper functions
  57. //
  58. LPCTSTR FormatMatchType( ITEM_STR strOut, const MATCH_TYPE matchType )
  59. {
  60. switch (matchType)
  61. {
  62. case MATCH_PGM:
  63. LoadStringHelper(strOut, IDS_MATCH_IMAGE);
  64. break;
  65. case MATCH_DIR:
  66. LoadStringHelper(strOut, IDS_MATCH_DIR);
  67. break;
  68. case MATCH_ANY:
  69. LoadStringHelper(strOut, IDS_MATCH_STRING);
  70. break;
  71. default:
  72. ASSERT(FALSE);
  73. LoadStringHelper(strOut, IDS_UNKNOWN);
  74. break;
  75. }
  76. return strOut;
  77. }
  78. LPCTSTR FormatAffinity(ITEM_STR str, const AFFINITY affinity)
  79. {
  80. str[MAX_ITEM_LEN-1] = 0;
  81. _sntprintf(str, MAX_ITEM_LEN-1, _T("0x%I64X"), affinity);
  82. return str;
  83. }
  84. LPCTSTR FormatPriority(ITEM_STR str, const PRIORITY priority)
  85. {
  86. if (priority == PCPrioNormal)
  87. LoadStringHelper(str, IDS_NORMAL);
  88. else if (priority == PCPrioRealTime)
  89. LoadStringHelper(str, IDS_REALTIME);
  90. else if (priority == PCPrioHigh)
  91. LoadStringHelper(str, IDS_HIGH);
  92. else if (priority == PCPrioAboveNormal)
  93. LoadStringHelper(str, IDS_ABOVE_NORMAL);
  94. else if (priority == PCPrioBelowNormal)
  95. LoadStringHelper(str, IDS_BELOW_NORMAL);
  96. else if (priority == PCPrioIdle)
  97. LoadStringHelper(str, IDS_LOW);
  98. else
  99. LoadStringHelper(str, IDS_UNKNOWN);
  100. return str;
  101. }
  102. LPCTSTR FormatSchedulingClass(ITEM_STR str, const SCHEDULING_CLASS schedClass)
  103. {
  104. str[MAX_ITEM_LEN - 1] = 0;
  105. _sntprintf(str, MAX_ITEM_LEN - 1, _T("%u"), schedClass);
  106. return str;
  107. }
  108. LPCTSTR FormatProcCount(ITEM_STR str, const PROC_COUNT procCount)
  109. {
  110. ASSERT(sizeof(PROC_COUNT) == sizeof(int));
  111. str[MAX_ITEM_LEN - 1] = 0;
  112. _sntprintf(str, MAX_ITEM_LEN - 1, _T("%u"), procCount);
  113. return str;
  114. }
  115. LPCTSTR FormatPCUINT32(ITEM_STR str, const PCUINT32 uInt)
  116. {
  117. str[MAX_ITEM_LEN - 1] = 0;
  118. _sntprintf(str, MAX_ITEM_LEN - 1, _T("%u"), uInt);
  119. return str;
  120. }
  121. LPCTSTR FormatPCINT32(ITEM_STR str, const PCINT32 aInt)
  122. {
  123. str[MAX_ITEM_LEN - 1] = 0;
  124. _sntprintf(str, MAX_ITEM_LEN - 1, _T("%d"), aInt);
  125. return str;
  126. }
  127. LPCTSTR FormatPCUINT64(ITEM_STR str, const PCUINT64 aUInt64)
  128. {
  129. str[MAX_ITEM_LEN - 1] = 0;
  130. _sntprintf(str, MAX_ITEM_LEN - 1, _T("%I64u"), aUInt64);
  131. return str;
  132. }
  133. LPCTSTR FormatApplyFlag(ITEM_STR str, const BOOL applied)
  134. {
  135. str[MAX_ITEM_LEN - 1] = 0;
  136. if (applied)
  137. LoadStringHelper(str, IDS_YES );
  138. else
  139. LoadStringHelper(str, IDS_NO );
  140. return str;
  141. }
  142. LPCTSTR FormatMemory(ITEM_STR str, const MEMORY_VALUE memory_value)
  143. {
  144. str[MAX_ITEM_LEN - 1] = 0;
  145. _sntprintf(str, MAX_ITEM_LEN - 1, _T("%I64u"), memory_value/1024 );
  146. return str;
  147. }
  148. LPCTSTR FormatTime(ITEM_STR str, const TIME_VALUE time)
  149. {
  150. SYSTEMTIME systime, localsystime;
  151. int len;
  152. str[MAX_ITEM_LEN - 1] = 0;
  153. if ( FileTimeToSystemTime((FILETIME *) &time, &systime) &&
  154. SystemTimeToTzSpecificLocalTime(NULL, &systime, &localsystime) )
  155. {
  156. if (len = GetDateFormat( LOCALE_USER_DEFAULT, 0, &localsystime, NULL, str, MAX_ITEM_LEN - 1 ))
  157. {
  158. str[len - 1 ] = _T(' ');
  159. if (GetTimeFormat( LOCALE_USER_DEFAULT, 0, &localsystime, NULL, &str[len], MAX_ITEM_LEN - len - 1))
  160. {
  161. return str;
  162. }
  163. }
  164. }
  165. str[0] = 0;
  166. return str;
  167. }
  168. LPCTSTR FormatTimeToms(ITEM_STR str, const TIME_VALUE time)
  169. {
  170. str[MAX_ITEM_LEN - 1] = 0;
  171. _sntprintf(str, MAX_ITEM_LEN - 1, _T("%I64u"), time/10000 );
  172. return str;
  173. }
  174. LPCTSTR FormatCNSTime(ITEM_STR str, TIME_VALUE time)
  175. {
  176. TIME_VALUE hours = time / CNSperHour;
  177. time -= CNSperHour * hours;
  178. TIME_VALUE minutes = time / CNSperMinute;
  179. time -= CNSperMinute * minutes;
  180. TIME_VALUE seconds = time / CNSperSec;
  181. time -= CNSperSec * seconds;
  182. str[MAX_ITEM_LEN - 1] = 0;
  183. _sntprintf(str, MAX_ITEM_LEN - 1, _T("%I64u:%.2I64u:%.2I64u.%.7I64u"), hours, minutes, seconds, time);
  184. int len = _tcslen(str);
  185. while (len && str[--len] == _T('0') ) //strip trailing 0's
  186. str[len] = 0;
  187. return str;
  188. }
  189. LPCTSTR FormatCPUTIMELimitAction(ITEM_STR str, BOOL bMsgOnLimit)
  190. {
  191. str[MAX_ITEM_LEN - 1] = 0;
  192. if (bMsgOnLimit)
  193. LoadStringHelper(str, IDS_CPUTIMELIMT_ACTION_MSG );
  194. else
  195. LoadStringHelper(str, IDS_CPUTIMELIMT_ACTION_TERM );
  196. return str;
  197. }
  198. LPCTSTR FormatSheetTitle(CComBSTR &Title, const CComBSTR &item_name, const COMPUTER_CONNECTION_INFO &Target)
  199. {
  200. Title = item_name;
  201. CComBSTR bTemp;
  202. if (bTemp.LoadString(IDS_ON))
  203. Title.Append(bTemp);
  204. if (Target.bLocalComputer)
  205. {
  206. if (bTemp.LoadString(IDS_LOCAL_COMPUTER) )
  207. Title.Append(bTemp);
  208. }
  209. else
  210. {
  211. Title.Append(Target.RemoteComputer);
  212. }
  213. return Title.m_str;
  214. }
  215. ///////////////////////////////////////////////////////////////////////////
  216. // some dialog helper functions
  217. //
  218. int PriorityToID(PRIORITY p)
  219. {
  220. ASSERT(IDC_REALTIME == 1 + IDC_HIGH && IDC_HIGH == 1 + IDC_ABOVE_NORMAL &&
  221. IDC_ABOVE_NORMAL == 1 + IDC_NORMAL && IDC_NORMAL == 1 + IDC_BELOW_NORMAL &&
  222. IDC_BELOW_NORMAL == 1 + IDC_LOW );
  223. if (p == PCPrioRealTime)
  224. return IDC_REALTIME;
  225. else if (p == PCPrioHigh)
  226. return IDC_HIGH;
  227. else if (p == PCPrioAboveNormal)
  228. return IDC_ABOVE_NORMAL;
  229. else if (p == PCPrioNormal)
  230. return IDC_NORMAL;
  231. else if (p == PCPrioBelowNormal)
  232. return IDC_BELOW_NORMAL;
  233. else if (p == PCPrioIdle)
  234. return IDC_LOW;
  235. ASSERT(FALSE);
  236. return IDC_NORMAL;
  237. }
  238. PRIORITY IDToPriority(int id)
  239. {
  240. ASSERT(IDC_REALTIME == 1 + IDC_HIGH && IDC_HIGH == 1 + IDC_ABOVE_NORMAL &&
  241. IDC_ABOVE_NORMAL == 1 + IDC_NORMAL && IDC_NORMAL == 1 + IDC_BELOW_NORMAL &&
  242. IDC_BELOW_NORMAL == 1 + IDC_LOW );
  243. if (id == IDC_REALTIME)
  244. return PCPrioRealTime;
  245. else if (id == IDC_HIGH)
  246. return PCPrioHigh;
  247. else if (id == IDC_ABOVE_NORMAL)
  248. return PCPrioAboveNormal;
  249. else if (id == IDC_NORMAL)
  250. return PCPrioNormal;
  251. else if (id == IDC_BELOW_NORMAL)
  252. return PCPrioBelowNormal;
  253. else if (id == IDC_LOW)
  254. return PCPrioIdle;
  255. ASSERT(FALSE);
  256. return PCPrioNormal;
  257. }
  258. int MatchTypeToID(MATCH_TYPE matchType)
  259. {
  260. ASSERT(IDC_DIR + 1 == IDC_IMAGE &&
  261. IDC_IMAGE + 1 == IDC_STRING );
  262. if (matchType == MATCH_PGM)
  263. return IDC_IMAGE;
  264. else if (matchType == MATCH_DIR)
  265. return IDC_DIR;
  266. else if (matchType == MATCH_ANY)
  267. return IDC_STRING;
  268. ASSERT(FALSE);
  269. return IDC_IMAGE;
  270. }
  271. BOOL ValidateTimeField(HWND hDlg, WORD wID, TIME_VALUE &newtime)
  272. {
  273. TCHAR ValidChars[] = _T("0123456789.:");
  274. TCHAR Digits[] = _T("0123456789");
  275. TCHAR StrBuffer[32];
  276. newtime = 0;
  277. StrBuffer[ARRAY_SIZE(StrBuffer) - 1 ] = 0;
  278. LRESULT pos = SendDlgItemMessage(hDlg, wID, WM_GETTEXT, ARRAY_SIZE(StrBuffer)-1, (LPARAM) &StrBuffer);
  279. if (pos > 0 )
  280. {
  281. if (pos != (int) _tcsspn(&StrBuffer[0], &ValidChars[0]) )
  282. return FALSE;
  283. __int64 cns = 0;
  284. __int64 seconds = 0;
  285. __int64 minutes = 0;
  286. __int64 hours = 0;
  287. TCHAR *dot = _tcsrchr(&StrBuffer[0], _T('.'));
  288. if (dot) // convert tenths of second to CNS
  289. {
  290. *dot = 0;
  291. dot++;
  292. unsigned int len = _tcslen(dot);
  293. if (len > 7 || len != _tcsspn(dot, Digits) )
  294. return FALSE;
  295. cns = _ttoi64(dot);
  296. for(unsigned int x = 0; cns && x < (7 - len); x++)
  297. cns *= 10;
  298. }
  299. struct {
  300. __int64 *val;
  301. __int64 max;
  302. } fields [] = {
  303. {&seconds, MAXLONGLONG/CNSperSec },
  304. {&minutes, MAXLONGLONG/CNSperMinute},
  305. {&hours, MAXLONGLONG/CNSperHour }
  306. };
  307. for (int i = 0; i < ARRAY_SIZE(fields); i++)
  308. {
  309. dot = _tcsrchr(&StrBuffer[0], _T(':'));
  310. if (!dot)
  311. {
  312. dot = &StrBuffer[0];
  313. }
  314. else
  315. {
  316. *dot = 0;
  317. dot++;
  318. }
  319. if (_tcslen(dot) != _tcsspn(dot, Digits))
  320. return FALSE;
  321. if ( !GetValue(dot, *(fields[i].val), fields[i].max) )
  322. return FALSE;
  323. if (dot == &StrBuffer[0])
  324. break;
  325. }
  326. newtime = cns;
  327. if ( (CNSperSec * seconds) <= (MAXLONGLONG - newtime) )
  328. {
  329. newtime += CNSperSec * seconds;
  330. if ( (CNSperMinute * minutes) <= (MAXLONGLONG - newtime) )
  331. {
  332. newtime += CNSperMinute * minutes;
  333. if (CNSperHour * hours <= (MAXLONGLONG - newtime) )
  334. {
  335. newtime += CNSperHour * hours;
  336. return TRUE;
  337. }
  338. }
  339. }
  340. }
  341. newtime = 0;
  342. return FALSE;
  343. }
  344. ///////////////////////////////////////////////////////////////////////////
  345. // Affinity Management Page Implementation
  346. CMGMTAffinityPage::CMGMTAffinityPage(int nTitle, CProcDetailContainer *pContainer, AFFINITY ProcessorMask) :
  347. CMySnapInPropertyPageImpl<CMGMTAffinityPage>(nTitle),
  348. m_PageType(PROCESS_PAGE), m_pProcContainer(pContainer), m_pJobContainer(NULL),
  349. m_ProcessorMask(ProcessorMask)
  350. {
  351. m_pProcContainer->AddRef();
  352. Initialize();
  353. }
  354. CMGMTAffinityPage::CMGMTAffinityPage(int nTitle, CJobDetailContainer *pContainer, AFFINITY ProcessorMask) :
  355. CMySnapInPropertyPageImpl<CMGMTAffinityPage>(nTitle),
  356. m_PageType(JOB_PAGE), m_pProcContainer(NULL), m_pJobContainer(pContainer),
  357. m_ProcessorMask(ProcessorMask)
  358. {
  359. m_pJobContainer->AddRef();
  360. Initialize();
  361. }
  362. void CMGMTAffinityPage::Initialize()
  363. {
  364. ASSERT(sizeof(PageFields.on) == sizeof(PageFields));
  365. PageFields.on = 0;
  366. m_bReadOnly = FALSE;
  367. m_affinitychk = FALSE;
  368. m_affinity = 0;
  369. m_hIconImage = NULL;
  370. m_psp.dwFlags |= PSP_HASHELP;
  371. }
  372. CMGMTAffinityPage::~CMGMTAffinityPage()
  373. {
  374. if (m_PageType == PROCESS_PAGE)
  375. m_pProcContainer->Release();
  376. else if (m_PageType == JOB_PAGE)
  377. m_pJobContainer->Release();
  378. if (m_hIconImage)
  379. VERIFY(::DestroyIcon( (HICON) m_hIconImage));
  380. }
  381. LRESULT CMGMTAffinityPage::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  382. {
  383. CComBSTR bStr;
  384. int PromptID;
  385. if (m_PageType == PROCESS_PAGE)
  386. {
  387. m_hIconImage = ::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDI_PROCESSES), IMAGE_ICON, 32, 32, LR_DEFAULTCOLOR );
  388. PromptID = IDS_AFFINITY_JOBWARNING;
  389. }
  390. else
  391. {
  392. m_hIconImage = ::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDI_JOBS), IMAGE_ICON, 32, 32, LR_DEFAULTCOLOR );
  393. PromptID = IDS_AFFINITY_NOJOBWARNING;
  394. }
  395. ASSERT(m_hIconImage);
  396. if (m_hIconImage)
  397. SendDlgItemMessage(IDC_PAGE_ICON, STM_SETICON, (WPARAM) m_hIconImage, 0);
  398. if (bStr.LoadString(PromptID))
  399. VERIFY(SetDlgItemText(IDC_AFFINITY_PROMPT, bStr.m_str));
  400. UpdateData(FALSE);
  401. bHandled = FALSE;
  402. return TRUE; // Let the system set the focus
  403. }
  404. LRESULT CMGMTAffinityPage::OnWMHelp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  405. {
  406. HELPINFO *phi = (HELPINFO*) lParam;
  407. if (phi && phi->iContextType == HELPINFO_WINDOW)
  408. {
  409. if (phi->iCtrlId > IDC_AFFINITY1 && phi->iCtrlId < IDC_AFFINITY64)
  410. {
  411. phi->iCtrlId = IDC_AFFINITY1;
  412. phi->hItemHandle = GetDlgItem(phi->iCtrlId);
  413. }
  414. if (m_pJobContainer)
  415. {
  416. IDCsToIDHs HelpMap[] = {{IDC_AFFINITY_FRAME, HELP_GRP_AFFINITY_FRAME },
  417. {IDC_AFFINITY_CHK, HELP_GRP_AFFINITY_APPLY },
  418. {IDC_AFFINITY1, HELP_GRP_AFFINITY},
  419. {IDC_AFFINITY64, HELP_GRP_AFFINITY},
  420. {0,0} };
  421. ::WinHelp((HWND) phi->hItemHandle, ContextHelpFile, HELP_WM_HELP, (DWORD_PTR) &HelpMap);
  422. }
  423. else
  424. {
  425. IDCsToIDHs HelpMap[] = {{IDC_AFFINITY_FRAME, HELP_PROC_AFFINITY_FRAME },
  426. {IDC_AFFINITY_CHK, HELP_PROC_AFFINITY_APPLY },
  427. {IDC_AFFINITY1, HELP_PROC_AFFINITY},
  428. {IDC_AFFINITY64, HELP_PROC_AFFINITY},
  429. {0,0} };
  430. ::WinHelp((HWND) phi->hItemHandle, ContextHelpFile, HELP_WM_HELP, (DWORD_PTR) &HelpMap);
  431. }
  432. return TRUE;
  433. }
  434. bHandled = FALSE;
  435. return FALSE;
  436. }
  437. BOOL CMGMTAffinityPage::OnHelp()
  438. {
  439. MMCPropertyHelp(const_cast<TCHAR*>(HELP_ru_affinity));
  440. return TRUE;
  441. }
  442. BOOL CMGMTAffinityPage::Validate(BOOL bSave /* = FALSE */)
  443. {
  444. AFFINITY affinity = 0;
  445. bool affinitychk = (BST_CHECKED == IsDlgButtonChecked(IDC_AFFINITY_CHK));
  446. for (int i = IDC_AFFINITY1; i <= IDC_AFFINITY64; i++)
  447. {
  448. if ( BST_UNCHECKED != IsDlgButtonChecked(i) )
  449. affinity |= (ProcessorBit << (i - IDC_AFFINITY1));
  450. }
  451. // warn the user if they make changes but have an apply affinity rule without
  452. // referencing at least one available processor
  453. if (affinitychk && !(affinity & m_ProcessorMask) && PageFields.on)
  454. {
  455. ITEM_STR strOut;
  456. LoadStringHelper(strOut, IDS_AFFINITY_WARNING);
  457. if (IDYES != MessageBox(strOut, NULL, MB_YESNO | MB_ICONQUESTION))
  458. return FALSE;
  459. }
  460. if (bSave)
  461. {
  462. if (m_PageType == PROCESS_PAGE)
  463. {
  464. m_pProcContainer->m_new.base.mgmtParms.affinity = affinity;
  465. SetMGMTFlag(m_pProcContainer->m_new.base.mgmtParms.mFlags, PCMFLAG_APPLY_AFFINITY, affinitychk);
  466. }
  467. else if (m_PageType == JOB_PAGE)
  468. {
  469. m_pJobContainer->m_new.base.mgmtParms.affinity = affinity;
  470. SetMGMTFlag(m_pJobContainer->m_new.base.mgmtParms.mFlags, PCMFLAG_APPLY_AFFINITY, affinitychk);
  471. }
  472. }
  473. return TRUE;
  474. }
  475. BOOL CMGMTAffinityPage::UpdateData(BOOL bSaveAndValidate)
  476. {
  477. if (bSaveAndValidate)
  478. {
  479. return Validate(TRUE);
  480. }
  481. else
  482. {
  483. ASSERT(IDC_AFFINITY1 + 63 == IDC_AFFINITY64);
  484. for(int i = IDC_AFFINITY1; i <= IDC_AFFINITY64; i++)
  485. {
  486. if (m_affinity & (ProcessorBit << (i - IDC_AFFINITY1) ) )
  487. {
  488. if (m_ProcessorMask & (ProcessorBit << (i - IDC_AFFINITY1)))
  489. CheckDlgButton(i, BST_CHECKED);
  490. else
  491. CheckDlgButton(i, BST_INDETERMINATE);
  492. }
  493. else
  494. CheckDlgButton(i, BST_UNCHECKED);
  495. }
  496. CheckDlgButton(IDC_AFFINITY_CHK, m_affinitychk ? BST_CHECKED : BST_UNCHECKED);
  497. ApplyControlEnableRules(FALSE);
  498. return TRUE;
  499. }
  500. }
  501. void CMGMTAffinityPage::ApplyControlEnableRules(BOOL bForceDisable)
  502. {
  503. BOOL bEnable;
  504. if (m_bReadOnly || !m_affinitychk || bForceDisable)
  505. bEnable = FALSE;
  506. else
  507. bEnable = TRUE;
  508. for (int i = IDC_AFFINITY1; i <= IDC_AFFINITY64; i++)
  509. ::EnableWindow(GetDlgItem(i), bEnable);
  510. ::EnableWindow(GetDlgItem(IDC_AFFINITY_CHK), !(m_bReadOnly || bForceDisable));
  511. }
  512. BOOL CMGMTAffinityPage::OnSetActive()
  513. {
  514. if ( m_PageType == PROCESS_PAGE )
  515. {
  516. if (m_pProcContainer->m_new.base.mgmtParms.mFlags & PCMFLAG_APPLY_JOB_MEMBERSHIP)
  517. ApplyControlEnableRules(TRUE);
  518. else
  519. ApplyControlEnableRules(FALSE);
  520. }
  521. return TRUE;
  522. }
  523. LRESULT CMGMTAffinityPage::OnAffinityEdit(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  524. {
  525. if (wNotifyCode == BN_CLICKED)
  526. {
  527. ASSERT(wID >= IDC_AFFINITY1 && wID <= IDC_AFFINITY64);
  528. int bit = wID - IDC_AFFINITY1;
  529. UINT btnState = IsDlgButtonChecked(wID);
  530. if (btnState == BST_UNCHECKED)
  531. {
  532. if ( m_ProcessorMask & (ProcessorBit << bit))
  533. CheckDlgButton(wID, BST_CHECKED);
  534. else
  535. CheckDlgButton(wID, BST_INDETERMINATE);
  536. }
  537. else
  538. {
  539. CheckDlgButton(wID, BST_UNCHECKED);
  540. }
  541. AFFINITY affinity = 0;
  542. for ( int i = IDC_AFFINITY1; i<= IDC_AFFINITY64; i++)
  543. {
  544. if ( BST_UNCHECKED != IsDlgButtonChecked(i) )
  545. affinity |= (ProcessorBit << (i - IDC_AFFINITY1));
  546. }
  547. PageFields.Fields.affinity = (m_affinity != affinity);
  548. SetModified(PageFields.on);
  549. }
  550. bHandled = FALSE;
  551. return 0;
  552. }
  553. LRESULT CMGMTAffinityPage::OnChk(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  554. {
  555. if (wID == IDC_AFFINITY_CHK)
  556. {
  557. bool checked = (BST_CHECKED == IsDlgButtonChecked(IDC_AFFINITY_CHK));
  558. PageFields.Fields.affinitychk = (m_affinitychk != checked);
  559. for (int i = IDC_AFFINITY1; i <= IDC_AFFINITY64; i++)
  560. ::EnableWindow(GetDlgItem(i), checked);
  561. SetModified(PageFields.on);
  562. }
  563. bHandled = FALSE;
  564. return 0;
  565. }
  566. BOOL CMGMTAffinityPage::OnApply()
  567. {
  568. if (m_bReadOnly || !PageFields.on)
  569. return TRUE;
  570. if ( (m_PageType == PROCESS_PAGE && m_pProcContainer->Apply(GetParent())) ||
  571. (m_PageType == JOB_PAGE && m_pJobContainer->Apply(GetParent())) )
  572. {
  573. PageFields.on = 0;
  574. if (m_PageType == PROCESS_PAGE)
  575. {
  576. m_affinity = m_pProcContainer->m_new.base.mgmtParms.affinity;
  577. m_affinitychk = (m_pProcContainer->m_new.base.mgmtParms.mFlags & PCMFLAG_APPLY_AFFINITY);
  578. }
  579. else if (m_PageType == JOB_PAGE)
  580. {
  581. m_affinity = m_pJobContainer->m_new.base.mgmtParms.affinity;
  582. m_affinitychk = (m_pJobContainer->m_new.base.mgmtParms.mFlags & PCMFLAG_APPLY_AFFINITY);
  583. }
  584. return TRUE;
  585. }
  586. return FALSE;
  587. }
  588. ///////////////////////////////////////////////////////////////////////////
  589. // Priority Management Page Implementation
  590. CMGMTPriorityPage::CMGMTPriorityPage(int nTitle, CProcDetailContainer *pContainer) :
  591. CMySnapInPropertyPageImpl<CMGMTPriorityPage>(nTitle),
  592. m_pProcContainer(pContainer), m_pJobContainer(NULL), m_PageType(PROCESS_PAGE)
  593. {
  594. m_pProcContainer->AddRef();
  595. Initialize();
  596. }
  597. CMGMTPriorityPage::CMGMTPriorityPage(int nTitle, CJobDetailContainer *pContainer) :
  598. CMySnapInPropertyPageImpl<CMGMTPriorityPage>(nTitle),
  599. m_pProcContainer(NULL), m_pJobContainer(pContainer), m_PageType(JOB_PAGE)
  600. {
  601. m_pJobContainer->AddRef();
  602. Initialize();
  603. }
  604. void CMGMTPriorityPage::Initialize()
  605. {
  606. ASSERT(sizeof(PageFields.on) == sizeof(PageFields));
  607. PageFields.on = 0;
  608. m_bReadOnly = FALSE;
  609. m_prioritychk = FALSE;
  610. m_priority = PCPrioNormal;
  611. m_hIconImage = NULL;
  612. m_psp.dwFlags |= PSP_HASHELP;
  613. }
  614. CMGMTPriorityPage::~CMGMTPriorityPage()
  615. {
  616. if (m_PageType == PROCESS_PAGE)
  617. m_pProcContainer->Release();
  618. else if (m_PageType == JOB_PAGE)
  619. m_pJobContainer->Release();
  620. if (m_hIconImage)
  621. VERIFY(::DestroyIcon( (HICON) m_hIconImage));
  622. }
  623. LRESULT CMGMTPriorityPage::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  624. {
  625. CComBSTR bStr;
  626. int PromptID;
  627. if (m_PageType == PROCESS_PAGE)
  628. {
  629. m_hIconImage = ::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDI_PROCESSES), IMAGE_ICON, 32, 32, LR_DEFAULTCOLOR );
  630. ASSERT(m_hIconImage);
  631. PromptID = IDS_PRIORITY_JOBWARNING;
  632. }
  633. else
  634. {
  635. m_hIconImage = ::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDI_JOBS), IMAGE_ICON, 32, 32, LR_DEFAULTCOLOR );
  636. ASSERT(m_hIconImage);
  637. PromptID = IDS_PRIORITY_NOJOBWARNING;
  638. }
  639. if (m_hIconImage)
  640. SendDlgItemMessage(IDC_PAGE_ICON, STM_SETICON, (WPARAM) m_hIconImage, 0);
  641. if (bStr.LoadString(PromptID))
  642. VERIFY(SetDlgItemText(IDC_PRIORITY_PROMPT, bStr.m_str));
  643. UpdateData(FALSE);
  644. bHandled = FALSE;
  645. return TRUE; // Let the system set the focus
  646. }
  647. LRESULT CMGMTPriorityPage::OnWMHelp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  648. {
  649. HELPINFO *phi = (HELPINFO*) lParam;
  650. if (phi && phi->iContextType == HELPINFO_WINDOW)
  651. {
  652. if (m_pJobContainer)
  653. {
  654. IDCsToIDHs HelpMap[] = {{IDC_PRIORITY_FRAME, HELP_GRP_PRIORITY_FRAME },
  655. {IDC_PRIORITY_CHK, HELP_GRP_PRIORITY_APPLY },
  656. {IDC_REALTIME, HELP_GRP_PRIORITY_REAL},
  657. {IDC_HIGH, HELP_GRP_PRIORITY_HIGH},
  658. {IDC_ABOVE_NORMAL, HELP_GRP_PRIORITY_ABOVENORMAL},
  659. {IDC_NORMAL, HELP_GRP_PRIORITY_NORMAL},
  660. {IDC_BELOW_NORMAL, HELP_GRP_PRIORITY_BELOWNORMAL},
  661. {IDC_LOW, HELP_GRP_PRIORITY_LOW},
  662. {0,0} };
  663. ::WinHelp((HWND) phi->hItemHandle, ContextHelpFile, HELP_WM_HELP, (DWORD_PTR) &HelpMap);
  664. }
  665. else
  666. {
  667. IDCsToIDHs HelpMap[] = {{IDC_PRIORITY_FRAME, HELP_PROC_PRIORITY_FRAME },
  668. {IDC_PRIORITY_CHK, HELP_PROC_PRIORITY_APPLY },
  669. {IDC_REALTIME, HELP_PROC_PRIORITY_REAL},
  670. {IDC_HIGH, HELP_PROC_PRIORITY_HIGH},
  671. {IDC_ABOVE_NORMAL, HELP_PROC_PRIORITY_ABOVENORMAL},
  672. {IDC_NORMAL, HELP_PROC_PRIORITY_NORMAL},
  673. {IDC_BELOW_NORMAL, HELP_PROC_PRIORITY_BELOWNORMAL},
  674. {IDC_LOW, HELP_PROC_PRIORITY_LOW},
  675. {0,0} };
  676. ::WinHelp((HWND) phi->hItemHandle, ContextHelpFile, HELP_WM_HELP, (DWORD_PTR) &HelpMap);
  677. }
  678. return TRUE;
  679. }
  680. bHandled = FALSE;
  681. return FALSE;
  682. }
  683. BOOL CMGMTPriorityPage::OnHelp()
  684. {
  685. MMCPropertyHelp(const_cast<TCHAR*>(HELP_ru_priority));
  686. return TRUE;
  687. }
  688. BOOL CMGMTPriorityPage::Validate(BOOL bSave)
  689. {
  690. PRIORITY p = 0;
  691. for ( int i = IDC_LOW; i <= IDC_REALTIME; i++)
  692. {
  693. if ( BST_CHECKED == IsDlgButtonChecked(i) )
  694. p += IDToPriority(i);
  695. }
  696. if (IDToPriority(PriorityToID(p)) != p) //not fool proof, but do we really need to check this? no
  697. {
  698. MessageBeep(MB_ICONASTERISK);
  699. return FALSE;
  700. }
  701. if (bSave)
  702. {
  703. if (m_PageType == PROCESS_PAGE)
  704. {
  705. m_pProcContainer->m_new.base.mgmtParms.priority = p;
  706. SetMGMTFlag(m_pProcContainer->m_new.base.mgmtParms.mFlags, PCMFLAG_APPLY_PRIORITY, (BST_CHECKED == IsDlgButtonChecked(IDC_PRIORITY_CHK)));
  707. }
  708. else if (m_PageType == JOB_PAGE)
  709. {
  710. m_pJobContainer->m_new.base.mgmtParms.priority = p;
  711. SetMGMTFlag(m_pJobContainer->m_new.base.mgmtParms.mFlags, PCMFLAG_APPLY_PRIORITY, (BST_CHECKED == IsDlgButtonChecked(IDC_PRIORITY_CHK)));
  712. }
  713. }
  714. return TRUE;
  715. }
  716. BOOL CMGMTPriorityPage::UpdateData(BOOL bSaveAndValidate)
  717. {
  718. if (bSaveAndValidate)
  719. {
  720. return Validate(TRUE);
  721. }
  722. else
  723. {
  724. CheckRadioButton(IDC_LOW, IDC_REALTIME, PriorityToID(m_priority));
  725. CheckDlgButton(IDC_PRIORITY_CHK, m_prioritychk ? BST_CHECKED : BST_UNCHECKED);
  726. ApplyControlEnableRules(FALSE);
  727. return TRUE;
  728. }
  729. }
  730. void CMGMTPriorityPage::ApplyControlEnableRules(BOOL bForceDisable)
  731. {
  732. BOOL bEnable;
  733. if (m_bReadOnly || !m_prioritychk || bForceDisable)
  734. bEnable = FALSE;
  735. else
  736. bEnable = TRUE;
  737. UINT ids[] = { IDC_REALTIME, IDC_HIGH, IDC_ABOVE_NORMAL, IDC_NORMAL, IDC_BELOW_NORMAL, IDC_LOW, 0 };
  738. for (int i = 0; ids[i]; i++)
  739. ::EnableWindow(GetDlgItem(ids[i]), bEnable);
  740. ::EnableWindow(GetDlgItem(IDC_PRIORITY_CHK), !(m_bReadOnly || bForceDisable));
  741. }
  742. BOOL CMGMTPriorityPage::OnSetActive()
  743. {
  744. if ( m_PageType == PROCESS_PAGE )
  745. {
  746. if (m_pProcContainer->m_new.base.mgmtParms.mFlags & PCMFLAG_APPLY_JOB_MEMBERSHIP)
  747. ApplyControlEnableRules(TRUE);
  748. else
  749. ApplyControlEnableRules(FALSE);
  750. }
  751. return TRUE;
  752. }
  753. LRESULT CMGMTPriorityPage::OnChk(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  754. {
  755. if (wID == IDC_PRIORITY_CHK)
  756. {
  757. bool checked = (BST_CHECKED == IsDlgButtonChecked(IDC_PRIORITY_CHK));
  758. PageFields.Fields.prioritychk = (m_prioritychk != checked);
  759. UINT ids[] = { IDC_REALTIME, IDC_HIGH, IDC_ABOVE_NORMAL, IDC_NORMAL, IDC_BELOW_NORMAL, IDC_LOW,0 };
  760. for (int i = 0; ids[i]; i++)
  761. ::EnableWindow(GetDlgItem(ids[i]), checked);
  762. SetModified(PageFields.on);
  763. }
  764. bHandled = FALSE;
  765. return 0;
  766. }
  767. LRESULT CMGMTPriorityPage::OnPriorityEdit(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  768. {
  769. if (wNotifyCode == BN_CLICKED)
  770. {
  771. ASSERT(wID >= IDC_LOW && wID <= IDC_REALTIME );
  772. PRIORITY p = 0;
  773. for ( int i = IDC_LOW; i <= IDC_REALTIME; i++)
  774. {
  775. if ( BST_CHECKED == IsDlgButtonChecked(i) )
  776. p += IDToPriority(i);
  777. }
  778. PageFields.Fields.priority = (m_priority != p);
  779. SetModified(PageFields.on);
  780. }
  781. bHandled = FALSE;
  782. return 0;
  783. }
  784. BOOL CMGMTPriorityPage::OnApply()
  785. {
  786. if (m_bReadOnly || !PageFields.on)
  787. return TRUE;
  788. if ( (m_PageType == PROCESS_PAGE && m_pProcContainer->Apply(GetParent()) ) ||
  789. (m_PageType == JOB_PAGE && m_pJobContainer->Apply(GetParent()) ) )
  790. {
  791. PageFields.on = 0;
  792. if (m_PageType == PROCESS_PAGE)
  793. {
  794. m_priority = m_pProcContainer->m_new.base.mgmtParms.priority;
  795. m_prioritychk = m_pProcContainer->m_new.base.mgmtParms.mFlags & PCMFLAG_APPLY_PRIORITY;
  796. }
  797. else if (m_PageType == JOB_PAGE)
  798. {
  799. m_priority = m_pJobContainer->m_new.base.mgmtParms.priority;
  800. m_prioritychk = m_pJobContainer->m_new.base.mgmtParms.mFlags & PCMFLAG_APPLY_PRIORITY;
  801. }
  802. return TRUE;
  803. }
  804. return FALSE;
  805. }
  806. ///////////////////////////////////////////////////////////////////////////
  807. // Scheduling Class Management Page Implementation
  808. CMGMTSchedulingClassPage::CMGMTSchedulingClassPage(int nTitle, CJobDetailContainer *pContainer)
  809. : CMySnapInPropertyPageImpl<CMGMTSchedulingClassPage>(nTitle),
  810. m_pJobContainer(pContainer)
  811. {
  812. ASSERT(sizeof(PageFields.on) == sizeof(PageFields));
  813. PageFields.on = 0;
  814. m_bReadOnly = FALSE;
  815. m_schedClasschk = FALSE;
  816. m_schedClass = 5;
  817. m_psp.dwFlags |= PSP_HASHELP;
  818. m_pJobContainer->AddRef();
  819. }
  820. CMGMTSchedulingClassPage::~CMGMTSchedulingClassPage()
  821. {
  822. m_pJobContainer->Release();
  823. }
  824. LRESULT CMGMTSchedulingClassPage::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  825. {
  826. UpdateData(FALSE);
  827. bHandled = FALSE;
  828. return TRUE; // Let the system set the focus
  829. }
  830. LRESULT CMGMTSchedulingClassPage::OnWMHelp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  831. {
  832. HELPINFO *phi = (HELPINFO*) lParam;
  833. if (phi && phi->iContextType == HELPINFO_WINDOW)
  834. {
  835. IDCsToIDHs HelpMap[] = {{IDC_SCHEDULING_FRAME, HELP_SCHEDULING_FRAME },
  836. {IDC_SCHEDULING_CHK, HELP_SCHEDULING_APPLY },
  837. {IDC_SCLASS, HELP_SCHEDULING_CLASS},
  838. {IDC_SPIN, HELP_SCHEDULING_CLASS_SPIN},
  839. {0,0} };
  840. ::WinHelp((HWND) phi->hItemHandle, ContextHelpFile, HELP_WM_HELP, (DWORD_PTR) &HelpMap);
  841. return TRUE;
  842. }
  843. bHandled = FALSE;
  844. return FALSE;
  845. }
  846. BOOL CMGMTSchedulingClassPage::OnHelp()
  847. {
  848. MMCPropertyHelp(const_cast<TCHAR*>(HELP_ru_job_sch));
  849. return TRUE;
  850. }
  851. BOOL CMGMTSchedulingClassPage::Validate(BOOL bSave)
  852. {
  853. LRESULT pos = SendDlgItemMessage(IDC_SPIN, UDM_GETPOS, 0, 0);
  854. if (0 == HIWORD(pos) && LOWORD(pos) >= 0 && LOWORD(pos) <= 9 )
  855. {
  856. if (bSave)
  857. {
  858. SetMGMTFlag(m_pJobContainer->m_new.base.mgmtParms.mFlags, PCMFLAG_APPLY_SCHEDULING_CLASS, (BST_CHECKED == IsDlgButtonChecked(IDC_SCHEDULING_CHK)));
  859. m_pJobContainer->m_new.base.mgmtParms.schedClass = (SCHEDULING_CLASS) LOWORD(pos);
  860. }
  861. return TRUE;
  862. }
  863. HWND hWndCtl = GetDlgItem(IDC_SCLASS);
  864. if(hWndCtl)
  865. ::SetFocus(hWndCtl);
  866. MessageBeep(MB_ICONASTERISK);
  867. return FALSE;
  868. }
  869. BOOL CMGMTSchedulingClassPage::UpdateData(BOOL bSaveAndValidate)
  870. {
  871. if (bSaveAndValidate)
  872. {
  873. return Validate(TRUE);
  874. }
  875. else
  876. {
  877. CheckDlgButton(IDC_SCHEDULING_CHK, m_schedClasschk ? BST_CHECKED : BST_UNCHECKED);
  878. SendDlgItemMessage(IDC_SPIN, UDM_SETPOS, 0, MAKELONG(m_schedClass, 0) );
  879. SendDlgItemMessage(IDC_SPIN, UDM_SETRANGE32, 0, 9);
  880. if (m_bReadOnly || !m_schedClasschk)
  881. {
  882. DisableControl(IDC_SCLASS);
  883. DisableControl(IDC_SPIN);
  884. }
  885. if (m_bReadOnly)
  886. DisableControl(IDC_SCHEDULING_CHK);
  887. return TRUE;
  888. }
  889. }
  890. LRESULT CMGMTSchedulingClassPage::OnEditChange(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  891. {
  892. if (wID == IDC_SCLASS)
  893. {
  894. PageFields.Fields.schedClass = FALSE;
  895. LRESULT pos = SendDlgItemMessage(IDC_SPIN, UDM_GETPOS, 0,0);
  896. if (0 == HIWORD(pos) && LOWORD(pos) >= 0 && LOWORD(pos) <= 9 )
  897. PageFields.Fields.schedClass = (m_schedClass != LOWORD(pos));
  898. }
  899. SetModified(PageFields.on);
  900. bHandled = FALSE;
  901. return 0;
  902. }
  903. LRESULT CMGMTSchedulingClassPage::OnChk(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  904. {
  905. if (wID == IDC_SCHEDULING_CHK)
  906. {
  907. bool checked = (BST_CHECKED == IsDlgButtonChecked(IDC_SCHEDULING_CHK));
  908. PageFields.Fields.schedClasschk = (m_schedClasschk != checked);
  909. ::EnableWindow(GetDlgItem(IDC_SCLASS), checked);
  910. ::EnableWindow(GetDlgItem(IDC_SPIN), checked);
  911. SetModified(PageFields.on);
  912. }
  913. bHandled = FALSE;
  914. return 0;
  915. }
  916. BOOL CMGMTSchedulingClassPage::OnApply()
  917. {
  918. if (m_bReadOnly || !PageFields.on) // read only, nothing modified
  919. return TRUE;
  920. if ( m_pJobContainer->Apply(GetParent()) )
  921. {
  922. PageFields.on = 0;
  923. m_schedClasschk = m_pJobContainer->m_new.base.mgmtParms.mFlags & PCMFLAG_APPLY_SCHEDULING_CLASS;
  924. m_schedClass = m_pJobContainer->m_new.base.mgmtParms.schedClass;
  925. return TRUE;
  926. }
  927. return FALSE;
  928. }
  929. ///////////////////////////////////////////////////////////////////////////
  930. // Memory Management Page Implementation
  931. CMGMTMemoryPage::CMGMTMemoryPage(int nTitle, CProcDetailContainer *pContainer) :
  932. CMySnapInPropertyPageImpl<CMGMTMemoryPage>(nTitle),
  933. m_pProcContainer(pContainer), m_pJobContainer(NULL)
  934. {
  935. m_pProcContainer->AddRef();
  936. Initialize();
  937. }
  938. CMGMTMemoryPage::CMGMTMemoryPage(int nTitle, CJobDetailContainer *pContainer) :
  939. CMySnapInPropertyPageImpl<CMGMTMemoryPage>(nTitle),
  940. m_pProcContainer(NULL), m_pJobContainer(pContainer)
  941. {
  942. m_pJobContainer->AddRef();
  943. Initialize();
  944. }
  945. void CMGMTMemoryPage::Initialize()
  946. {
  947. ASSERT(sizeof(PageFields.on) == sizeof(PageFields));
  948. PageFields.on = 0;
  949. m_bReadOnly = FALSE;
  950. m_WSchk = FALSE;
  951. m_minWS = 0;
  952. m_maxWS = 0;
  953. m_procmemorylimitchk = FALSE;
  954. m_procmemorylimit = 0;
  955. m_jobmemorylimitchk = FALSE;
  956. m_jobmemorylimit = 0;
  957. m_hIconImage = NULL;
  958. m_psp.dwFlags |= PSP_HASHELP;
  959. }
  960. CMGMTMemoryPage::~CMGMTMemoryPage()
  961. {
  962. if (m_pProcContainer)
  963. m_pProcContainer->Release();
  964. if (m_pJobContainer)
  965. m_pJobContainer->Release();
  966. if (m_hIconImage)
  967. VERIFY(::DestroyIcon( (HICON) m_hIconImage));
  968. }
  969. LRESULT CMGMTMemoryPage::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  970. {
  971. if (m_pProcContainer)
  972. {
  973. m_hIconImage = ::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDI_PROCESSES), IMAGE_ICON, 32, 32, LR_DEFAULTCOLOR );
  974. //PromptID = IDS_AFFINITY_JOBWARNING;
  975. }
  976. else if (m_pJobContainer)
  977. {
  978. m_hIconImage = ::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDI_JOBS), IMAGE_ICON, 32, 32, LR_DEFAULTCOLOR );
  979. //PromptID = IDS_AFFINITY_NOJOBWARNING;
  980. }
  981. ASSERT(m_hIconImage);
  982. if (m_hIconImage)
  983. SendDlgItemMessage(IDC_PAGE_ICON, STM_SETICON, (WPARAM) m_hIconImage, 0);
  984. UpdateData(FALSE);
  985. bHandled = FALSE;
  986. return TRUE; // Let the system set the focus
  987. }
  988. LRESULT CMGMTMemoryPage::OnWMHelp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  989. {
  990. HELPINFO *phi = (HELPINFO*) lParam;
  991. if (phi && phi->iContextType == HELPINFO_WINDOW)
  992. {
  993. if (m_pJobContainer)
  994. {
  995. IDCsToIDHs HelpMap[]={{IDC_WORKINGSET_FRAME, HELP_GRP_WS_FRAME },
  996. {IDC_WORKINGSET_CHK, HELP_GRP_WS_APPLY },
  997. {IDC_MINWS, HELP_GRP_WS_MIN },
  998. {IDC_MINWS_SPIN, HELP_GRP_WS_MIN_SPIN},
  999. {IDC_MAXWS, HELP_GRP_WS_MAX},
  1000. {IDC_MAXWS_SPIN, HELP_GRP_WS_MAX_SPIN },
  1001. {IDC_PROCMEM_FRM, HELP_GRP_PROCCOM_FRAME },
  1002. {IDC_PROCMEMORY_CHK, HELP_GRP_PROCCOM_APPLY },
  1003. {IDC_PROCMEMORY, HELP_GRP_PROCCOM_MAX },
  1004. {IDC_PROC_SPIN, HELP_GRP_PROCCOM_MAX_SPIN},
  1005. {IDC_JOBMEM_FRM, HELP_GRP_GRPCOM_FRAME },
  1006. {IDC_JOBMEMORY_CHK, HELP_GRP_GRPCOM_APPLY },
  1007. {IDC_JOBMEMORY, HELP_GRP_GRPCOM_MAX },
  1008. {IDC_JOB_SPIN, HELP_GRP_GRPCOM_MAX_SPIN},
  1009. {0,0} };
  1010. ::WinHelp((HWND) phi->hItemHandle, ContextHelpFile, HELP_WM_HELP, (DWORD_PTR) &HelpMap);
  1011. }
  1012. else
  1013. {
  1014. IDCsToIDHs HelpMap[]={{IDC_WORKINGSET_FRAME, HELP_PROC_WS_FRAME },
  1015. {IDC_WORKINGSET_CHK, HELP_PROC_WS_APPLY },
  1016. {IDC_MINWS, HELP_PROC_WS_MIN },
  1017. {IDC_MINWS_SPIN, HELP_PROC_WS_MIN_SPIN},
  1018. {IDC_MAXWS, HELP_PROC_WS_MAX},
  1019. {IDC_MAXWS_SPIN, HELP_PROC_WS_MAX_SPIN },
  1020. {0,0} };
  1021. ::WinHelp((HWND) phi->hItemHandle, ContextHelpFile, HELP_WM_HELP, (DWORD_PTR) &HelpMap);
  1022. }
  1023. return TRUE;
  1024. }
  1025. bHandled = FALSE;
  1026. return FALSE;
  1027. }
  1028. BOOL CMGMTMemoryPage::OnHelp()
  1029. {
  1030. TCHAR *pTopic = const_cast<TCHAR*>(HELP_ru_workset);
  1031. if (m_pJobContainer)
  1032. pTopic = const_cast<TCHAR*>(HELP_ru_job_mem);
  1033. MMCPropertyHelp(pTopic);
  1034. return TRUE;
  1035. }
  1036. BOOL CMGMTMemoryPage::Validate(BOOL bSave)
  1037. {
  1038. LONG_PTR PosErr = 0;
  1039. MEMORY_VALUE minWS;
  1040. MEMORY_VALUE maxWS;
  1041. MEMORY_VALUE procmemorylimit;
  1042. MEMORY_VALUE jobmemorylimit;
  1043. BOOL WSchk = (BST_CHECKED == IsDlgButtonChecked(IDC_WORKINGSET_CHK));
  1044. minWS = SendDlgItemMessage(IDC_MINWS_SPIN, UDM_GETPOS32, 0, (LPARAM) &PosErr);
  1045. if (PosErr || minWS > MAXLONG - 1 || (WSchk && minWS <= 0) )
  1046. {
  1047. HWND hWndCtl = GetDlgItem(IDC_MINWS);
  1048. if(hWndCtl)
  1049. ::SetFocus(hWndCtl);
  1050. ITEM_STR strOut;
  1051. LoadStringHelper(strOut, IDS_WSMINMAX_WARNING);
  1052. MessageBox(strOut, NULL, MB_OK | MB_ICONWARNING);
  1053. return FALSE;
  1054. }
  1055. maxWS = SendDlgItemMessage(IDC_MAXWS_SPIN, UDM_GETPOS32, 0, (LPARAM) &PosErr);
  1056. if (PosErr || maxWS > MAXLONG - 1 || (WSchk && minWS >= maxWS) )
  1057. {
  1058. HWND hWndCtl = GetDlgItem(IDC_MAXWS);
  1059. if(hWndCtl)
  1060. ::SetFocus(hWndCtl);
  1061. ITEM_STR strOut;
  1062. LoadStringHelper(strOut, IDS_WSMINMAX_WARNING);
  1063. MessageBox(strOut, NULL, MB_OK | MB_ICONWARNING);
  1064. return FALSE;
  1065. }
  1066. if (m_pJobContainer)
  1067. {
  1068. procmemorylimit = SendDlgItemMessage(IDC_PROC_SPIN, UDM_GETPOS32, 0, (LPARAM) &PosErr);
  1069. if (PosErr || procmemorylimit > MAXLONG - 1 )
  1070. {
  1071. HWND hWndCtl = GetDlgItem(IDC_PROCMEMORY);
  1072. if(hWndCtl)
  1073. ::SetFocus(hWndCtl);
  1074. MessageBeep(MB_ICONASTERISK);
  1075. return FALSE;
  1076. }
  1077. jobmemorylimit = SendDlgItemMessage(IDC_JOB_SPIN, UDM_GETPOS32, 0, (LPARAM) &PosErr);
  1078. if (PosErr || jobmemorylimit > MAXLONG - 1 )
  1079. {
  1080. HWND hWndCtl = GetDlgItem(IDC_JOBMEMORY);
  1081. if(hWndCtl)
  1082. ::SetFocus(hWndCtl);
  1083. MessageBeep(MB_ICONASTERISK);
  1084. return FALSE;
  1085. }
  1086. }
  1087. if (bSave)
  1088. {
  1089. if (m_pProcContainer)
  1090. {
  1091. SetMGMTFlag(m_pProcContainer->m_new.base.mgmtParms.mFlags, PCMFLAG_APPLY_WS_MINMAX, WSchk);
  1092. m_pProcContainer->m_new.base.mgmtParms.minWS = minWS * 1024;
  1093. m_pProcContainer->m_new.base.mgmtParms.maxWS = maxWS * 1024;
  1094. }
  1095. else if (m_pJobContainer)
  1096. {
  1097. SetMGMTFlag(m_pJobContainer->m_new.base.mgmtParms.mFlags, PCMFLAG_APPLY_WS_MINMAX, WSchk);
  1098. m_pJobContainer->m_new.base.mgmtParms.minWS = minWS * 1024;
  1099. m_pJobContainer->m_new.base.mgmtParms.maxWS = maxWS * 1024;
  1100. m_procmemorylimitchk = (BST_CHECKED == IsDlgButtonChecked(IDC_PROCMEMORY_CHK));
  1101. m_procmemorylimit = procmemorylimit * 1024;
  1102. m_jobmemorylimitchk = (BST_CHECKED == IsDlgButtonChecked(IDC_JOBMEMORY_CHK));
  1103. m_jobmemorylimit = jobmemorylimit * 1024;
  1104. SetMGMTFlag(m_pJobContainer->m_new.base.mgmtParms.mFlags, PCMFLAG_APPLY_PROC_MEMORY_LIMIT, (BST_CHECKED == IsDlgButtonChecked(IDC_PROCMEMORY_CHK)));
  1105. m_pJobContainer->m_new.base.mgmtParms.procMemoryLimit = procmemorylimit * 1024;
  1106. SetMGMTFlag(m_pJobContainer->m_new.base.mgmtParms.mFlags, PCMFLAG_APPLY_JOB_MEMORY_LIMIT, (BST_CHECKED == IsDlgButtonChecked(IDC_JOBMEMORY_CHK)));
  1107. m_pJobContainer->m_new.base.mgmtParms.jobMemoryLimit = jobmemorylimit * 1024;
  1108. }
  1109. }
  1110. return TRUE;
  1111. }
  1112. BOOL CMGMTMemoryPage::UpdateData(BOOL bSaveAndValidate)
  1113. {
  1114. if (bSaveAndValidate)
  1115. {
  1116. return Validate(TRUE);
  1117. }
  1118. else
  1119. {
  1120. if ( m_minWS/1024 > (MAXLONG - 1) ||
  1121. m_maxWS/1024 > (MAXLONG - 1) ||
  1122. m_procmemorylimit/1024 > (MAXLONG - 1) ||
  1123. m_jobmemorylimit/1024 > (MAXLONG - 1) )
  1124. m_bReadOnly = TRUE;
  1125. long minWSInK = (long) (m_minWS/1024);
  1126. long maxWSInK = (long) (m_maxWS/1024);
  1127. CheckDlgButton(IDC_WORKINGSET_CHK, m_WSchk ? BST_CHECKED : BST_UNCHECKED);
  1128. SendDlgItemMessage(IDC_MINWS_SPIN, UDM_SETRANGE32, 0, MAXLONG - 1 );
  1129. SendDlgItemMessage(IDC_MINWS_SPIN, UDM_SETPOS32, 0, minWSInK );
  1130. SendDlgItemMessage(IDC_MAXWS_SPIN, UDM_SETRANGE32, 0, MAXLONG - 1);
  1131. SendDlgItemMessage(IDC_MAXWS_SPIN, UDM_SETPOS32, 0, maxWSInK );
  1132. if (m_pJobContainer)
  1133. {
  1134. long ProcMemInK = (long) (m_procmemorylimit/1024);
  1135. long JobMemInK = (long) (m_jobmemorylimit/1024);
  1136. CheckDlgButton(IDC_PROCMEMORY_CHK, m_procmemorylimitchk ? BST_CHECKED : BST_UNCHECKED);
  1137. SendDlgItemMessage(IDC_PROC_SPIN, UDM_SETRANGE32, 0, MAXLONG - 1);
  1138. SendDlgItemMessage(IDC_PROC_SPIN, UDM_SETPOS32, 0, ProcMemInK );
  1139. CheckDlgButton(IDC_JOBMEMORY_CHK, m_jobmemorylimitchk ? BST_CHECKED : BST_UNCHECKED);
  1140. SendDlgItemMessage(IDC_JOB_SPIN, UDM_SETRANGE32, 0, MAXLONG - 1);
  1141. SendDlgItemMessage(IDC_JOB_SPIN, UDM_SETPOS32, 0, JobMemInK );
  1142. }
  1143. if (m_pProcContainer)
  1144. {
  1145. UINT nIDs[] = { IDC_PROCMEM_FRM, IDC_PROCMEMORY_CHK, IDC_PROCMEM_LBL, IDC_PROCMEMORY, IDC_PROC_SPIN, IDC_JOBMEM_FRM, IDC_JOBMEMORY_CHK, IDC_JOBMEM_LBL, IDC_JOBMEMORY, IDC_JOB_SPIN };
  1146. for (int i = 0; i < ARRAY_SIZE(nIDs); i++ )
  1147. {
  1148. HWND hWndCtl = GetDlgItem(nIDs[i]);
  1149. if(hWndCtl)
  1150. ::ShowWindow(hWndCtl, SW_HIDE);
  1151. }
  1152. }
  1153. ApplyControlEnableRules(FALSE);
  1154. if (m_bReadOnly || !m_procmemorylimitchk)
  1155. DisableControl(IDC_PROCMEMORY);
  1156. if (m_bReadOnly || !m_jobmemorylimitchk)
  1157. DisableControl(IDC_JOBMEMORY);
  1158. if (m_bReadOnly)
  1159. {
  1160. DisableControl(IDC_PROCMEMORY_CHK);
  1161. DisableControl(IDC_JOBMEMORY_CHK);
  1162. }
  1163. return TRUE;
  1164. }
  1165. }
  1166. void CMGMTMemoryPage::ApplyControlEnableRules(BOOL bForceDisable)
  1167. {
  1168. BOOL bEnable;
  1169. if (m_bReadOnly || !(BST_CHECKED == IsDlgButtonChecked(IDC_WORKINGSET_CHK)) || bForceDisable)
  1170. bEnable = FALSE;
  1171. else
  1172. bEnable = TRUE;
  1173. UINT ids[] = { IDC_MINWS, IDC_MAXWS, IDC_MINWS_SPIN, IDC_MAXWS_SPIN };
  1174. for (int i = 0; i < ARRAY_SIZE(ids); i++)
  1175. ::EnableWindow(GetDlgItem(ids[i]), bEnable);
  1176. ::EnableWindow(GetDlgItem(IDC_WORKINGSET_CHK), !(m_bReadOnly || bForceDisable));
  1177. }
  1178. BOOL CMGMTMemoryPage::OnSetActive()
  1179. {
  1180. if ( m_pProcContainer )
  1181. {
  1182. if (m_pProcContainer->m_new.base.mgmtParms.mFlags & PCMFLAG_APPLY_JOB_MEMBERSHIP)
  1183. ApplyControlEnableRules(TRUE);
  1184. else
  1185. ApplyControlEnableRules(FALSE);
  1186. }
  1187. return TRUE;
  1188. }
  1189. LRESULT CMGMTMemoryPage::OnSpin(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  1190. {
  1191. if (idCtrl == IDC_MINWS_SPIN ||
  1192. idCtrl == IDC_MAXWS_SPIN ||
  1193. idCtrl == IDC_PROC_SPIN ||
  1194. idCtrl == IDC_JOB_SPIN )
  1195. {
  1196. NMUPDOWN * nmupdown = (NMUPDOWN *) pnmh;
  1197. __int64 value = (__int64) nmupdown->iPos + 1024 * (__int64) nmupdown->iDelta;
  1198. if ( value <= MAXLONG - 1 )
  1199. nmupdown->iDelta *= 1024;
  1200. }
  1201. bHandled = FALSE;
  1202. return 0;
  1203. }
  1204. LRESULT CMGMTMemoryPage::OnEditChange(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  1205. {
  1206. LONG_PTR PosErr = 0;
  1207. LRESULT pos;
  1208. if (wID == IDC_MINWS)
  1209. {
  1210. PageFields.Fields.minWS = FALSE;
  1211. pos = SendDlgItemMessage(IDC_MINWS_SPIN, UDM_GETPOS32, 0,(LPARAM) &PosErr);
  1212. if (!PosErr && pos <= MAXLONG - 1)
  1213. PageFields.Fields.minWS = (m_minWS != pos * 1024 );
  1214. pos = SendDlgItemMessage(IDC_MINWS_SPIN, UDM_GETPOS32, 0, (LPARAM) &PosErr);
  1215. }
  1216. else if (wID == IDC_MAXWS)
  1217. {
  1218. PageFields.Fields.maxWS = FALSE;
  1219. pos = SendDlgItemMessage(IDC_MAXWS_SPIN, UDM_GETPOS32, 0,(LPARAM) &PosErr);
  1220. if (!PosErr && pos <= MAXLONG - 1 )
  1221. PageFields.Fields.maxWS = (m_maxWS != pos * 1024);
  1222. }
  1223. else if (wID == IDC_PROCMEMORY)
  1224. {
  1225. PageFields.Fields.procmemorylimit = FALSE;
  1226. pos = SendDlgItemMessage(IDC_PROC_SPIN, UDM_GETPOS32, 0,(LPARAM) &PosErr);
  1227. if (!PosErr && pos <= MAXLONG - 1)
  1228. PageFields.Fields.procmemorylimit = (m_procmemorylimit != pos * 1024);
  1229. }
  1230. else if (wID == IDC_JOBMEMORY)
  1231. {
  1232. PageFields.Fields.jobmemorylimit = FALSE;
  1233. pos = SendDlgItemMessage(IDC_JOB_SPIN, UDM_GETPOS32, 0,(LPARAM) &PosErr);
  1234. if (!PosErr && pos <= MAXLONG - 1)
  1235. PageFields.Fields.jobmemorylimit = (m_jobmemorylimit != pos * 1024);
  1236. }
  1237. SetModified(PageFields.on);
  1238. bHandled = FALSE;
  1239. return 0;
  1240. }
  1241. LRESULT CMGMTMemoryPage::OnChk(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  1242. {
  1243. if (wID == IDC_WORKINGSET_CHK)
  1244. {
  1245. bool checked = (BST_CHECKED == IsDlgButtonChecked(IDC_WORKINGSET_CHK));
  1246. PageFields.Fields.WSchk = (m_WSchk != checked);
  1247. ::EnableWindow(GetDlgItem(IDC_MINWS), checked);
  1248. ::EnableWindow(GetDlgItem(IDC_MAXWS), checked);
  1249. ::EnableWindow(GetDlgItem(IDC_MINWS_SPIN), checked);
  1250. ::EnableWindow(GetDlgItem(IDC_MAXWS_SPIN), checked);
  1251. SetModified(PageFields.on);
  1252. }
  1253. else if (wID == IDC_PROCMEMORY_CHK)
  1254. {
  1255. bool checked = (BST_CHECKED == IsDlgButtonChecked(IDC_PROCMEMORY_CHK));
  1256. PageFields.Fields.procmemorylimitchk = (m_procmemorylimitchk != checked);
  1257. ::EnableWindow(GetDlgItem(IDC_PROCMEMORY), checked);
  1258. ::EnableWindow(GetDlgItem(IDC_PROC_SPIN), checked);
  1259. SetModified(PageFields.on);
  1260. }
  1261. else if (wID == IDC_JOBMEMORY_CHK)
  1262. {
  1263. bool checked = (BST_CHECKED == IsDlgButtonChecked(IDC_JOBMEMORY_CHK));
  1264. PageFields.Fields.jobmemorylimitchk = (m_jobmemorylimitchk != checked);
  1265. ::EnableWindow(GetDlgItem(IDC_JOBMEMORY), checked);
  1266. ::EnableWindow(GetDlgItem(IDC_JOB_SPIN), checked);
  1267. SetModified(PageFields.on);
  1268. }
  1269. bHandled = FALSE;
  1270. return 0;
  1271. }
  1272. BOOL CMGMTMemoryPage::OnApply()
  1273. {
  1274. if (m_bReadOnly || !PageFields.on) // read only, nothing modified
  1275. return TRUE;
  1276. if ( (m_pProcContainer && m_pProcContainer->Apply(GetParent())) ||
  1277. (m_pJobContainer && m_pJobContainer->Apply( GetParent())) )
  1278. {
  1279. PageFields.on = 0;
  1280. if (m_pProcContainer)
  1281. {
  1282. m_WSchk = m_pProcContainer->m_new.base.mgmtParms.mFlags & PCMFLAG_APPLY_WS_MINMAX;
  1283. m_minWS = m_pProcContainer->m_new.base.mgmtParms.minWS;
  1284. m_maxWS = m_pProcContainer->m_new.base.mgmtParms.maxWS;
  1285. }
  1286. else if (m_pJobContainer)
  1287. {
  1288. m_WSchk = m_pJobContainer->m_new.base.mgmtParms.mFlags & PCMFLAG_APPLY_WS_MINMAX;
  1289. m_minWS = m_pJobContainer->m_new.base.mgmtParms.minWS;
  1290. m_maxWS = m_pJobContainer->m_new.base.mgmtParms.maxWS;
  1291. m_procmemorylimitchk = m_pJobContainer->m_new.base.mgmtParms.mFlags & PCMFLAG_APPLY_PROC_MEMORY_LIMIT;
  1292. m_procmemorylimit = m_pJobContainer->m_new.base.mgmtParms.procMemoryLimit;
  1293. m_jobmemorylimitchk = m_pJobContainer->m_new.base.mgmtParms.mFlags & PCMFLAG_APPLY_JOB_MEMORY_LIMIT;
  1294. m_jobmemorylimit = m_pJobContainer->m_new.base.mgmtParms.jobMemoryLimit;
  1295. }
  1296. return TRUE;
  1297. }
  1298. return FALSE;
  1299. }
  1300. ///////////////////////////////////////////////////////////////////////////
  1301. // Time Limits Page Implementation
  1302. CMGMTTimePage::CMGMTTimePage(int nTitle, CJobDetailContainer *pContainer) :
  1303. CMySnapInPropertyPageImpl<CMGMTTimePage>(nTitle),
  1304. m_pJobContainer(pContainer)
  1305. {
  1306. ASSERT(sizeof(PageFields.on) == sizeof(PageFields));
  1307. PageFields.on = 0;
  1308. m_bReadOnly = FALSE;
  1309. m_procusertimechk = FALSE;
  1310. m_procusertime = 0;
  1311. m_jobusertimechk = FALSE;
  1312. m_jobmsgontimelimit = FALSE;
  1313. m_jobusertime = 0;
  1314. m_psp.dwFlags |= PSP_HASHELP;
  1315. m_pJobContainer->AddRef();
  1316. }
  1317. CMGMTTimePage::~CMGMTTimePage()
  1318. {
  1319. m_pJobContainer->Release();
  1320. }
  1321. LRESULT CMGMTTimePage::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1322. {
  1323. UpdateData(FALSE);
  1324. bHandled = FALSE;
  1325. return TRUE; // Let the system set the focus
  1326. }
  1327. LRESULT CMGMTTimePage::OnWMHelp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1328. {
  1329. HELPINFO *phi = (HELPINFO*) lParam;
  1330. if (phi && phi->iContextType == HELPINFO_WINDOW)
  1331. {
  1332. IDCsToIDHs HelpMap[]={{IDC_PROCUSERTIME_FRAME, HELP_TIME_PROC_FRAME },
  1333. {IDC_PROCUSERTIME_CHK, HELP_TIME_PROC_APPLY },
  1334. {IDC_PROCUSERTIME, HELP_TIME_PROC_MAX },
  1335. {IDC_JOBUSERTIME_FRAME, HELP_TIME_GRP_FRAME},
  1336. {IDC_JOBUSERTIME_CHK, HELP_TIME_GRP_APPLY },
  1337. {IDC_JOBUSERTIME, HELP_TIME_GRP_MAX },
  1338. {IDC_JOBTIMELIMIT_TERM, HELP_TIME_GRP_TERMINATE },
  1339. {IDC_JOBTIMELIMIT_MSG, HELP_TIME_GRP_LOG },
  1340. {0,0} };
  1341. ::WinHelp((HWND) phi->hItemHandle, ContextHelpFile, HELP_WM_HELP, (DWORD_PTR) &HelpMap);
  1342. return TRUE;
  1343. }
  1344. bHandled = FALSE;
  1345. return FALSE;
  1346. }
  1347. BOOL CMGMTTimePage::OnHelp()
  1348. {
  1349. MMCPropertyHelp(const_cast<TCHAR*>(HELP_ru_job_time));
  1350. return TRUE;
  1351. }
  1352. BOOL CMGMTTimePage::Validate(BOOL bSave)
  1353. {
  1354. TIME_VALUE procusertime;
  1355. TIME_VALUE jobusertime;
  1356. bool procusertimechk = (BST_CHECKED == IsDlgButtonChecked(IDC_PROCUSERTIME_CHK));
  1357. bool jobusertimechk = (BST_CHECKED == IsDlgButtonChecked(IDC_JOBUSERTIME_CHK));
  1358. if ( !ValidateTimeField(m_hWnd, IDC_PROCUSERTIME, procusertime) ||
  1359. (procusertimechk && procusertime < PC_MIN_TIME_LIMIT) )
  1360. {
  1361. HWND hWndCtl = GetDlgItem(IDC_PROCUSERTIME);
  1362. if(hWndCtl)
  1363. ::SetFocus(hWndCtl);
  1364. MessageBeep(MB_ICONASTERISK);
  1365. CComBSTR bTemp;
  1366. if (bTemp.LoadString(IDS_TIMEENTRY))
  1367. MessageBox(bTemp.m_str, NULL, MB_OK | MB_ICONWARNING);
  1368. return FALSE;
  1369. }
  1370. if ( !ValidateTimeField(m_hWnd, IDC_JOBUSERTIME, jobusertime) ||
  1371. (jobusertimechk && jobusertime < PC_MIN_TIME_LIMIT) )
  1372. {
  1373. HWND hWndCtl = GetDlgItem(IDC_JOBUSERTIME);
  1374. if(hWndCtl)
  1375. ::SetFocus(hWndCtl);
  1376. MessageBeep(MB_ICONASTERISK);
  1377. CComBSTR bTemp;
  1378. if (bTemp.LoadString(IDS_TIMEENTRY))
  1379. MessageBox(bTemp.m_str, NULL, MB_OK | MB_ICONWARNING);
  1380. return FALSE;
  1381. }
  1382. if (bSave)
  1383. {
  1384. m_pJobContainer->m_new.base.mgmtParms.procTimeLimitCNS = procusertime;
  1385. SetMGMTFlag(m_pJobContainer->m_new.base.mgmtParms.mFlags, PCMFLAG_APPLY_PROC_TIME_LIMIT, procusertimechk);
  1386. m_pJobContainer->m_new.base.mgmtParms.jobTimeLimitCNS = jobusertime;
  1387. SetMGMTFlag(m_pJobContainer->m_new.base.mgmtParms.mFlags, PCMFLAG_APPLY_JOB_TIME_LIMIT, jobusertimechk);
  1388. SetMGMTFlag(m_pJobContainer->m_new.base.mgmtParms.mFlags, PCMFLAG_MSG_ON_JOB_TIME_LIMIT_HIT, (BST_CHECKED == IsDlgButtonChecked(IDC_JOBTIMELIMIT_MSG)));
  1389. }
  1390. return TRUE;
  1391. }
  1392. BOOL CMGMTTimePage::UpdateData(BOOL bSaveAndValidate)
  1393. {
  1394. if (bSaveAndValidate)
  1395. {
  1396. return Validate(TRUE);
  1397. }
  1398. else
  1399. {
  1400. ITEM_STR str;
  1401. CheckDlgButton(IDC_PROCUSERTIME_CHK, m_procusertimechk ? BST_CHECKED : BST_UNCHECKED);
  1402. SetDlgItemText(IDC_PROCUSERTIME, FormatCNSTime(str, m_procusertime));
  1403. CheckDlgButton(IDC_JOBUSERTIME_CHK, m_jobusertimechk ? BST_CHECKED : BST_UNCHECKED);
  1404. SetDlgItemText(IDC_JOBUSERTIME, FormatCNSTime(str, m_jobusertime));
  1405. ASSERT(IDC_JOBTIMELIMIT_TERM + 1 == IDC_JOBTIMELIMIT_MSG);
  1406. CheckRadioButton(IDC_JOBTIMELIMIT_TERM, IDC_JOBTIMELIMIT_MSG, m_jobmsgontimelimit ? IDC_JOBTIMELIMIT_MSG : IDC_JOBTIMELIMIT_TERM );
  1407. if (m_bReadOnly || !m_procusertimechk)
  1408. DisableControl(IDC_PROCUSERTIME);
  1409. if (m_bReadOnly || !m_jobusertimechk)
  1410. {
  1411. DisableControl(IDC_JOBUSERTIME);
  1412. DisableControl(IDC_JOBTIMELIMIT_TERM);
  1413. DisableControl(IDC_JOBTIMELIMIT_MSG);
  1414. }
  1415. if (m_bReadOnly)
  1416. {
  1417. DisableControl(IDC_PROCUSERTIME_CHK);
  1418. DisableControl(IDC_JOBUSERTIME_CHK);
  1419. }
  1420. return TRUE;
  1421. }
  1422. }
  1423. LRESULT CMGMTTimePage::OnEditChange(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  1424. {
  1425. TIME_VALUE time;
  1426. if (wID == IDC_PROCUSERTIME)
  1427. {
  1428. PageFields.Fields.procusertime = FALSE;
  1429. if ( ValidateTimeField(m_hWnd, wID, time) )
  1430. PageFields.Fields.procusertime = (m_procusertime != time);
  1431. }
  1432. else if (wID == IDC_JOBUSERTIME)
  1433. {
  1434. PageFields.Fields.jobusertime = FALSE;
  1435. if ( ValidateTimeField(m_hWnd, wID, time) )
  1436. PageFields.Fields.jobusertime = (m_jobusertime != time);
  1437. }
  1438. SetModified(PageFields.on);
  1439. bHandled = FALSE;
  1440. return 0;
  1441. }
  1442. LRESULT CMGMTTimePage::OnChk(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  1443. {
  1444. if (wID == IDC_PROCUSERTIME_CHK)
  1445. {
  1446. bool checked = (BST_CHECKED == IsDlgButtonChecked(IDC_PROCUSERTIME_CHK));
  1447. PageFields.Fields.procusertimechk = (m_procusertimechk != checked);
  1448. ::EnableWindow(GetDlgItem(IDC_PROCUSERTIME), checked);
  1449. SetModified(PageFields.on);
  1450. }
  1451. else if (wID == IDC_JOBUSERTIME_CHK)
  1452. {
  1453. bool checked = (BST_CHECKED == IsDlgButtonChecked(IDC_JOBUSERTIME_CHK));
  1454. PageFields.Fields.jobusertimechk = (m_jobusertimechk != checked);
  1455. ::EnableWindow(GetDlgItem(IDC_JOBUSERTIME), checked);
  1456. ::EnableWindow(GetDlgItem(IDC_JOBTIMELIMIT_TERM), checked);
  1457. ::EnableWindow(GetDlgItem(IDC_JOBTIMELIMIT_MSG), checked);
  1458. SetModified(PageFields.on);
  1459. }
  1460. else if (wID == IDC_JOBTIMELIMIT_TERM)
  1461. {
  1462. bool checked = !(BST_CHECKED == IsDlgButtonChecked(IDC_JOBTIMELIMIT_TERM));
  1463. PageFields.Fields.jobmsgontimelimit = (m_jobmsgontimelimit != checked);
  1464. SetModified(PageFields.on);
  1465. }
  1466. else if (wID == IDC_JOBTIMELIMIT_MSG)
  1467. {
  1468. bool checked = (BST_CHECKED == IsDlgButtonChecked(IDC_JOBTIMELIMIT_MSG));
  1469. PageFields.Fields.jobmsgontimelimit = (m_jobmsgontimelimit != checked);
  1470. SetModified(PageFields.on);
  1471. }
  1472. bHandled = FALSE;
  1473. return 0;
  1474. }
  1475. BOOL CMGMTTimePage::OnApply()
  1476. {
  1477. if (m_bReadOnly || !PageFields.on) // read only, nothing modified
  1478. return TRUE;
  1479. if (m_pJobContainer->Apply(GetParent()) )
  1480. {
  1481. PageFields.on = 0;
  1482. m_procusertime = m_pJobContainer->m_new.base.mgmtParms.procTimeLimitCNS;
  1483. m_procusertimechk = m_pJobContainer->m_new.base.mgmtParms.mFlags & PCMFLAG_APPLY_PROC_TIME_LIMIT;
  1484. m_jobusertime = m_pJobContainer->m_new.base.mgmtParms.jobTimeLimitCNS;
  1485. m_jobusertimechk = m_pJobContainer->m_new.base.mgmtParms.mFlags & PCMFLAG_APPLY_JOB_TIME_LIMIT;
  1486. m_jobmsgontimelimit = m_pJobContainer->m_new.base.mgmtParms.mFlags & PCMFLAG_MSG_ON_JOB_TIME_LIMIT_HIT;
  1487. return TRUE;
  1488. }
  1489. return FALSE;
  1490. }
  1491. ///////////////////////////////////////////////////////////////////////////
  1492. // Advanced Page Implementation
  1493. CMGMTAdvancedPage::CMGMTAdvancedPage(int nTitle, CJobDetailContainer *pContainer) :
  1494. CMySnapInPropertyPageImpl<CMGMTAdvancedPage>(nTitle),
  1495. m_pJobContainer(pContainer)
  1496. {
  1497. ASSERT(sizeof(PageFields.on) == sizeof(PageFields));
  1498. PageFields.on = 0;
  1499. m_bReadOnly = FALSE;
  1500. m_endjob = FALSE;
  1501. m_unhandledexcept = FALSE;
  1502. m_breakaway = FALSE;
  1503. m_silentbreakaway = FALSE;
  1504. m_psp.dwFlags |= PSP_HASHELP;
  1505. m_pJobContainer->AddRef();
  1506. }
  1507. CMGMTAdvancedPage::~CMGMTAdvancedPage()
  1508. {
  1509. m_pJobContainer->Release();
  1510. }
  1511. LRESULT CMGMTAdvancedPage::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1512. {
  1513. UpdateData(FALSE);
  1514. bHandled = FALSE;
  1515. // Setting focus when a property page does not work...
  1516. return TRUE; // Let the system set the focus
  1517. }
  1518. LRESULT CMGMTAdvancedPage::OnWMHelp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1519. {
  1520. HELPINFO *phi = (HELPINFO*) lParam;
  1521. if (phi && phi->iContextType == HELPINFO_WINDOW)
  1522. {
  1523. IDCsToIDHs HelpMap[]={{IDC_ADV_FRAME, HELP_ADV_FRAME },
  1524. {IDC_ENDJOB_CHK, HELP_ADV_ENDGRP },
  1525. {IDC_UNHANDLEDEXCEPT_CHK, HELP_ADV_NODIEONEX },
  1526. {IDC_SILENTBREAKAWAY_CHK, HELP_ADV_SILENT_BREAKAWAY},
  1527. {IDC_BREAKAWAY_CHK, HELP_ADV_BREAKAWAY_OK },
  1528. {0,0} };
  1529. ::WinHelp((HWND) phi->hItemHandle, ContextHelpFile, HELP_WM_HELP, (DWORD_PTR) &HelpMap);
  1530. return TRUE;
  1531. }
  1532. bHandled = FALSE;
  1533. return FALSE;
  1534. }
  1535. BOOL CMGMTAdvancedPage::OnHelp()
  1536. {
  1537. MMCPropertyHelp(const_cast<TCHAR*>(HELP_ru_job_adv));
  1538. return TRUE;
  1539. }
  1540. BOOL CMGMTAdvancedPage::Validate(BOOL bSave)
  1541. {
  1542. if (bSave)
  1543. {
  1544. SetMGMTFlag(m_pJobContainer->m_new.base.mgmtParms.mFlags, PCMFLAG_END_JOB_WHEN_EMPTY, (BST_CHECKED == IsDlgButtonChecked(IDC_ENDJOB_CHK)));
  1545. SetMGMTFlag(m_pJobContainer->m_new.base.mgmtParms.mFlags, PCMFLAG_SET_DIE_ON_UH_EXCEPTION, (BST_CHECKED == IsDlgButtonChecked(IDC_UNHANDLEDEXCEPT_CHK)));
  1546. SetMGMTFlag(m_pJobContainer->m_new.base.mgmtParms.mFlags, PCMFLAG_SET_PROC_BREAKAWAY_OK, (BST_CHECKED == IsDlgButtonChecked(IDC_BREAKAWAY_CHK )));
  1547. SetMGMTFlag(m_pJobContainer->m_new.base.mgmtParms.mFlags, PCMFLAG_SET_SILENT_BREAKAWAY, (BST_CHECKED == IsDlgButtonChecked(IDC_SILENTBREAKAWAY_CHK)));
  1548. }
  1549. return TRUE;
  1550. }
  1551. BOOL CMGMTAdvancedPage::UpdateData(BOOL bSaveAndValidate)
  1552. {
  1553. if (bSaveAndValidate)
  1554. {
  1555. return Validate(TRUE);
  1556. }
  1557. else
  1558. {
  1559. CheckDlgButton(IDC_ENDJOB_CHK, m_endjob ? BST_CHECKED : BST_UNCHECKED);
  1560. CheckDlgButton(IDC_UNHANDLEDEXCEPT_CHK, m_unhandledexcept ? BST_CHECKED : BST_UNCHECKED);
  1561. CheckDlgButton(IDC_BREAKAWAY_CHK, m_breakaway ? BST_CHECKED : BST_UNCHECKED);
  1562. CheckDlgButton(IDC_SILENTBREAKAWAY_CHK, m_silentbreakaway ? BST_CHECKED : BST_UNCHECKED);
  1563. if (m_bReadOnly)
  1564. {
  1565. DisableControl(IDC_ENDJOB_CHK);
  1566. DisableControl(IDC_UNHANDLEDEXCEPT_CHK);
  1567. DisableControl(IDC_BREAKAWAY_CHK);
  1568. DisableControl(IDC_SILENTBREAKAWAY_CHK);
  1569. }
  1570. return TRUE;
  1571. }
  1572. }
  1573. LRESULT CMGMTAdvancedPage::OnChk(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  1574. {
  1575. if (wID == IDC_BREAKAWAY_CHK)
  1576. {
  1577. bool checked = (BST_CHECKED == IsDlgButtonChecked(IDC_BREAKAWAY_CHK));
  1578. PageFields.Fields.breakaway = (m_breakaway != checked);
  1579. SetModified(PageFields.on);
  1580. }
  1581. else if (wID == IDC_SILENTBREAKAWAY_CHK)
  1582. {
  1583. bool checked = (BST_CHECKED == IsDlgButtonChecked(IDC_SILENTBREAKAWAY_CHK));
  1584. PageFields.Fields.silentbreakaway = (m_silentbreakaway != checked);
  1585. SetModified(PageFields.on);
  1586. }
  1587. else if (wID == IDC_ENDJOB_CHK)
  1588. {
  1589. bool checked = (BST_CHECKED == IsDlgButtonChecked(IDC_ENDJOB_CHK));
  1590. PageFields.Fields.endjob = (m_endjob != checked);
  1591. SetModified(PageFields.on);
  1592. }
  1593. else if (wID == IDC_UNHANDLEDEXCEPT_CHK)
  1594. {
  1595. bool checked = (BST_CHECKED == IsDlgButtonChecked(IDC_UNHANDLEDEXCEPT_CHK));
  1596. PageFields.Fields.unhandledexcept = (m_unhandledexcept != checked);
  1597. SetModified(PageFields.on);
  1598. }
  1599. bHandled = FALSE;
  1600. return 0;
  1601. }
  1602. BOOL CMGMTAdvancedPage::OnApply()
  1603. {
  1604. if (m_bReadOnly || !PageFields.on)
  1605. return TRUE;
  1606. if (m_pJobContainer->Apply( GetParent() ))
  1607. {
  1608. PageFields.on = 0;
  1609. m_endjob = m_pJobContainer->m_new.base.mgmtParms.mFlags & PCMFLAG_END_JOB_WHEN_EMPTY;
  1610. m_unhandledexcept = m_pJobContainer->m_new.base.mgmtParms.mFlags & PCMFLAG_SET_DIE_ON_UH_EXCEPTION;
  1611. m_breakaway = m_pJobContainer->m_new.base.mgmtParms.mFlags & PCMFLAG_SET_PROC_BREAKAWAY_OK;
  1612. m_silentbreakaway = m_pJobContainer->m_new.base.mgmtParms.mFlags & PCMFLAG_SET_SILENT_BREAKAWAY;
  1613. return TRUE;
  1614. }
  1615. return FALSE;
  1616. }
  1617. #if _MSC_VER >= 1200
  1618. #pragma warning( pop )
  1619. #endif