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.

939 lines
25 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996-2000 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // BarfDlg.cpp
  7. //
  8. // Abstract:
  9. // Implementation of the Basic Artifical Resource Failure dialog classes.
  10. //
  11. // Author:
  12. // David Potter (davidp) April 11, 1997
  13. //
  14. // Revision History:
  15. //
  16. // Notes:
  17. //
  18. /////////////////////////////////////////////////////////////////////////////
  19. #include "stdafx.h"
  20. #include "resource.h"
  21. #define _RESOURCE_H_
  22. #define _NO_BARF_DEFINITIONS_
  23. #include "Barf.h"
  24. #include "BarfDlg.h"
  25. #include "TraceTag.h"
  26. #include "ExcOper.h"
  27. #ifdef _USING_BARF_
  28. #error BARF failures should be disabled!
  29. #endif
  30. #ifdef _DEBUG // The entire file!
  31. #define new DEBUG_NEW
  32. #undef THIS_FILE
  33. static char THIS_FILE[] = __FILE__;
  34. /////////////////////////////////////////////////////////////////////////////
  35. // Global Variables
  36. /////////////////////////////////////////////////////////////////////////////
  37. CTraceTag g_tagBarfDialog(_T("Debug"), _T("BARF Dialog"), 0);
  38. //*************************************************************************//
  39. /////////////////////////////////////////////////////////////////////////////
  40. // CBarfDialog
  41. /////////////////////////////////////////////////////////////////////////////
  42. CBarfDialog * CBarfDialog::s_pdlg = NULL;
  43. HICON CBarfDialog::s_hicon = NULL;
  44. /////////////////////////////////////////////////////////////////////////////
  45. // Message Maps
  46. BEGIN_MESSAGE_MAP(CBarfDialog, CDialog)
  47. //{{AFX_MSG_MAP(CBarfDialog)
  48. ON_BN_CLICKED(IDC_BS_RESET_CURRENT_COUNT, OnResetCurrentCount)
  49. ON_BN_CLICKED(IDC_BS_RESET_ALL_COUNTS, OnResetAllCounts)
  50. ON_BN_CLICKED(IDC_BS_GLOBAL_ENABLE, OnGlobalEnable)
  51. ON_NOTIFY(LVN_ITEMCHANGED, IDC_BS_CATEGORIES_LIST, OnItemChanged)
  52. ON_BN_CLICKED(IDC_BS_CONTINUOUS, OnStatusChange)
  53. ON_BN_CLICKED(IDC_BS_DISABLE, OnStatusChange)
  54. ON_EN_CHANGE(IDC_BS_FAIL_AT, OnStatusChange)
  55. ON_WM_CLOSE()
  56. //}}AFX_MSG_MAP
  57. ON_COMMAND(IDCANCEL, OnCancel)
  58. ON_MESSAGE(WM_USER+5, OnBarfUpdate)
  59. END_MESSAGE_MAP()
  60. /////////////////////////////////////////////////////////////////////////////
  61. //++
  62. //
  63. // CBarfDialog::CBarfDialog
  64. //
  65. // Routine Description:
  66. // Constructor.
  67. //
  68. // Arguments:
  69. // None.
  70. //
  71. // Return Value:
  72. // None.
  73. //
  74. //--
  75. /////////////////////////////////////////////////////////////////////////////
  76. CBarfDialog::CBarfDialog(void)
  77. {
  78. //{{AFX_DATA_INIT(CBarfDialog)
  79. m_nFailAt = 0;
  80. m_bContinuous = FALSE;
  81. m_bDisable = FALSE;
  82. m_bGlobalEnable = FALSE;
  83. //}}AFX_DATA_INIT
  84. Trace(g_tagBarfDialog, _T("CBarfDialog::CBarfDialog"));
  85. m_pbarfSelected = NULL;
  86. } //*** CBarfDialog::CBarfDialog()
  87. /////////////////////////////////////////////////////////////////////////////
  88. //++
  89. //
  90. // CBarfDialog::Create
  91. //
  92. // Routine Description:
  93. // Modeless dialog creation method.
  94. //
  95. // Arguments:
  96. // pParentWnd [IN OUT] Parent window for the dialog.
  97. //
  98. // Return Value:
  99. // None.
  100. //
  101. //--
  102. /////////////////////////////////////////////////////////////////////////////
  103. CBarfDialog::Create(
  104. IN OUT CWnd * pParentWnd //=NULL
  105. )
  106. {
  107. Trace(g_tagBarfDialog, _T("CBarfDialog::Create"));
  108. return CDialog::Create(IDD, pParentWnd);
  109. } //*** CBarfDialog::Create()
  110. /////////////////////////////////////////////////////////////////////////////
  111. //++
  112. //
  113. // CBarfDialog::DoDataExchange
  114. //
  115. // Routine Description:
  116. // Do data exchange between the dialog and the class.
  117. //
  118. // Arguments:
  119. // pDX [IN OUT] Data exchange object
  120. //
  121. // Return Value:
  122. // None.
  123. //
  124. //--
  125. /////////////////////////////////////////////////////////////////////////////
  126. void CBarfDialog::DoDataExchange(CDataExchange * pDX)
  127. {
  128. CDialog::DoDataExchange(pDX);
  129. //{{AFX_DATA_MAP(CBarfDialog)
  130. DDX_Control(pDX, IDC_BS_GLOBAL_ENABLE, m_ckbGlobalEnable);
  131. DDX_Control(pDX, IDC_BS_DISABLE, m_ckbDisable);
  132. DDX_Control(pDX, IDC_BS_CONTINUOUS, m_ckbContinuous);
  133. DDX_Control(pDX, IDC_BS_CATEGORIES_LIST, m_lcCategories);
  134. DDX_Text(pDX, IDC_BS_FAIL_AT, m_nFailAt);
  135. DDX_Check(pDX, IDC_BS_CONTINUOUS, m_bContinuous);
  136. DDX_Check(pDX, IDC_BS_DISABLE, m_bDisable);
  137. DDX_Check(pDX, IDC_BS_GLOBAL_ENABLE, m_bGlobalEnable);
  138. //}}AFX_DATA_MAP
  139. if (pDX->m_bSaveAndValidate)
  140. {
  141. } // if: saving data from the dialog
  142. else
  143. {
  144. int ili;
  145. CBarf * pbarf;
  146. CString str;
  147. ili = m_lcCategories.GetNextItem(-1, LVNI_SELECTED);
  148. if (ili == -1)
  149. ili = m_lcCategories.GetNextItem(-1, LVNI_FOCUSED);
  150. if (ili != -1)
  151. {
  152. pbarf = (CBarf *) m_lcCategories.GetItemData(ili);
  153. // Set the current count.
  154. str.Format(_T("%d"), pbarf->NCurrent());
  155. VERIFY(m_lcCategories.SetItemText(ili, 1, str));
  156. // Set the failure point.
  157. str.Format(_T("%d"), pbarf->NFail());
  158. VERIFY(m_lcCategories.SetItemText(ili, 2, str));
  159. } // if: there is an item with focus
  160. } // else: setting data to the dialog
  161. } //*** CBarfDialog::DoDataExchange()
  162. /////////////////////////////////////////////////////////////////////////////
  163. //++
  164. //
  165. // CBarfDialog::OnInitDialog
  166. //
  167. // Routine Description:
  168. // Handler for the WM_INITDIALOG message.
  169. //
  170. // Arguments:
  171. // None.
  172. //
  173. // Return Value:
  174. // TRUE Focus needs to be set.
  175. // FALSE Focus already set.
  176. //
  177. //--
  178. /////////////////////////////////////////////////////////////////////////////
  179. BOOL CBarfDialog::OnInitDialog(void)
  180. {
  181. // Call the base class.
  182. CDialog::OnInitDialog();
  183. ASSERT(Pdlg() == NULL);
  184. s_pdlg = this;
  185. // Set the post update function to point to our static function.
  186. CBarf::SetPostUpdateFn(&PostUpdate);
  187. CBarf::SetSpecialMem(Pdlg());
  188. // Add the columns to the list control.
  189. {
  190. m_lcCategories.InsertColumn(0, _T("Category"), LVCFMT_LEFT, 100);
  191. m_lcCategories.InsertColumn(1, _T("Count"), LVCFMT_LEFT, 50);
  192. m_lcCategories.InsertColumn(2, _T("Fail At"), LVCFMT_LEFT, 50);
  193. } // Add the columns to the list control
  194. // Set-up the dialog based on the real values...
  195. FillList();
  196. OnUpdate();
  197. return TRUE; // return TRUE unless you set the focus to a control
  198. // EXCEPTION: OCX Property Pages should return FALSE
  199. } //*** CBarfDialog::OnInitDialog()
  200. /////////////////////////////////////////////////////////////////////////////
  201. //++
  202. //
  203. // CBarfDialog::OnClose
  204. //
  205. // Routine Description:
  206. // Handler method for the WM_CLOSE message.
  207. //
  208. // Arguments:
  209. // None.
  210. //
  211. // Return Value:
  212. // None.
  213. //
  214. //--
  215. /////////////////////////////////////////////////////////////////////////////
  216. void CBarfDialog::OnClose(void)
  217. {
  218. CDialog::OnClose();
  219. DestroyWindow();
  220. } //*** CBarfDialog::OnClose()
  221. /////////////////////////////////////////////////////////////////////////////
  222. //++
  223. //
  224. // CBarfDialog::OnCancel
  225. //
  226. // Routine Description:
  227. // Handler method for the WM_COMMAND message when IDCANCEL is sent.
  228. //
  229. // Arguments:
  230. // None.
  231. //
  232. // Return Value:
  233. // None.
  234. //
  235. //--
  236. /////////////////////////////////////////////////////////////////////////////
  237. void CBarfDialog::OnCancel(void)
  238. {
  239. CDialog::OnCancel();
  240. DestroyWindow();
  241. } //*** CBarfDialog::OnCancel()
  242. /////////////////////////////////////////////////////////////////////////////
  243. //++
  244. //
  245. // CBarfDialog::PostNcDestroy
  246. //
  247. // Routine Description:
  248. // Processing after non-client has been destroyed.
  249. //
  250. // Arguments:
  251. // None.
  252. //
  253. // Return Value:
  254. // None.
  255. //
  256. //--
  257. /////////////////////////////////////////////////////////////////////////////
  258. void CBarfDialog::PostNcDestroy(void)
  259. {
  260. CDialog::PostNcDestroy();
  261. delete this;
  262. CBarf::ClearPostUpdateFn();
  263. s_pdlg = NULL;
  264. } //*** CBarfDialog::PostNcDestroy()
  265. /////////////////////////////////////////////////////////////////////////////
  266. //++
  267. //
  268. // CBarfDialog::FillList
  269. //
  270. // Routine Description:
  271. // Loads the list of failure categories.
  272. //
  273. // Arguments:
  274. // None.
  275. //
  276. // Return Value:
  277. // None.
  278. //
  279. //--
  280. /////////////////////////////////////////////////////////////////////////////
  281. void CBarfDialog::FillList(void)
  282. {
  283. int ili;
  284. int iliReturn;
  285. CString str;
  286. CBarf * pbarf = CBarf::s_pbarfFirst;
  287. CBarfSuspend bs;
  288. m_lcCategories.DeleteAllItems();
  289. for (ili = 0 ; pbarf != NULL ; ili++)
  290. {
  291. // Insert the item.
  292. iliReturn = m_lcCategories.InsertItem(ili, pbarf->PszName());
  293. ASSERT(iliReturn != -1);
  294. // Set the current count.
  295. str.Format(_T("%d"), pbarf->NCurrent());
  296. VERIFY(m_lcCategories.SetItemText(iliReturn, 1, str));
  297. // Set the failure point.
  298. str.Format(_T("%d"), pbarf->NFail());
  299. VERIFY(m_lcCategories.SetItemText(iliReturn, 2, str));
  300. // Set the pointer in the entry so we can retrieve it later.
  301. VERIFY(m_lcCategories.SetItemData(iliReturn, (DWORD) pbarf));
  302. // Advance to the next entry
  303. pbarf = pbarf->m_pbarfNext;
  304. } // while: more BARF entries
  305. // If no known selection yet, get the current selection.
  306. if (m_pbarfSelected == NULL)
  307. {
  308. ili = m_lcCategories.GetNextItem(-1, LVNI_SELECTED);
  309. if (ili == -1)
  310. ili = 0;
  311. m_pbarfSelected = (CBarf *) m_lcCategories.GetItemData(ili);
  312. if (m_pbarfSelected != NULL)
  313. OnUpdate();
  314. } // if: no know selection
  315. // Select the proper item.
  316. {
  317. LV_FINDINFO lvfi = { LVFI_PARAM, NULL, (DWORD) m_pbarfSelected };
  318. ili = m_lcCategories.FindItem(&lvfi);
  319. if (ili != -1)
  320. m_lcCategories.SetItemState(ili, LVIS_SELECTED, LVIS_SELECTED);
  321. } // Select the proper item
  322. } //*** CBarfDialog::FillList()
  323. /////////////////////////////////////////////////////////////////////////////
  324. //++
  325. //
  326. // CBarfDialog::OnUpdate
  327. //
  328. // Routine Description:
  329. // Updates the displayed counts to their TRUE values.
  330. //
  331. // Arguments:
  332. // None.
  333. //
  334. // Return Value:
  335. // None.
  336. //
  337. //--
  338. /////////////////////////////////////////////////////////////////////////////
  339. void CBarfDialog::OnUpdate(void)
  340. {
  341. Trace(g_tagBarfDialog, _T("Updating the counts."));
  342. ASSERT(m_pbarfSelected != NULL);
  343. m_bContinuous = m_pbarfSelected->BContinuous();
  344. m_bDisable = m_pbarfSelected->BDisabled();
  345. m_nFailAt = m_pbarfSelected->NFail();
  346. m_bGlobalEnable = CBarf::s_bGlobalEnable;
  347. UpdateData(FALSE /*bSaveAndValidate*/);
  348. } //*** CBarfDialog::OnUpdate()
  349. /////////////////////////////////////////////////////////////////////////////
  350. //++
  351. //
  352. // CBarfDialog::OnGlobalEnable
  353. //
  354. // Routine Description:
  355. // Handler function for the BN_CLICKED message on the Global Enable
  356. // checkbox.
  357. //
  358. // Arguments:
  359. // None.
  360. //
  361. // Return Value:
  362. // None.
  363. //
  364. //--
  365. /////////////////////////////////////////////////////////////////////////////
  366. void CBarfDialog::OnGlobalEnable(void)
  367. {
  368. ASSERT(m_ckbGlobalEnable.m_hWnd != NULL);
  369. CBarf::s_bGlobalEnable = m_ckbGlobalEnable.GetCheck() == BST_CHECKED;
  370. } //*** CBarfDialog::OnGlobalEnable()
  371. /////////////////////////////////////////////////////////////////////////////
  372. //++
  373. //
  374. // CBarfDialog::OnResetCurrentCount
  375. //
  376. // Routine Description:
  377. // Handler function for the BN_CLICKED message on the Reset Current
  378. // Count button.
  379. //
  380. // Arguments:
  381. // None.
  382. //
  383. // Return Value:
  384. // None.
  385. //
  386. //--
  387. /////////////////////////////////////////////////////////////////////////////
  388. void CBarfDialog::OnResetCurrentCount(void)
  389. {
  390. int ili;
  391. CBarf * pbarf;
  392. ASSERT(m_lcCategories.m_hWnd != NULL);
  393. // Get the selected item.
  394. ili = m_lcCategories.GetNextItem(-1, LVIS_SELECTED);
  395. ASSERT(ili != -1);
  396. pbarf = (CBarf *) m_lcCategories.GetItemData(ili);
  397. ASSERT(pbarf != NULL);
  398. ASSERT(pbarf == m_pbarfSelected);
  399. // Reset the count.
  400. pbarf->m_nCurrent = 0;
  401. OnStatusChange();
  402. } //*** CBarfDialog::OnResetCurrentCount()
  403. /////////////////////////////////////////////////////////////////////////////
  404. //++
  405. //
  406. // CBarfDialog::OnResetAllCounts
  407. //
  408. // Routine Description:
  409. // Handler function for the BN_CLICKED message on the Reset All
  410. // Counts button.
  411. //
  412. // Arguments:
  413. // None.
  414. //
  415. // Return Value:
  416. // None.
  417. //
  418. //--
  419. /////////////////////////////////////////////////////////////////////////////
  420. void CBarfDialog::OnResetAllCounts(void)
  421. {
  422. CBarf * pbarf = CBarf::s_pbarfFirst;
  423. Trace(g_tagBarfDialog, _T("Resetting ALL current counts."));
  424. while (pbarf != NULL)
  425. {
  426. pbarf->m_nCurrent = 0;
  427. pbarf = pbarf->m_pbarfNext;
  428. } // while: more BARF entries
  429. FillList();
  430. } //*** CBarfDialog::OnResetAllCounts()
  431. /////////////////////////////////////////////////////////////////////////////
  432. //++
  433. //
  434. // CBarfDialog::OnResetAllCounts
  435. //
  436. // Routine Description:
  437. // Handler function for the LVN_ITEMCHANGED message from the list control.
  438. //
  439. // Arguments:
  440. // None.
  441. //
  442. // Return Value:
  443. // None.
  444. //
  445. //--
  446. /////////////////////////////////////////////////////////////////////////////
  447. void CBarfDialog::OnItemChanged(NMHDR * pNMHDR, LRESULT * pResult)
  448. {
  449. NM_LISTVIEW * pNMListView = (NM_LISTVIEW *) pNMHDR;
  450. // If the item just became unselected or selected, change the checkboxes to match.
  451. if ((pNMListView->uChanged & LVIF_STATE)
  452. && ((pNMListView->uOldState & LVIS_SELECTED)
  453. || (pNMListView->uNewState & LVIS_SELECTED)))
  454. {
  455. // Handle a selection change.
  456. m_pbarfSelected = (CBarf *) pNMListView->lParam;
  457. OnStatusChange();
  458. } // if: item received the focus
  459. *pResult = 0;
  460. } //*** CBarfDialog::OnItemChanged()
  461. /////////////////////////////////////////////////////////////////////////////
  462. //++
  463. //
  464. // CBarfDialog::OnStatusChange
  465. //
  466. // Routine Description:
  467. // Adjusts the C== object when the status of the currently selected
  468. // item changes.
  469. //
  470. // Arguments:
  471. // None.
  472. //
  473. // Return Value:
  474. // None.
  475. //
  476. //--
  477. /////////////////////////////////////////////////////////////////////////////
  478. void CBarfDialog::OnStatusChange(void)
  479. {
  480. ASSERT(m_pbarfSelected != NULL);
  481. UpdateData(TRUE /*bSaveAndValidate*/);
  482. m_pbarfSelected->m_bContinuous = m_bContinuous;
  483. m_pbarfSelected->m_bDisabled = m_bDisable;
  484. m_pbarfSelected->m_nFail = m_nFailAt;
  485. UpdateData(FALSE /*bSaveAndValidate*/);
  486. } //*** CBarfDialog::OnStatusChange()
  487. /////////////////////////////////////////////////////////////////////////////
  488. //++
  489. //
  490. // CBarfDialog::OnBarfUpdate
  491. //
  492. // Routine Description:
  493. // Handler for the WM_USER message.
  494. // Processes barf notifications.
  495. //
  496. // Arguments:
  497. // wparam 1st parameter.
  498. // lparam 2nd parameter.
  499. //
  500. // Return Value:
  501. // Value returned from the application method.
  502. //
  503. //--
  504. /////////////////////////////////////////////////////////////////////////////
  505. LRESULT CBarfDialog::OnBarfUpdate(WPARAM wparam, LPARAM lparam)
  506. {
  507. OnUpdate();
  508. return 0;
  509. } //*** CBarfDialog::OnBarfUpdate()
  510. /////////////////////////////////////////////////////////////////////////////
  511. //++
  512. //
  513. // CBarfDialog::PostUpdate
  514. //
  515. // Routine Description:
  516. // Static function so that CBarf::BFail can post updates to us.
  517. //
  518. // Arguments:
  519. // None.
  520. //
  521. // Return Value:
  522. // None.
  523. //
  524. //--
  525. /////////////////////////////////////////////////////////////////////////////
  526. void CBarfDialog::PostUpdate(void)
  527. {
  528. // If this function gets called, there should be BARF dialog.
  529. ASSERT(Pdlg() != NULL);
  530. if (Pdlg() != NULL)
  531. ::PostMessage(Pdlg()->m_hWnd, WM_USER+5, NULL, NULL);
  532. } //*** CBarfDialog::PostUpdate()
  533. //*************************************************************************//
  534. /////////////////////////////////////////////////////////////////////////////
  535. // CBarfAllDialog
  536. /////////////////////////////////////////////////////////////////////////////
  537. /////////////////////////////////////////////////////////////////////////////
  538. // Message Maps
  539. BEGIN_MESSAGE_MAP(CBarfAllDialog, CDialog)
  540. //{{AFX_MSG_MAP(CBarfAllDialog)
  541. ON_BN_CLICKED(IDC_BAS_MENU_ITEM, OnMenuItem)
  542. //}}AFX_MSG_MAP
  543. END_MESSAGE_MAP()
  544. /////////////////////////////////////////////////////////////////////////////
  545. //++
  546. //
  547. // CBarfAllDialog::CBarfAllDialog
  548. //
  549. // Routine Description:
  550. // Constructor.
  551. //
  552. // Arguments:
  553. // pParentWnd [IN OUT] Parent window for the dialog.
  554. //
  555. // Return Value:
  556. // None.
  557. //
  558. //--
  559. /////////////////////////////////////////////////////////////////////////////
  560. CBarfAllDialog::CBarfAllDialog(
  561. IN OUT CWnd * pParentWnd //=NULL
  562. )
  563. : CDialog(IDD, pParentWnd)
  564. {
  565. //{{AFX_DATA_INIT(CBarfAllDialog)
  566. //}}AFX_DATA_INIT
  567. m_hwndBarf = NULL;
  568. m_wmBarf = 0;
  569. m_wparamBarf = 0;
  570. m_lparamBarf = 0;
  571. } //*** CBarfAllDialog::CBarfAllDialog()
  572. /////////////////////////////////////////////////////////////////////////////
  573. //++
  574. //
  575. // CBarfAllDialog::DoDataExchange
  576. //
  577. // Routine Description:
  578. // Do data exchange between the dialog and the class.
  579. //
  580. // Arguments:
  581. // pDX [IN OUT] Data exchange object
  582. //
  583. // Return Value:
  584. // None.
  585. //
  586. //--
  587. /////////////////////////////////////////////////////////////////////////////
  588. void CBarfAllDialog::DoDataExchange(CDataExchange * pDX)
  589. {
  590. CDialog::DoDataExchange(pDX);
  591. //{{AFX_DATA_MAP(CBarfAllDialog)
  592. DDX_Control(pDX, IDC_BAS_LPARAM, m_editLparam);
  593. DDX_Control(pDX, IDC_BAS_WPARAM, m_editWparam);
  594. DDX_Control(pDX, IDC_BAS_WM, m_editWm);
  595. DDX_Control(pDX, IDC_BAS_HWND, m_editHwnd);
  596. //}}AFX_DATA_MAP
  597. DDX_Text(pDX, IDC_BAS_HWND, (DWORD &) m_hwndBarf);
  598. DDX_Text(pDX, IDC_BAS_WM, m_wmBarf);
  599. DDX_Text(pDX, IDC_BAS_WPARAM, m_wparamBarf);
  600. DDX_Text(pDX, IDC_BAS_LPARAM, m_lparamBarf);
  601. } //*** CBarfAllDialog::DoDataExchange()
  602. /////////////////////////////////////////////////////////////////////////////
  603. //++
  604. //
  605. // CBarfAllDialog::OnInitDialog
  606. //
  607. // Routine Description:
  608. // Handler for the WM_INITDIALOG message.
  609. //
  610. // Arguments:
  611. // None.
  612. //
  613. // Return Value:
  614. // TRUE Focus needs to be set.
  615. // FALSE Focus already set.
  616. //
  617. //--
  618. /////////////////////////////////////////////////////////////////////////////
  619. BOOL CBarfAllDialog::OnInitDialog(void)
  620. {
  621. // Call the base class.
  622. CDialog::OnInitDialog();
  623. return TRUE; // return TRUE unless you set the focus to a control
  624. // EXCEPTION: OCX Property Pages should return FALSE
  625. } //*** CBarfAllDialog::OnInitDialog()
  626. /////////////////////////////////////////////////////////////////////////////
  627. //++
  628. //
  629. // CBarfAllDialog::OnOK
  630. //
  631. // Routine Description:
  632. // Handler for the BN_CLICKED message on the OK button.
  633. //
  634. // Arguments:
  635. // None.
  636. //
  637. // Return Value:
  638. // None.
  639. //
  640. //--
  641. /////////////////////////////////////////////////////////////////////////////
  642. void CBarfAllDialog::OnOK(void)
  643. {
  644. if (m_hwndBarf == NULL)
  645. m_hwndBarf = AfxGetMainWnd()->m_hWnd;
  646. CDialog::OnOK();
  647. } //*** CBarfAllDialog::OnDialog()
  648. /////////////////////////////////////////////////////////////////////////////
  649. //++
  650. //
  651. // CBarfAllDialog::OnMenuItem
  652. //
  653. // Routine Description:
  654. // Handler for the BN_CLICKED message on the Menu Item button.
  655. //
  656. // Arguments:
  657. // None.
  658. //
  659. // Return Value:
  660. // None.
  661. //
  662. //--
  663. /////////////////////////////////////////////////////////////////////////////
  664. void CBarfAllDialog::OnMenuItem(void)
  665. {
  666. m_editHwnd.SetWindowText(_T("0"));
  667. m_editWm.SetWindowText(_T("273")); // WM_COMMAND
  668. m_editLparam.SetWindowText(_T("0"));
  669. m_editWparam.SetWindowText(_T("0"));
  670. } //*** CBarfAllDialog::OnMenuItem()
  671. //*************************************************************************//
  672. /////////////////////////////////////////////////////////////////////////////
  673. // Global Functions
  674. /////////////////////////////////////////////////////////////////////////////
  675. /////////////////////////////////////////////////////////////////////////////
  676. //++
  677. //
  678. // BarfAll
  679. //
  680. // Routine Description:
  681. // Exercises all possible single failures.
  682. //
  683. // Arguments:
  684. // None.
  685. //
  686. // Return Value:
  687. // None.
  688. //
  689. //--
  690. /////////////////////////////////////////////////////////////////////////////
  691. void BarfAll(void)
  692. {
  693. CBarf * pbarf;
  694. CBarfAllDialog dlg(AfxGetMainWnd());
  695. ID id;
  696. CString str;
  697. // First, pick-up the message to test.
  698. id = dlg.DoModal();
  699. if (id != IDOK)
  700. {
  701. Trace(g_tagAlways, _T("BarfAll() - operation cancelled."));
  702. return;
  703. } // if: BarfAll cancelled
  704. Trace(g_tagAlways,
  705. _T("BarfAll with hwnd = %#08lX, wm = 0x%4x, wparam = %d, lparam = %d"),
  706. dlg.HwndBarf(), dlg.WmBarf(), dlg.WparamBarf(), dlg.LparamBarf());
  707. // Now, find out how many counts of each resource...
  708. pbarf = CBarf::s_pbarfFirst;
  709. while (pbarf != NULL)
  710. {
  711. pbarf->m_nCurrentSave = pbarf->m_nCurrent;
  712. pbarf->m_nCurrent = 0;
  713. pbarf->m_nFail = 0;
  714. pbarf->m_bContinuous = FALSE;
  715. pbarf->m_bDisabled = FALSE;
  716. pbarf = pbarf->m_pbarfNext;
  717. } // while: more BARF entries
  718. if (CBarfDialog::Pdlg())
  719. CBarfDialog::Pdlg()->OnUpdate();
  720. str = _T("BarfAll Test pass.");
  721. Trace(g_tagAlways, str);
  722. SendMessage(dlg.HwndBarf(), dlg.WmBarf(),
  723. dlg.WparamBarf(), dlg.LparamBarf());
  724. pbarf = CBarf::s_pbarfFirst;
  725. while (pbarf != NULL)
  726. {
  727. pbarf->m_nBarfAll = pbarf->m_nCurrentSave;
  728. pbarf = pbarf->m_pbarfNext;
  729. } // while: more entries in the list
  730. MessageBox(dlg.HwndBarf(), str, _T("BARF Status"), MB_OK | MB_ICONEXCLAMATION);
  731. // Finally, THE big loop...
  732. pbarf = CBarf::s_pbarfFirst;
  733. while (pbarf != NULL)
  734. {
  735. for (pbarf->m_nFail = 1
  736. ; pbarf->m_nFail <= pbarf->m_nBarfAll
  737. ; pbarf->m_nFail++)
  738. {
  739. // CBarfMemory::Mark();
  740. pbarf->m_nCurrent = 0;
  741. if (CBarfDialog::Pdlg())
  742. CBarfDialog::Pdlg()->OnUpdate();
  743. str.Format(_T("BarfAll on resource %s, call # %d of %d"),
  744. pbarf->m_pszName, pbarf->m_nFail, pbarf->m_nBarfAll);
  745. Trace(g_tagAlways, str);
  746. SendMessage(dlg.HwndBarf(), dlg.WmBarf(),
  747. dlg.WparamBarf(), dlg.LparamBarf());
  748. // CBarfMemory::DumpMarked();
  749. // ValidateMemory();
  750. str += _T("\nContinue?");
  751. if (MessageBox(dlg.HwndBarf(), str, _T("BARF: Pass Complete."), MB_YESNO | MB_ICONEXCLAMATION) != IDYES)
  752. break;
  753. } // for: while the failure count is less than the BARF All count
  754. pbarf->m_nFail = 0;
  755. pbarf->m_nCurrent = pbarf->m_nCurrentSave;
  756. pbarf = pbarf->m_pbarfNext;
  757. } // while: more BARF entries
  758. if (CBarfDialog::Pdlg())
  759. CBarfDialog::Pdlg()->OnUpdate();
  760. } //*** BarfAll()
  761. /////////////////////////////////////////////////////////////////////////////
  762. //++
  763. //
  764. // DoBarfDialog
  765. //
  766. // Routine Description:
  767. // Launches the Barf Settings dialog.
  768. //
  769. // Arguments:
  770. // None.
  771. //
  772. // Return Value:
  773. // None.
  774. //
  775. //--
  776. /////////////////////////////////////////////////////////////////////////////
  777. void DoBarfDialog( void )
  778. {
  779. if ( CBarf::s_pbarfFirst == NULL )
  780. {
  781. AfxMessageBox( _T("No BARF counters defined yet."), MB_OK );
  782. } // if: no counters defined yet
  783. else if ( CBarfDialog::Pdlg() )
  784. {
  785. BringWindowToTop( CBarfDialog::Pdlg()->m_hWnd );
  786. if ( IsIconic( CBarfDialog::Pdlg()->m_hWnd ) )
  787. {
  788. SendMessage( CBarfDialog::Pdlg()->m_hWnd, WM_SYSCOMMAND, SC_RESTORE, NULL );
  789. } // if: window is currently minimized
  790. } // if: there is already a dialog up
  791. else
  792. {
  793. CBarfDialog * pdlg = NULL;
  794. try
  795. {
  796. pdlg = new CBarfDialog;
  797. if ( pdlg == NULL )
  798. {
  799. AfxThrowMemoryException();
  800. } // if: error allocating the dialog
  801. pdlg->Create( AfxGetMainWnd() );
  802. } // try
  803. catch ( CException * pe )
  804. {
  805. pe->ReportError();
  806. pe->Delete();
  807. } // catch: CException
  808. } // else: no dialog up yet
  809. } //*** DoBarfDialog()
  810. #endif // _DEBUG