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.

208 lines
5.3 KiB

  1. //
  2. // maskbmp.cpp
  3. //
  4. #include "private.h"
  5. #include "globals.h"
  6. #include "maskbmp.h"
  7. extern HINSTANCE g_hInst;
  8. //
  9. // from CUILIB.LIB
  10. //
  11. extern CBitmapDC *g_phdcSrc;
  12. extern CBitmapDC *g_phdcMask;
  13. extern CBitmapDC *g_phdcDst;
  14. //////////////////////////////////////////////////////////////////////////////
  15. //
  16. // misc func
  17. //
  18. //////////////////////////////////////////////////////////////////////////////
  19. //+---------------------------------------------------------------------------
  20. //
  21. // StretchIcon
  22. //
  23. //----------------------------------------------------------------------------
  24. HICON StretchIcon(HICON hIcon, int cxNew, int cyNew)
  25. {
  26. BITMAP bmp;
  27. ICONINFO ii;
  28. HICON hIconRet = NULL;
  29. GetIconInfo(hIcon, &ii);
  30. GetObject(ii.hbmMask, sizeof(BITMAP), &bmp);
  31. if ((bmp.bmWidth == cxNew) && (bmp.bmHeight == cyNew))
  32. {
  33. hIconRet = (HICON)CopyImage(hIcon,
  34. IMAGE_ICON,
  35. cxNew, cyNew,
  36. LR_COPYFROMRESOURCE);
  37. goto Exit;
  38. }
  39. g_phdcDst->SetDIB(cxNew, cyNew);
  40. g_phdcSrc->SetDIB(bmp.bmWidth, bmp.bmHeight);
  41. DrawIconEx(*g_phdcSrc, 0, 0, hIcon, bmp.bmWidth, bmp.bmHeight, 0, NULL, DI_IMAGE);
  42. SetStretchBltMode(*g_phdcDst, HALFTONE);
  43. StretchBlt(*g_phdcDst, 0, 0, cxNew, cyNew,
  44. *g_phdcSrc, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
  45. g_phdcSrc->Uninit();
  46. g_phdcSrc->SetBitmap(bmp.bmWidth, bmp.bmHeight, 1, 1);
  47. g_phdcMask->SetBitmap(cxNew, cyNew, 1, 1);
  48. DrawIconEx(*g_phdcSrc, 0, 0, hIcon, bmp.bmWidth, bmp.bmHeight, 0, NULL, DI_MASK);
  49. StretchBlt(*g_phdcMask, 0, 0, cxNew, cyNew,
  50. *g_phdcSrc, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
  51. ii.fIcon = TRUE;
  52. ii.xHotspot = 0;
  53. ii.yHotspot = 0;
  54. DeleteObject(ii.hbmMask);
  55. DeleteObject(ii.hbmColor);
  56. ii.hbmMask = g_phdcMask->GetBitmapAndKeep();
  57. ii.hbmColor = g_phdcDst->GetBitmapAndKeep();
  58. g_phdcMask->Uninit();
  59. g_phdcDst->Uninit();
  60. g_phdcSrc->Uninit();
  61. hIconRet= CreateIconIndirect(&ii);
  62. Exit:
  63. DeleteObject(ii.hbmMask);
  64. DeleteObject(ii.hbmColor);
  65. return hIconRet;
  66. }
  67. //////////////////////////////////////////////////////////////////////////////
  68. //
  69. // CMaskBitmap
  70. //
  71. //////////////////////////////////////////////////////////////////////////////
  72. //+---------------------------------------------------------------------------
  73. //
  74. // Init
  75. //
  76. //----------------------------------------------------------------------------
  77. BOOL CMaskBitmap::Init(int nId, int cx, int cy, COLORREF rgb)
  78. {
  79. Clear();
  80. CSolidBrush hbrFore(rgb);
  81. HBRUSH hbrBlack = (HBRUSH)GetStockObject(BLACK_BRUSH);
  82. HBRUSH hbrWhite = (HBRUSH)GetStockObject(WHITE_BRUSH);
  83. RECT rc;
  84. g_phdcMask->SetBitmap(cx, cy, 1, 1);
  85. g_phdcDst->SetDIB(cx, cy);
  86. g_phdcSrc->SetBitmapFromRes(g_hInst, MAKEINTRESOURCE(nId));
  87. ::SetRect(&rc, 0, 0, cx, cy);
  88. FillRect(*g_phdcDst, &rc, hbrBlack);
  89. FillRect(*g_phdcMask, &rc, hbrWhite);
  90. //
  91. // draw caps bitmap
  92. //
  93. // src
  94. ::SetRect(&rc, 0, 0, cx, cy);
  95. FillRect(*g_phdcDst, &rc, hbrFore);
  96. BitBlt(*g_phdcDst, 0, 0, cx, cy,
  97. *g_phdcSrc, 0, 0, SRCAND);
  98. // mask
  99. BitBlt(*g_phdcMask, 0, 0, cx, cy,
  100. *g_phdcSrc, 0, 0, SRCINVERT);
  101. g_phdcSrc->Uninit();
  102. g_phdcMask->Uninit(TRUE);
  103. g_phdcDst->Uninit(TRUE);
  104. _hbmp = g_phdcDst->GetBitmapAndKeep();
  105. _hbmpMask = g_phdcMask->GetBitmapAndKeep();
  106. DeleteObject(hbrBlack);
  107. DeleteObject(hbrWhite);
  108. return TRUE;
  109. }
  110. //+---------------------------------------------------------------------------
  111. //
  112. // Init
  113. //
  114. //----------------------------------------------------------------------------
  115. BOOL CMaskBitmap::Init(HICON hIcon, int cx, int cy, COLORREF rgb)
  116. {
  117. Clear();
  118. CSolidBrush hbrFore(rgb);
  119. HBRUSH hbrBlack = (HBRUSH)GetStockObject(BLACK_BRUSH);
  120. HBRUSH hbrWhite = (HBRUSH)GetStockObject(WHITE_BRUSH);
  121. RECT rc;
  122. g_phdcMask->SetBitmap(cx, cy, 1, 1);
  123. g_phdcDst->SetDIB(cx, cy);
  124. g_phdcSrc->SetDIB(cx, cy);
  125. //
  126. // flip mask of Icon.
  127. //
  128. DrawIconEx(*g_phdcDst, 0, 0, hIcon, cx, cy, 0, NULL, DI_MASK);
  129. ::SetRect(&rc, 0, 0, cx, cy);
  130. FillRect(*g_phdcSrc, &rc, hbrWhite);
  131. BitBlt(*g_phdcSrc, 0, 0, cx, cy, *g_phdcDst, 0, 0, SRCINVERT);
  132. //
  133. // draw caps bitmap
  134. //
  135. //
  136. // src
  137. //
  138. ::SetRect(&rc, 0, 0, cx, cy);
  139. FillRect(*g_phdcDst, &rc, hbrFore);
  140. BitBlt(*g_phdcDst, 0, 0, cx, cy, *g_phdcSrc, 0, 0, SRCAND);
  141. //
  142. // mask
  143. //
  144. ::SetRect(&rc, 0, 0, cx, cy);
  145. FillRect(*g_phdcMask, &rc, hbrWhite);
  146. BitBlt(*g_phdcMask, 0, 0, cx, cy, *g_phdcSrc, 0, 0, SRCINVERT);
  147. //
  148. // Draw white area for image.
  149. //
  150. FillRect(*g_phdcSrc, &rc, hbrBlack);
  151. DrawIconEx(*g_phdcSrc, 0, 0, hIcon, cx, cy, 0, NULL, DI_IMAGE);
  152. BitBlt(*g_phdcDst, 0, 0, cx, cy, *g_phdcSrc, 0, 0, SRCPAINT);
  153. g_phdcSrc->Uninit();
  154. g_phdcMask->Uninit(TRUE);
  155. g_phdcDst->Uninit(TRUE);
  156. _hbmp = g_phdcDst->GetBitmapAndKeep();
  157. _hbmpMask = g_phdcMask->GetBitmapAndKeep();
  158. DeleteObject(hbrBlack);
  159. DeleteObject(hbrWhite);
  160. return TRUE;
  161. }