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.

195 lines
6.4 KiB

  1. //
  2. // mallocdbgdlg.cpp: mallocdbg dialog box
  3. //
  4. #include "stdafx.h"
  5. #define TRC_GROUP TRC_GROUP_UI
  6. #define TRC_FILE "mallocdbgdlg"
  7. #include <atrcapi.h>
  8. #include "mallocdbgdlg.h"
  9. #include "sh.h"
  10. #ifdef DC_DEBUG
  11. CMallocDbgDlg* CMallocDbgDlg::_pMallocDbgDlgInstance = NULL;
  12. CMallocDbgDlg::CMallocDbgDlg( HWND hwndOwner, HINSTANCE hInst, DCINT failPercent, DCBOOL mallocHuge) :
  13. CDlgBase( hwndOwner, hInst, mallocHuge ? UI_IDD_MALLOCHUGEFAILURE : UI_IDD_MALLOCFAILURE)
  14. {
  15. DC_BEGIN_FN("CMallocDbgDlg");
  16. TRC_ASSERT((NULL == CMallocDbgDlg::_pMallocDbgDlgInstance),
  17. (TB,_T("Clobbering existing dlg instance pointer\n")));
  18. _failPercent = failPercent;
  19. CMallocDbgDlg::_pMallocDbgDlgInstance = this;
  20. DC_END_FN();
  21. }
  22. CMallocDbgDlg::~CMallocDbgDlg()
  23. {
  24. CMallocDbgDlg::_pMallocDbgDlgInstance = NULL;
  25. }
  26. DCINT CMallocDbgDlg::DoModal()
  27. {
  28. DCINT retVal = 0;
  29. DC_BEGIN_FN("DoModal");
  30. retVal = DialogBox(_hInstance, MAKEINTRESOURCE(_dlgResId),
  31. _hwndOwner, StaticDialogBoxProc);
  32. TRC_ASSERT((retVal != 0 && retVal != -1), (TB, _T("DialogBoxParam failed\n")));
  33. DC_END_FN();
  34. return retVal;
  35. }
  36. INT_PTR CALLBACK CMallocDbgDlg::StaticDialogBoxProc (HWND hwndDlg, UINT uMsg,WPARAM wParam, LPARAM lParam)
  37. {
  38. //
  39. // Delegate to appropriate instance (only works for single instance dialogs)
  40. //
  41. DC_BEGIN_FN("StaticDialogBoxProc");
  42. DCINT retVal = 0;
  43. TRC_ASSERT(_pMallocDbgDlgInstance, (TB, _T("MallocDbg dialog has NULL static instance ptr\n")));
  44. if(_pMallocDbgDlgInstance)
  45. {
  46. retVal = _pMallocDbgDlgInstance->DialogBoxProc( hwndDlg, uMsg, wParam, lParam);
  47. }
  48. DC_END_FN();
  49. return retVal;
  50. }
  51. /****************************************************************************/
  52. /* Name: DialogBoxProc */
  53. /* */
  54. /* Purpose: Handles MallocDbg Box dialog (Random Failure dialog) */
  55. /* */
  56. /* Returns: TRUE if message dealt with */
  57. /* FALSE otherwise */
  58. /* */
  59. /* Params: See window documentation */
  60. /* */
  61. /****************************************************************************/
  62. INT_PTR CALLBACK CMallocDbgDlg::DialogBoxProc (HWND hwndDlg, UINT uMsg,WPARAM wParam, LPARAM lParam)
  63. {
  64. INT_PTR rc = FALSE;
  65. DCTCHAR numberString[SH_NUMBER_STRING_MAX_LENGTH];
  66. DCINT percent = 0;
  67. DCINT lenchar = 0;
  68. DC_BEGIN_FN("UIRandomFailureDialogProc");
  69. TRC_DBG((TB, _T("Random failure dialog")));
  70. switch (uMsg)
  71. {
  72. case WM_INITDIALOG:
  73. {
  74. _hwndDlg = hwndDlg;
  75. /****************************************************************/
  76. /* Center the dialog */
  77. /****************************************************************/
  78. if(hwndDlg)
  79. {
  80. CenterWindow(NULL);
  81. SetDialogAppIcon(hwndDlg);
  82. SetFocus(GetDlgItem(hwndDlg, UI_IDC_RANDOMFAILURE_EDIT));
  83. /************************************************************/
  84. /* Set edit text with current percentage */
  85. /************************************************************/
  86. TRC_ASSERT((HIWORD(_failPercent) == 0), (TB,_T("_UI.randomFailureItem")));
  87. SetDlgItemText(hwndDlg,
  88. UI_IDC_RANDOMFAILURE_EDIT,
  89. DC_ITOT(LOWORD(_failPercent), numberString, 10));
  90. }
  91. rc = TRUE;
  92. }
  93. break;
  94. case WM_COMMAND:
  95. {
  96. switch (wParam)
  97. {
  98. case UI_IDB_MALLOCFAILURE_OK:
  99. {
  100. rc = TRUE;
  101. lenchar = GetWindowText(GetDlgItem(hwndDlg, UI_IDC_RANDOMFAILURE_EDIT),
  102. numberString,
  103. SH_NUMBER_STRING_MAX_LENGTH);
  104. if(lenchar)
  105. {
  106. percent = DC_TTOI(numberString);
  107. }
  108. if ((percent <= 100) && (percent >= 0))
  109. {
  110. _failPercent = percent;
  111. if(hwndDlg)
  112. {
  113. EndDialog(hwndDlg, IDOK);
  114. }
  115. }
  116. }
  117. break;
  118. case UI_IDB_MALLOCHUGEFAILURE_OK:
  119. {
  120. rc = TRUE;
  121. lenchar = GetWindowText(GetDlgItem(hwndDlg, UI_IDC_RANDOMFAILURE_EDIT),
  122. numberString,
  123. SH_NUMBER_STRING_MAX_LENGTH);
  124. if(lenchar)
  125. {
  126. percent = DC_TTOI(numberString);
  127. }
  128. if ((percent <= 100) && (percent >= 0))
  129. {
  130. _failPercent = percent;
  131. if(hwndDlg)
  132. {
  133. EndDialog(hwndDlg, IDOK);
  134. }
  135. }
  136. }
  137. break;
  138. default:
  139. {
  140. if(hwndDlg)
  141. {
  142. rc = CDlgBase::DialogBoxProc(hwndDlg,
  143. uMsg,
  144. wParam,
  145. lParam);
  146. }
  147. }
  148. break;
  149. }
  150. }
  151. break;
  152. default:
  153. {
  154. rc = CDlgBase::DialogBoxProc(hwndDlg,
  155. uMsg,
  156. wParam,
  157. lParam);
  158. }
  159. break;
  160. }
  161. DC_END_FN();
  162. return(rc);
  163. }
  164. #endif //DC_DEBUG