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.

123 lines
3.2 KiB

  1. /* @doc INTERNAL
  2. *
  3. * @module _OSDC.H Off Screen DC class |
  4. *
  5. * Define class for off screen DC
  6. *
  7. * Original Author: <nl>
  8. * Ricksa
  9. *
  10. * History: <nl>
  11. * 1/11/96 ricksa Created
  12. *
  13. * Copyright (c) 1996-1998, Microsoft Corporation. All rights reserved.
  14. */
  15. #ifndef __OSDC_H__
  16. #define __OSDC_H__
  17. /*
  18. * COffScreenDC
  19. *
  20. * @class The COffScreenDC is a helper that creates, fills and destroys
  21. * an off screen DC and its bitmaps.
  22. *
  23. */
  24. class COffScreenDC
  25. {
  26. //@access Public Methods
  27. public:
  28. //@cmember Constructor - create null object.
  29. COffScreenDC() {_hdc = NULL;}
  30. //@cmember Destructor - clean up allocated
  31. // resources if any.
  32. ~COffScreenDC() {FreeData();}
  33. //@cmember Initialize data based on input DC
  34. HDC Init(HDC hdc, LONG xWidth, LONG yHeight, COLORREF crBackground);
  35. //@cmember Get DC for offscreen rendering
  36. HDC GetDC() {return _hdc;}
  37. //@cmember Fill bitmap associated with off
  38. // screen rendering with background color.
  39. void FillBitmap(LONG xWidth, LONG yHeight);
  40. //@cmember Render off screen bitmap to hdc
  41. void RenderBitMap(HDC hdc, LONG xLeft, LONG yTop, LONG xWidth, LONG yHeight);
  42. //@cmember Get a copy of a bitmap from hdc
  43. BOOL Get(HDC hdc, LONG xLeft, LONG yTop, LONG xWidth, LONG yHeight);
  44. //@cmember Reallocate bitmap for render
  45. BOOL Realloc(LONG xWidth, LONG yHeight);
  46. //@cmember Select in a palette
  47. void SelectPalette(HPALETTE hpa);
  48. //@access Private Methods
  49. private:
  50. //@cmember Free all data associated with object
  51. void FreeData();
  52. //@access Private Data
  53. private:
  54. HDC _hdc; //@cmember HDC for off screen DC
  55. HBITMAP _hbmpOld; //@cmember bitmap when DC created
  56. HBITMAP _hbmp; //@cmember compatible bitmap for render
  57. HPALETTE _hpalOld; //@cmember palette used by DC
  58. };
  59. /*
  60. * COffScreenDC::FillBitmap (xWidth, yHeight)
  61. *
  62. * @mfunc
  63. * Fill bitmap
  64. */
  65. inline void COffScreenDC::FillBitmap(
  66. LONG xWidth, //@parm Width to fill with background color
  67. LONG yHeight) //@parm height to fill with background color
  68. {
  69. // Erase background
  70. RECT rcClient;
  71. rcClient.top = rcClient.left = 0;
  72. rcClient.right = xWidth;
  73. rcClient.bottom = yHeight;
  74. ExtTextOut(_hdc, 0, 0, ETO_OPAQUE, &rcClient, NULL, 0, NULL);
  75. }
  76. /*
  77. * COffScreenDC::RenderBitMap(hdc, xLeft, yTop, xWidth, yHeight)
  78. *
  79. * @mfunc
  80. * Render bitmap to input DC
  81. */
  82. inline void COffScreenDC::RenderBitMap(
  83. HDC hdc, //@parm HDC to render to
  84. LONG xLeft, //@parm left position to start render
  85. LONG yTop, //@parm top top position to start render
  86. LONG xWidth, //@parm width to render
  87. LONG yHeight) //@parm height to render
  88. {
  89. BitBlt(hdc, xLeft, yTop, xWidth, yHeight, _hdc, 0, 0, SRCCOPY);
  90. }
  91. /*
  92. * COffScreenDC::Get(hdc, xLeft, yTop, xWidth, yHeight)
  93. *
  94. * @mfunc
  95. * Get a copy of a bitmap from another DC
  96. *
  97. * @rdesc
  98. * TRUE - succeeded
  99. * FALSE - Failed
  100. */
  101. inline BOOL COffScreenDC::Get(
  102. HDC hdc, //@parm HDC to copy from
  103. LONG xLeft, //@parm left position of source bitmap
  104. LONG yTop, //@parm top top position of source bitmap
  105. LONG xWidth, //@parm width of bitmap
  106. LONG yHeight) //@parm height to bitmap
  107. {
  108. return BitBlt(_hdc, 0, 0, xWidth, yHeight, hdc, xLeft, yTop, SRCCOPY);
  109. }
  110. #endif __OSDC_H__