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.

157 lines
3.0 KiB

  1. /*
  2. * @doc INTERNAL
  3. *
  4. * @module OSDC.CPP -- Off Screen DC class |
  5. *
  6. * This contains method used to implement the off screen
  7. * DC class
  8. *
  9. * Owner:<nl>
  10. * Rick Sailor
  11. *
  12. * Copyright (c) 1995-2000, Microsoft Corporation. All rights reserved.
  13. */
  14. #include "_common.h"
  15. #include "_osdc.h"
  16. ASSERTDATA
  17. /*
  18. * COffscreenDC::GetDimensions(pdx, pdy)
  19. *
  20. * @mfunc
  21. * return the current height of the osdc
  22. *
  23. * @rdesc
  24. * height of the osdc
  25. */
  26. void COffscreenDC::GetDimensions(long *pdx, long *pdy)
  27. {
  28. Assert(_hbmp);
  29. BITMAP bitmap;
  30. W32->GetObject(_hbmp, sizeof(BITMAP), &bitmap);
  31. *pdx = bitmap.bmWidth;
  32. *pdy = bitmap.bmHeight;
  33. }
  34. /*
  35. * COffscreenDC::Init(hdc, xWidth, yHeight, crBackground)
  36. *
  37. * @mfunc
  38. * Initialize off screen DC with compatible bitmap
  39. *
  40. * @rdesc
  41. * HDC created
  42. */
  43. HDC COffscreenDC::Init(
  44. HDC hdc, //@parm DC to be compatible with
  45. LONG xWidth, //@parm Width of compatible bitmap
  46. LONG yHeight, //@parm Height of compatible bitmap
  47. COLORREF crBackground) //@parm Default background for bitmap
  48. {
  49. if (_hdc)
  50. return _hdc;
  51. HDC hdcRet = NULL; // HDC to return to caller
  52. _hbmpOld = NULL; // Assume failure
  53. _hbmp = NULL;
  54. _hpalOld = NULL;
  55. // Create memory DC
  56. _hdc = CreateCompatibleDC(hdc);
  57. if(_hdc)
  58. {
  59. // Create bitmap based on size of client rectangle
  60. _hbmp = CreateCompatibleBitmap(hdc, xWidth, yHeight);
  61. if(_hbmp)
  62. {
  63. // Select bitmap into hdc
  64. _hbmpOld = (HBITMAP)SelectObject(_hdc, _hbmp);
  65. if(_hbmpOld && SetBkColor(_hdc, crBackground) != CLR_INVALID)
  66. hdcRet = _hdc;
  67. }
  68. }
  69. if(!hdcRet)
  70. FreeData();
  71. return hdcRet;
  72. }
  73. /*
  74. * COffscreenDC::SelectPalette(hpal)
  75. *
  76. * @mfunc
  77. * Set a new palette into the hdc
  78. */
  79. void COffscreenDC::SelectPalette(
  80. HPALETTE hpal) //@parm Handle to palette to set
  81. {
  82. #ifndef NOPALETTE
  83. if(hpal)
  84. {
  85. _hpalOld = ::SelectPalette(_hdc, hpal, TRUE);
  86. RealizePalette(_hdc);
  87. }
  88. #endif
  89. }
  90. /*
  91. * COffscreenDC::FreeData()
  92. *
  93. * @mfunc
  94. * Free resources associated with bitmap
  95. */
  96. void COffscreenDC::FreeData()
  97. {
  98. if(_hdc)
  99. {
  100. #ifndef NOPALETTE
  101. if(_hpalOld)
  102. ::SelectPalette(_hdc, _hpalOld, TRUE);
  103. #endif
  104. if(_hbmpOld)
  105. SelectObject(_hdc, _hbmpOld);
  106. if(_hbmp)
  107. {
  108. DeleteObject(_hbmp);
  109. _hbmp = NULL;
  110. }
  111. DeleteDC(_hdc);
  112. _hdc = NULL;
  113. }
  114. }
  115. /*
  116. * COffscreenDC::Realloc(xWidth, yHeight)
  117. *
  118. * @mfunc
  119. * Reallocate bitmap
  120. *
  121. * @rdesc
  122. * TRUE - succeeded
  123. * FALSE - failed
  124. */
  125. BOOL COffscreenDC::Realloc(
  126. LONG xWidth, //@parm Width of new bitmap
  127. LONG yHeight) //@parm Height of new bitmap
  128. {
  129. // Create bitmap based on size of client rectangle
  130. HBITMAP hbmpNew = CreateCompatibleBitmap(_hdc, xWidth, yHeight);
  131. if(!hbmpNew)
  132. {
  133. AssertSz(FALSE, "COffscreenDC::Realloc CreateCompatibleBitmap failed");
  134. return FALSE;
  135. }
  136. SelectObject(_hdc, hbmpNew);
  137. // Delete old bitmap
  138. DeleteObject(_hbmp);
  139. // Put in new bitmap
  140. _hbmp = hbmpNew;
  141. return TRUE;
  142. }