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.

112 lines
2.7 KiB

  1. //
  2. // maskbmp.h
  3. //
  4. #ifndef MASKBMP_H
  5. #define MASKBMP_H
  6. #include "cmydc.h"
  7. extern HINSTANCE g_hInst;
  8. class CMaskBitmap
  9. {
  10. public:
  11. CMaskBitmap(HBITMAP hBmp)
  12. {
  13. BITMAP bmp;
  14. _hbmpOrg = hBmp;
  15. int nRet = GetObject(hBmp,sizeof(BITMAP), &bmp);
  16. Assert(nRet);
  17. _cx = bmp.bmWidth;
  18. _cy = bmp.bmHeight;
  19. _hbmp = NULL;
  20. _hbmpMask = NULL;
  21. }
  22. ~CMaskBitmap()
  23. {
  24. // Clear();
  25. }
  26. void Clear()
  27. {
  28. if (_hbmp)
  29. {
  30. DeleteObject(_hbmp);
  31. _hbmp = NULL;
  32. }
  33. if (_hbmpMask)
  34. {
  35. DeleteObject(_hbmpMask);
  36. _hbmpMask = NULL;
  37. }
  38. }
  39. BOOL Init(COLORREF rgb)
  40. {
  41. Clear();
  42. CBitmapDC hdcSrc(TRUE);
  43. CBitmapDC hdcDst(TRUE);
  44. CBitmapDC hdcMask(TRUE);
  45. CBitmapDC hdcMask2(TRUE);
  46. CSolidBrush hbrFore(rgb);
  47. HBRUSH hbrBlack = (HBRUSH)GetStockObject(BLACK_BRUSH);
  48. HBRUSH hbrWhite = (HBRUSH)GetStockObject(WHITE_BRUSH);
  49. DWORD DSPDxax;
  50. DSPDxax = 0x00E20746L;
  51. COLORREF crBLACK = RGB(0,0,0);
  52. COLORREF crWHITE = RGB(255,255,255);
  53. hdcMask.SetBitmap(_cx, _cy, 1, 1);
  54. hdcDst.SetCompatibleBitmap(_cx, _cy);
  55. hdcSrc.SetBitmap(_hbmpOrg);
  56. // Generate mask to mask background color of original bitmap. WHITE
  57. BitBlt(hdcDst, 0, 0, _cx, _cy,hdcSrc, 0, 0, SRCCOPY);
  58. SetBkColor(hdcDst, crWHITE);
  59. BitBlt(hdcMask, 0, 0, _cx, _cy, hdcDst, 0, 0, SRCCOPY);
  60. _hbmpMask = hdcMask.GetBitmapAndKeep();
  61. // Generate mask to mask the foreground color of original bitmap: BLACK
  62. hdcMask2.SetBitmap(_cx, _cy, 1, 1);
  63. SetBkColor(hdcDst, crBLACK);
  64. BitBlt(hdcMask2, 0, 0, _cx, _cy, hdcDst, 0, 0, SRCCOPY);
  65. // Change the original foreground color to specified rgb
  66. SelectObject(hdcDst, hbrFore);
  67. SetBkColor(hdcDst, crWHITE);
  68. BitBlt(hdcDst, 0, 0, _cx, _cy, hdcMask2, 0, 0, DSPDxax);
  69. // Change the original background WHITE color to BLACK to meet CUILIB's requirement.
  70. SelectObject(hdcDst, hbrBlack);
  71. SetBkColor(hdcDst, crWHITE);
  72. BitBlt(hdcDst, 0, 0, _cx, _cy, hdcMask, 0, 0, DSPDxax);
  73. _hbmp = hdcDst.GetBitmapAndKeep();
  74. DeleteObject(hbrBlack);
  75. DeleteObject(hbrWhite);
  76. return TRUE;
  77. }
  78. HBITMAP GetBmp() {return _hbmp;}
  79. HBITMAP GetBmpMask() {return _hbmpMask;}
  80. private:
  81. int _cx;
  82. int _cy;
  83. HBITMAP _hbmpOrg;
  84. HBITMAP _hbmp;
  85. HBITMAP _hbmpMask;
  86. };
  87. #endif // MASKBMP_H