Windows NT 4.0 source code leak
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.

211 lines
3.9 KiB

4 years ago
  1. /************************************************************************
  2. * *
  3. * CWINFILE.CPP *
  4. * *
  5. * Copyright (C) Microsoft Corporation 1993-1994 *
  6. * All Rights reserved. *
  7. * *
  8. ************************************************************************/
  9. #include "stdafx.h"
  10. #pragma hdrstop
  11. #include "cpaldc.h"
  12. #ifdef _DEBUG
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16. CPalDC::CPalDC(HBITMAP hbmpSel, HPALETTE hpalSel)
  17. {
  18. hdc = CreateCompatibleDC(NULL);
  19. ASSERT(hdc);
  20. if (!hdc)
  21. return; // out of system resources
  22. hpal = NULL;
  23. if (hpalSel)
  24. SelectPal(hpalSel);
  25. hbmpOrg = hbmpSel;
  26. if (hbmpSel) {
  27. // Can fail if hbmp is selected into another DC
  28. VERIFY((hbmp = (HBITMAP) SelectObject(hdc, hbmpSel)));
  29. }
  30. else
  31. hbmp = NULL;
  32. hbrCreated = NULL;
  33. hwndDC = NULL;
  34. hbr = NULL;
  35. }
  36. CPalDC::CPalDC(HWND hwnd)
  37. {
  38. hdc = GetDC(hwnd);
  39. ASSERT(hdc);
  40. if (!hdc)
  41. return; // out of system resources
  42. hwndDC = hwnd;
  43. hpal = NULL;
  44. hbmp = NULL;
  45. hbrCreated = NULL;
  46. hbr = NULL;
  47. hbmpOrg = NULL;
  48. }
  49. static const char txtDisplay[] = "DISPLAY";
  50. CPalDC::CPalDC(int type)
  51. {
  52. switch (type) {
  53. case SCREEN_DC:
  54. hdc = CreateDC(txtDisplay, NULL, NULL, NULL);
  55. break;
  56. case SCREEN_IC:
  57. hdc = CreateIC(txtDisplay, NULL, NULL, NULL);
  58. break;
  59. default:
  60. ASSERT(type == SCREEN_DC);
  61. break;
  62. }
  63. ASSERT(hdc);
  64. if (!hdc)
  65. return; // out of system resources
  66. hwndDC = NULL;
  67. hpal = NULL;
  68. hbmp = NULL;
  69. hbrCreated = NULL;
  70. hbr = NULL;
  71. hbmpOrg = NULL;
  72. }
  73. CPalDC::~CPalDC(void)
  74. {
  75. if (hpal)
  76. SelectPalette(hdc, hpal, FALSE);
  77. if (hbmp)
  78. VERIFY(SelectObject(hdc, hbmp));
  79. if (hbr)
  80. VERIFY(SelectObject(hdc, hbr));
  81. if (hwndDC)
  82. ReleaseDC(hwndDC, hdc);
  83. else
  84. DeleteDC(hdc);
  85. if (hbrCreated)
  86. DeleteObject(hbrCreated);
  87. }
  88. void STDCALL CPalDC::SelectPal(HPALETTE hpalSel)
  89. {
  90. if (hpalSel) {
  91. if (hpal) // hpal is set once, and only once
  92. SelectPalette(hdc, hpalSel, FALSE);
  93. else
  94. hpal = SelectPalette(hdc, hpalSel, FALSE);
  95. RealizePalette(hdc);
  96. }
  97. else if (hpal) {
  98. SelectPalette(hdc, hpal, FALSE);
  99. hpal = NULL;
  100. }
  101. }
  102. void STDCALL CPalDC::SelectBitmap(HBITMAP hbmpSel)
  103. {
  104. if (hbmpSel) {
  105. hbmpOrg = hbmpSel;
  106. if (hbmp) // hbmp is set once, and only once
  107. SelectObject(hdc, hbmpSel);
  108. else
  109. VERIFY((hbmp = (HBITMAP) SelectObject(hdc, hbmpSel)));
  110. }
  111. else if (hbmp) {
  112. SelectObject(hdc, hbmp);
  113. hbmp = NULL;
  114. }
  115. }
  116. void STDCALL CPalDC::SelectBrush(HBRUSH hbrSel)
  117. {
  118. if (hbrSel) {
  119. if (hbr) // hbr is set once, and only once
  120. SelectObject(hdc, hbrSel);
  121. else
  122. VERIFY((hbr = (HBRUSH) SelectObject(hdc, hbrSel)));
  123. }
  124. else if (hbr) {
  125. SelectObject(hdc, hbr);
  126. hbr = NULL;
  127. }
  128. }
  129. void STDCALL CPalDC::SelectBrush(COLORREF clr)
  130. {
  131. hbrCreated = CreateSolidBrush(clr);
  132. SelectBrush(hbrCreated);
  133. }
  134. void STDCALL CPalDC::DeleteBrush(void)
  135. {
  136. ASSERT(hbrCreated);
  137. SelectBrush((HBRUSH) NULL);
  138. DeleteObject(hbrCreated);
  139. hbrCreated = NULL;
  140. }
  141. void STDCALL CPalDC::DeleteBmp(void)
  142. {
  143. if (hbmp)
  144. SelectObject(hdc, hbmp);
  145. if (hbmpOrg)
  146. DeleteObject(hbmpOrg);
  147. hbmp = NULL;
  148. }
  149. BOOL STDCALL CPalDC::BitBlt(CPalDC* pSrcDC, int xSrc,
  150. int ySrc, DWORD dwRop)
  151. {
  152. BITMAP bmp;
  153. GetObject(hbmpOrg, sizeof(BITMAP), &bmp);
  154. return ::BitBlt(hdc, 0, 0, bmp.bmWidth, bmp.bmHeight, pSrcDC->hdc,
  155. xSrc, ySrc, dwRop);
  156. }
  157. HBITMAP STDCALL CPalDC::CreateCompatibleBitmap(void)
  158. {
  159. BITMAP bmp;
  160. GetObject(hbmpOrg, sizeof(BITMAP), &bmp);
  161. return ::CreateCompatibleBitmap(hdc, bmp.bmWidth, bmp.bmHeight);
  162. }
  163. void STDCALL CPalDC::FillRect(RECT* prc, COLORREF clr)
  164. {
  165. HBRUSH hbr = CreateSolidBrush(clr);
  166. ::FillRect(hdc, prc, hbr);
  167. DeleteObject(hbr);
  168. }
  169. int CPalDC::GetXAsepect(void)
  170. {
  171. return MulDiv(GetDeviceWidth(), 1000, GetDeviceCaps(hdc, HORZSIZE));
  172. }
  173. int CPalDC::GetYAsepect(void)
  174. {
  175. return MulDiv(GetDeviceHeight(), 1000, GetDeviceCaps(hdc, VERTSIZE));
  176. }