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.

566 lines
16 KiB

  1. /*======================================================================================//
  2. | Process Control //
  3. | //
  4. |Copyright (c) 1998 Sequent Computer Systems, Incorporated. All rights reserved. //
  5. | //
  6. |File Name: ProcessPages.cpp //
  7. | //
  8. |Description: Implementation of Process pages //
  9. | //
  10. |Created: Paul Skoglund 08-1998 //
  11. | //
  12. |Rev History: //
  13. | //
  14. |=======================================================================================*/
  15. #include "stdafx.h"
  16. #include "ProcessPages.h"
  17. #include "ManagementRuleWizards.h"
  18. #include "ManagementPages.h" // helper functions
  19. using std::list<tstring>;
  20. static HRESULT ConstructProcDetailPropPages(LPPROPERTYSHEETCALLBACK lpProvider,
  21. CProcDetailContainer *pContainer,
  22. const PCProcDetail &ProcDetail,
  23. const PCSystemParms &SystemParms,
  24. PCid hID);
  25. #if _MSC_VER >= 1200
  26. #pragma warning( push )
  27. #endif
  28. #pragma warning( disable : 4800 ) //warning C4800: 'unsigned long' : forcing value to bool 'true' or 'false' (performance warning)
  29. CProcessIDPage::CProcessIDPage(int nTitle, CProcDetailContainer *pContainer, list<tstring> *jobnames) :
  30. CMySnapInPropertyPageImpl<CProcessIDPage>(nTitle),
  31. m_pProcContainer(pContainer), m_pJobNames(jobnames),
  32. m_bName(_T("")), m_bComment(_T("")), m_bJob(_T(""))
  33. {
  34. ASSERT(sizeof(PageFields.on) == sizeof(PageFields));
  35. PageFields.on = 0;
  36. m_bReadOnly = FALSE;
  37. m_JobChk = FALSE;
  38. m_psp.dwFlags |= PSP_HASHELP;
  39. m_pProcContainer->AddRef();
  40. }
  41. CProcessIDPage::~CProcessIDPage()
  42. {
  43. m_pProcContainer->Release();
  44. if (m_pJobNames)
  45. delete m_pJobNames;
  46. }
  47. LRESULT CProcessIDPage::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  48. {
  49. CComBSTR bTitle;
  50. PropSheet_SetTitle( GetParent(), PSH_PROPTITLE, FormatSheetTitle(bTitle, m_bName, m_pProcContainer->GetConnectionInfo()));
  51. UpdateData(FALSE);
  52. bHandled = FALSE;
  53. // Setting focus when a property page does not work...
  54. return TRUE; // Let the system set the focus
  55. }
  56. LRESULT CProcessIDPage::OnWMHelp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  57. {
  58. HELPINFO *phi = (HELPINFO*) lParam;
  59. if (phi && phi->iContextType == HELPINFO_WINDOW)
  60. {
  61. IDCsToIDHs HelpMap[] = {{IDC_NAME, HELP_PROCID_NAME},
  62. {IDC_COMMENT, HELP_PROCID_COMMENT},
  63. {IDC_APPLYGROUP_FRAME, HELP_PROCID_APPLYGROUP_FRAME},
  64. {IDC_JOBMEMBER_CHK, HELP_PROCID_APPLYGROUP_CHK},
  65. {IDC_JOB_LIST, HELP_PROCID_JOB_LIST},
  66. {0,0} };
  67. ::WinHelp((HWND) phi->hItemHandle, ContextHelpFile, HELP_WM_HELP, (DWORD_PTR) &HelpMap);
  68. return TRUE;
  69. }
  70. bHandled = FALSE;
  71. return FALSE;
  72. }
  73. BOOL CProcessIDPage::OnHelp()
  74. {
  75. MMCPropertyHelp(const_cast<TCHAR*>(HELP_ru_proc_name));
  76. return TRUE;
  77. }
  78. BOOL CProcessIDPage::Validate(BOOL bSave)
  79. {
  80. CComBSTR bName;
  81. CComBSTR bComment;
  82. CComBSTR bJob;
  83. bool bChecked = (BST_CHECKED == IsDlgButtonChecked(IDC_JOBMEMBER_CHK));
  84. if (!GetDlgItemText( IDC_NAME, bName.m_str ) ||
  85. !IsValidName(bName, FALSE) )
  86. {
  87. HWND hWndCtl = GetDlgItem(IDC_NAME);
  88. if(hWndCtl)
  89. ::SetFocus(hWndCtl);
  90. ITEM_STR strOut;
  91. LoadStringHelper(strOut, IDS_JOBNAME_WARNING);
  92. MessageBox(strOut, NULL, MB_OK | MB_ICONWARNING);
  93. return FALSE;
  94. }
  95. if (!GetDlgItemText(IDC_COMMENT, bComment.m_str))
  96. bComment = _T("");
  97. if (bComment.Length() > RULE_DESCRIPTION_LEN)
  98. {
  99. HWND hWndCtl = GetDlgItem(IDC_COMMENT);
  100. if(hWndCtl)
  101. ::SetFocus(hWndCtl);
  102. MessageBeep(MB_ICONASTERISK);
  103. return FALSE;
  104. }
  105. if (!GetDlgItemText( IDC_JOB_LIST, bJob.m_str) )
  106. bJob = _T("");
  107. if (!IsValidName(bJob, !bChecked))
  108. {
  109. HWND hWndCtl = NULL;
  110. if (bChecked)
  111. hWndCtl = GetDlgItem(IDC_JOB_LIST);
  112. else
  113. hWndCtl = GetDlgItem(IDC_JOBMEMBER_CHK);
  114. if(hWndCtl)
  115. ::SetFocus(hWndCtl);
  116. ITEM_STR strOut;
  117. LoadStringHelper(strOut, IDS_JOBNAME_WARNING);
  118. MessageBox(strOut, NULL, MB_OK | MB_ICONWARNING);
  119. return FALSE;
  120. }
  121. if (bSave)
  122. {
  123. // everything validated so save
  124. _tcscpy(m_pProcContainer->m_new.base.mgmtParms.description, bComment);
  125. _tcscpy(m_pProcContainer->m_new.base.memberOfJobName, bJob);
  126. SetMGMTFlag(m_pProcContainer->m_new.base.mgmtParms.mFlags, PCMFLAG_APPLY_JOB_MEMBERSHIP, bChecked);
  127. }
  128. return TRUE;
  129. }
  130. BOOL CProcessIDPage::UpdateData(BOOL bSaveAndValidate)
  131. {
  132. if (bSaveAndValidate)
  133. {
  134. return Validate(TRUE);
  135. }
  136. else
  137. {
  138. if (m_pJobNames)
  139. {
  140. list<tstring>::const_iterator i;
  141. for (i = (*m_pJobNames).begin(); i != (*m_pJobNames).end(); i++)
  142. SendDlgItemMessage(IDC_JOB_LIST, CB_ADDSTRING, 0, (LPARAM) (*i).c_str() );
  143. }
  144. VERIFY(SetDlgItemText( IDC_NAME, m_bName.m_str ));
  145. SendDlgItemMessage( IDC_NAME, EM_SETLIMITTEXT, PROC_NAME_LEN, 0);
  146. VERIFY(SetDlgItemText( IDC_COMMENT, m_bComment.m_str ));
  147. SendDlgItemMessage( IDC_COMMENT, EM_SETLIMITTEXT, RULE_DESCRIPTION_LEN, 0);
  148. VERIFY(SetDlgItemText( IDC_JOB_LIST, m_bJob.m_str ));
  149. SendDlgItemMessage( IDC_JOB_LIST, CB_LIMITTEXT, JOB_NAME_LEN, 0);
  150. DisableControl(IDC_NAME);
  151. CheckDlgButton(IDC_JOBMEMBER_CHK, m_JobChk ? BST_CHECKED : BST_UNCHECKED);
  152. if (m_bReadOnly || !m_JobChk)
  153. DisableControl(IDC_JOB_LIST);
  154. if (m_bReadOnly)
  155. {
  156. int ids[] = { IDC_NAME, IDC_COMMENT, IDC_JOBMEMBER_CHK, 0 };
  157. for (int i = 0; ids[i]; i++)
  158. DisableControl(i);
  159. }
  160. return TRUE;
  161. }
  162. }
  163. LRESULT CProcessIDPage::OnEditChange(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  164. {
  165. CComBSTR bStr;
  166. switch (wID) {
  167. case IDC_COMMENT:
  168. if (wNotifyCode == EN_CHANGE)
  169. {
  170. if (! GetDlgItemText(wID, bStr.m_str) )
  171. bStr = _T("");
  172. PageFields.Fields.comment = (0 != _tcscmp(bStr, m_bComment));
  173. SetModified(PageFields.on);
  174. }
  175. break;
  176. case IDC_JOB_LIST:
  177. if (wNotifyCode == CBN_EDITCHANGE)
  178. {
  179. // GetDlgItemText returns FALSE, and doesn't create an empty
  180. if (! GetDlgItemText(wID, bStr.m_str) )
  181. bStr = _T("");
  182. PageFields.Fields.jobName = (0 != _tcscmp(bStr, m_bJob));
  183. SetModified(PageFields.on);
  184. }
  185. // caution: CBN_CLOSEUP doesn't get sent when the curser keys are use
  186. else if (wNotifyCode == CBN_SELCHANGE)
  187. {
  188. LRESULT nSel = SendDlgItemMessage(IDC_JOB_LIST, CB_GETCURSEL, 0, 0);
  189. if (nSel >= 0 && CB_ERR != nSel)
  190. {
  191. TCHAR newjob[2*JOB_NAME_LEN+2];
  192. LRESULT nLen = SendDlgItemMessage(IDC_JOB_LIST, CB_GETLBTEXTLEN, nSel, 0);
  193. if (nLen > 0 && CB_ERR != nLen && nLen < (ARRAY_SIZE(newjob) -1) )
  194. {
  195. if ( SendDlgItemMessage(IDC_JOB_LIST, CB_GETLBTEXT, nSel, (LPARAM) &newjob) > 0)
  196. PageFields.Fields.jobName = (0 != _tcscmp(newjob, m_bJob));
  197. }
  198. }
  199. SetModified(PageFields.on);
  200. }
  201. break;
  202. default:
  203. break;
  204. }
  205. bHandled = FALSE;
  206. return 0;
  207. }
  208. LRESULT CProcessIDPage::OnJobChk(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  209. {
  210. if (wID == IDC_JOBMEMBER_CHK )
  211. {
  212. bool checked = (BST_CHECKED == IsDlgButtonChecked(IDC_JOBMEMBER_CHK));
  213. PageFields.Fields.jobChk = (m_JobChk != checked);
  214. ::EnableWindow(GetDlgItem(IDC_JOB_LIST), checked);
  215. SetModified(PageFields.on);
  216. }
  217. bHandled = FALSE;
  218. return 0;
  219. }
  220. BOOL CProcessIDPage::OnApply()
  221. {
  222. if (m_bReadOnly || !PageFields.on)
  223. return TRUE;
  224. if (m_pProcContainer->Apply( GetParent() ))
  225. {
  226. PageFields.on = 0;
  227. m_bComment = m_pProcContainer->m_new.base.mgmtParms.description;
  228. m_bJob = m_pProcContainer->m_new.base.memberOfJobName;
  229. m_JobChk = (m_pProcContainer->m_new.base.mgmtParms.mFlags & PCMFLAG_APPLY_JOB_MEMBERSHIP);
  230. return TRUE;
  231. }
  232. return FALSE;
  233. }
  234. ///////////////////////////////////////////////////////////////////////////
  235. // Unmanaged Procees Page Implementation
  236. CProcessUnmanagedPage::CProcessUnmanagedPage(int nTitle, CNewProcDetailContainer *pContainer, const PCSystemParms sysParms, list<tstring> *jobnames)
  237. : CMySnapInPropertyPageImpl<CProcessUnmanagedPage>(nTitle),
  238. m_pProcContainer(pContainer), m_SystemParms(sysParms), m_bName(_T("")), m_pJobNames(jobnames)
  239. {
  240. m_bReadOnly = FALSE;
  241. m_psp.dwFlags |= PSP_HASHELP;
  242. m_pProcContainer->AddRef();
  243. }
  244. CProcessUnmanagedPage::~CProcessUnmanagedPage()
  245. {
  246. if (m_pJobNames)
  247. delete m_pJobNames;
  248. m_pProcContainer->Release();
  249. }
  250. LRESULT CProcessUnmanagedPage::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  251. {
  252. CComBSTR bTitle;
  253. PropSheet_SetTitle( GetParent(), PSH_PROPTITLE, FormatSheetTitle(bTitle, m_bName, m_pProcContainer->GetConnectionInfo() ));
  254. UpdateData(FALSE);
  255. bHandled = FALSE;
  256. // Setting focus when a property page does not work...
  257. return TRUE; // Let the system set the focus
  258. }
  259. LRESULT CProcessUnmanagedPage::OnWMHelp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  260. {
  261. HELPINFO *phi = (HELPINFO*) lParam;
  262. if (phi && phi->iContextType == HELPINFO_WINDOW)
  263. {
  264. IDCsToIDHs HelpMap[] = {{IDC_NAME, HELP_PROCDEF_NAME},
  265. {IDC_ADD, HELP_PROCDEF_ADD},
  266. {0,0} };
  267. ::WinHelp((HWND) phi->hItemHandle, ContextHelpFile, HELP_WM_HELP, (DWORD_PTR) &HelpMap);
  268. return TRUE;
  269. }
  270. bHandled = FALSE;
  271. return FALSE;
  272. }
  273. BOOL CProcessUnmanagedPage::OnHelp()
  274. {
  275. MMCPropertyHelp(const_cast<TCHAR*>(HELP_ru_proc));
  276. return TRUE;
  277. }
  278. LRESULT CProcessUnmanagedPage::OnAdd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  279. {
  280. if (wNotifyCode != BN_CLICKED || wID != IDC_ADD)
  281. {
  282. bHandled = FALSE;
  283. return 1;
  284. }
  285. PCProcDetail ProcDetail = { 0 };
  286. PROC_NAME pname;
  287. _tcscpy(pname, m_bName);
  288. BOOL rc = FALSE;
  289. if ( m_pJobNames )
  290. rc = ProcRuleWizard(IDS_PRULE_DEFINE, *m_pJobNames, ProcDetail, m_SystemParms, &pname);
  291. else
  292. {
  293. list<tstring> jobs;
  294. rc = ProcRuleWizard(IDS_PRULE_DEFINE, jobs, ProcDetail, m_SystemParms, &pname);
  295. }
  296. if (rc)
  297. {
  298. m_pProcContainer->m_new = ProcDetail;
  299. ::PostMessage(GetParent(), PSM_PRESSBUTTON, (WPARAM) PSBTN_OK, 0);
  300. // post ad ok button press...
  301. }
  302. return 0;
  303. }
  304. BOOL CProcessUnmanagedPage::Validate(BOOL bSave)
  305. {
  306. return TRUE;
  307. }
  308. BOOL CProcessUnmanagedPage::UpdateData(BOOL bSaveAndValidate)
  309. {
  310. if (bSaveAndValidate)
  311. {
  312. return Validate(TRUE);
  313. }
  314. else
  315. {
  316. // SendDlgItemMessage( IDC_NAME, EM_SETLIMITTEXT, PROC_NAME_LEN, 0);
  317. VERIFY(SetDlgItemText( IDC_NAME, m_bName.m_str ));
  318. DisableControl(IDC_NAME);
  319. if (m_bReadOnly)
  320. {
  321. int ids[] = { IDC_ADD, 0 };
  322. for (int i = 0; ids[i]; i++)
  323. DisableControl(i);
  324. }
  325. return TRUE;
  326. }
  327. }
  328. BOOL CProcessUnmanagedPage::OnApply()
  329. {
  330. if (m_bReadOnly)
  331. return TRUE;
  332. if ( m_pProcContainer->Apply(GetParent()) )
  333. return TRUE;
  334. return FALSE;
  335. }
  336. // Property Page Helper functions...
  337. HRESULT CreatePropertyPagesForProcListItem( const PCProcListItem &ProcListItem,
  338. LPPROPERTYSHEETCALLBACK lpProvider,
  339. LONG_PTR handle,
  340. CBaseNode *BaseNodePtr )
  341. {
  342. if ( ProcListItem.lFlags & PCLFLAG_IS_DEFINED )
  343. {
  344. return CreatePropertyPagesForProcDetail(ProcListItem.procName, lpProvider, handle, BaseNodePtr);
  345. }
  346. PCid hID = BaseNodePtr->GetPCid();
  347. PCSystemInfo sysInfo;
  348. if (!hID ||
  349. !PCGetServiceInfo(hID, &sysInfo, sizeof(sysInfo)) )
  350. {
  351. BaseNodePtr->ReportPCError();
  352. return S_OK;
  353. }
  354. COMPUTER_CONNECTION_INFO ConnInfo;
  355. BaseNodePtr->GetComputerConnectionInfo(ConnInfo);
  356. PCProcDetail ProcDetail = { 0 };
  357. _tcscpy(ProcDetail.base.procName, ProcListItem.procName);
  358. CNewProcDetailContainer *pContainer = new CNewProcDetailContainer(ProcDetail, BaseNodePtr, handle, hID, ConnInfo, 0, FALSE, -1);
  359. if (pContainer)
  360. {
  361. CProcessUnmanagedPage *pPage = new CProcessUnmanagedPage(NULL, pContainer, sysInfo.sysParms, GetGrpNameList(hID));
  362. if (pPage)
  363. {
  364. pPage->m_bName = ProcListItem.procName;
  365. lpProvider->AddPage(pPage->Create());
  366. }
  367. pContainer->Release();
  368. pContainer = NULL;
  369. }
  370. return S_OK;
  371. }
  372. HRESULT CreatePropertyPagesForProcDetail( const PROC_NAME &procName,
  373. LPPROPERTYSHEETCALLBACK lpProvider,
  374. LONG_PTR handle,
  375. CBaseNode *BaseNodePtr )
  376. {
  377. PCid hID = BaseNodePtr->GetPCid();
  378. if (!hID)
  379. {
  380. BaseNodePtr->ReportPCError();
  381. return S_OK;
  382. }
  383. COMPUTER_CONNECTION_INFO ConnInfo;
  384. BaseNodePtr->GetComputerConnectionInfo(ConnInfo);
  385. PCSystemInfo sysInfo;
  386. list<tstring> jobs;
  387. PCProcDetail ProcDetail = { 0 };
  388. _tcscpy(ProcDetail.base.procName, procName);
  389. PCINT32 nUpdateCtr = 0;
  390. if (!PCGetProcDetail ( hID, &ProcDetail, sizeof(ProcDetail), &nUpdateCtr) ||
  391. !PCGetServiceInfo( hID, &sysInfo, sizeof(sysInfo)) ) // || !GetGrpNameList ( hID, jobs) )
  392. {
  393. BaseNodePtr->ReportPCError();
  394. return S_OK;
  395. }
  396. CProcDetailContainer *pContainer = new CProcDetailContainer(ProcDetail, BaseNodePtr, handle, hID, ConnInfo, nUpdateCtr, FALSE, -1);
  397. if (pContainer)
  398. {
  399. ConstructProcDetailPropPages(lpProvider, pContainer, ProcDetail, sysInfo.sysParms, hID);
  400. pContainer->Release();
  401. pContainer = NULL;
  402. }
  403. return S_OK;
  404. }
  405. HRESULT ConstructProcDetailPropPages(LPPROPERTYSHEETCALLBACK lpProvider,
  406. CProcDetailContainer *pContainer,
  407. const PCProcDetail &ProcDetail,
  408. const PCSystemParms &SystemParms,
  409. PCid hID)
  410. {
  411. CProcessIDPage *pPage = new CProcessIDPage(NULL, pContainer, GetGrpNameList(hID));
  412. if (pPage)
  413. {
  414. pPage->m_bName = ProcDetail.base.procName;
  415. pPage->m_bComment = ProcDetail.base.mgmtParms.description;
  416. pPage->m_JobChk = (ProcDetail.base.mgmtParms.mFlags & PCMFLAG_APPLY_JOB_MEMBERSHIP);
  417. pPage->m_bJob = ProcDetail.base.memberOfJobName;
  418. lpProvider->AddPage(pPage->Create());
  419. }
  420. CMGMTAffinityPage *pPage2 = new CMGMTAffinityPage(NULL, pContainer, SystemParms.processorMask);
  421. if (pPage2)
  422. {
  423. pPage2->m_affinitychk = (ProcDetail.base.mgmtParms.mFlags & PCMFLAG_APPLY_AFFINITY);
  424. pPage2->m_affinity = ProcDetail.base.mgmtParms.affinity;
  425. lpProvider->AddPage(pPage2->Create());
  426. }
  427. CMGMTPriorityPage *pPage3 = new CMGMTPriorityPage(NULL, pContainer);
  428. if (pPage3)
  429. {
  430. pPage3->m_prioritychk = (ProcDetail.base.mgmtParms.mFlags & PCMFLAG_APPLY_PRIORITY);
  431. pPage3->m_priority = ProcDetail.base.mgmtParms.priority;
  432. lpProvider->AddPage(pPage3->Create());
  433. }
  434. CMGMTMemoryPage *pPage4 = new CMGMTMemoryPage(NULL, pContainer);
  435. if (pPage4)
  436. {
  437. pPage4->m_WSchk = (ProcDetail.base.mgmtParms.mFlags & PCMFLAG_APPLY_WS_MINMAX);
  438. pPage4->m_minWS = ProcDetail.base.mgmtParms.minWS;
  439. pPage4->m_maxWS = ProcDetail.base.mgmtParms.maxWS;
  440. lpProvider->AddPage(pPage4->Create());
  441. }
  442. return S_OK;
  443. }
  444. #if _MSC_VER >= 1200
  445. #pragma warning( pop )
  446. #endif