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.

124 lines
3.4 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. void GetDimensions(LONG *pdxp, LONG *pdyp);//@cmember the dimensions of the bitmap
  38. //@cmember Fill bitmap associated with off
  39. // screen rendering with background color.
  40. void FillBitmap(LONG dxp, LONG dyp);
  41. //@cmember Render off screen bitmap to hdc
  42. void RenderBitMap(HDC hdc, LONG xLeft, LONG yTop, LONG xWidth, LONG yHeight);
  43. //@cmember Get a copy of a bitmap from hdc
  44. BOOL Get(HDC hdc, LONG xLeft, LONG yTop, LONG xWidth, LONG yHeight);
  45. //@cmember Reallocate bitmap for render
  46. BOOL Realloc(LONG xWidth, LONG yHeight);
  47. //@cmember Select in a palette
  48. void SelectPalette(HPALETTE hpa);
  49. //@access Private Methods
  50. private:
  51. //@cmember Free all data associated with object
  52. void FreeData();
  53. //@access Private Data
  54. private:
  55. HDC _hdc; //@cmember HDC for off screen DC
  56. HBITMAP _hbmpOld; //@cmember bitmap when DC created
  57. HBITMAP _hbmp; //@cmember compatible bitmap for render
  58. HPALETTE _hpalOld; //@cmember palette used by DC
  59. };
  60. /*
  61. * COffscreenDC::FillBitmap (xWidth, yHeight)
  62. *
  63. * @mfunc
  64. * Fill bitmap
  65. */
  66. inline void COffscreenDC::FillBitmap(
  67. LONG dxp, //@parm Width to fill with background color
  68. LONG dyp) //@parm height to fill with background color
  69. {
  70. // Erase background
  71. RECT rcClient;
  72. rcClient.top = rcClient.left = 0;
  73. rcClient.right = dxp;
  74. rcClient.bottom = dyp;
  75. ExtTextOut(_hdc, 0, 0, ETO_OPAQUE, &rcClient, NULL, 0, NULL);
  76. }
  77. /*
  78. * COffscreenDC::RenderBitMap(hdc, xLeft, yTop, xWidth, yHeight)
  79. *
  80. * @mfunc
  81. * Render bitmap to input DC
  82. */
  83. inline void COffscreenDC::RenderBitMap(
  84. HDC hdc, //@parm HDC to render to
  85. LONG xLeft, //@parm left position to start render
  86. LONG yTop, //@parm top top position to start render
  87. LONG xWidth, //@parm width to render
  88. LONG yHeight) //@parm height to render
  89. {
  90. BitBlt(hdc, xLeft, yTop, xWidth, yHeight, _hdc, 0, 0, SRCCOPY);
  91. }
  92. /*
  93. * COffscreenDC::Get(hdc, xLeft, yTop, xWidth, yHeight)
  94. *
  95. * @mfunc
  96. * Get a copy of a bitmap from another DC
  97. *
  98. * @rdesc
  99. * TRUE - succeeded
  100. * FALSE - Failed
  101. */
  102. inline BOOL COffscreenDC::Get(
  103. HDC hdc, //@parm HDC to copy from
  104. LONG xLeft, //@parm left position of source bitmap
  105. LONG yTop, //@parm top top position of source bitmap
  106. LONG xWidth, //@parm width of bitmap
  107. LONG yHeight) //@parm height to bitmap
  108. {
  109. return BitBlt(_hdc, 0, 0, xWidth, yHeight, hdc, xLeft, yTop, SRCCOPY);
  110. }
  111. #endif __OSDC_H__