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.

108 lines
2.2 KiB

  1. #include "ddemlp.h"
  2. #include "heapwach.h"
  3. #ifdef WATCHHEAPS
  4. extern char FAR SZHEAPWATCHCLASS[];
  5. #define MAX_WINDOWS 20
  6. typedef struct {
  7. WORD sel;
  8. HWND hwnd;
  9. } SELWND;
  10. char szT[30];
  11. SELWND sw[MAX_WINDOWS];
  12. int cHwnds = 0;
  13. VOID LogAlloc(
  14. DWORD lpstr,
  15. WORD cb,
  16. DWORD color,
  17. HANDLE hInstance)
  18. {
  19. int i;
  20. HWND hwnd;
  21. WORD sel;
  22. WORD off;
  23. int mj, mn, cl;
  24. HDC hdc;
  25. RECT rc, rcClient;
  26. HBRUSH hbr;
  27. sel = HIWORD(lpstr);
  28. hwnd = NULL;
  29. for (i = 0; i < cHwnds; i++) {
  30. if (sel == sw[i].sel) {
  31. hwnd = sw[i].hwnd;
  32. if (!IsWindow(hwnd)) {
  33. // this must have been destroyed and we are now reusing the sel.
  34. sw[i] = sw[--cHwnds];
  35. hwnd = NULL;
  36. }
  37. break;
  38. }
  39. }
  40. if (!hwnd && cHwnds < MAX_WINDOWS) {
  41. itoa((int)sel, szT, 16);
  42. sw[cHwnds].sel = sel;
  43. sw[cHwnds].hwnd = hwnd = CreateWindow(SZHEAPWATCHCLASS, szT,
  44. WS_POPUP | WS_CAPTION, CW_USEDEFAULT, CW_USEDEFAULT, 64, 64,
  45. NULL, NULL, hInstance, NULL);
  46. if (hwnd) {
  47. cHwnds++;
  48. GetWindowRect(hwnd, &rc);
  49. GetClientRect(hwnd, &rcClient);
  50. rc.bottom += 128 - (rcClient.bottom - rcClient.top);
  51. rc.right += 128 - (rcClient.right - rcClient.left);
  52. MoveWindow(hwnd, 0, 0, rc.right - rc.left, rc.bottom - rc.top, FALSE);
  53. ShowWindow(hwnd, SW_SHOWNORMAL);
  54. }
  55. }
  56. if (!hwnd) {
  57. return;
  58. }
  59. off = LOWORD(lpstr) >> 2;
  60. mj = off >> 7;
  61. mn = off & 0x7f;
  62. cl = cb >> 2;
  63. hdc = GetDC(hwnd);
  64. hbr = CreateSolidBrush(color);
  65. rc.top = mj;
  66. rc.bottom = rc.top + 1;
  67. rc.left = (int)mn;
  68. rc.right = min(127, mn + cl);
  69. FillRect(hdc, &rc, hbr);
  70. cl -= (int)(rc.right - rc.left);
  71. if (cl > 127) {
  72. rc.top++;
  73. rc.bottom = rc.top + cl / 128;
  74. rc.left = 0;
  75. rc.right = 127;
  76. FillRect(hdc, &rc, hbr);
  77. cl -= 128 * (cl / 128);
  78. }
  79. if (cl > 0) {
  80. rc.top = rc.bottom;
  81. rc.bottom++;
  82. rc.left = 0;
  83. rc.right = cl;
  84. FillRect(hdc, &rc, hbr);
  85. }
  86. DeleteObject(hbr);
  87. ReleaseDC(hwnd, hdc);
  88. }
  89. VOID CloseHeapWatch()
  90. {
  91. int i;
  92. for (i = 0; i < cHwnds; i++) {
  93. DestroyWindow(sw[i].hwnd);
  94. }
  95. cHwnds = 0;
  96. }
  97. #endif