PPDrawManager.cpp
上传用户:dengkfang
上传日期:2008-12-30
资源大小:5233k
文件大小:46k
源码类别:

CA认证

开发平台:

Visual C++

  1. #include "stdafx.h"
  2. #include "PPDrawManager.h"
  3. /*
  4. #ifdef _DEBUG
  5. #undef THIS_FILE
  6. static char THIS_FILE[]=__FILE__;
  7. #define new DEBUG_NEW
  8. #endif
  9. */
  10. /*
  11. DIBs use RGBQUAD format:
  12. 0xbb 0xgg 0xrr 0x00
  13. */
  14. #ifndef CLR_TO_RGBQUAD
  15. #define CLR_TO_RGBQUAD(clr)     (RGB(GetBValue(clr), GetGValue(clr), GetRValue(clr)))
  16. #endif
  17. //////////////////////////////////////////////////////////////////////
  18. // Construction/Destruction
  19. //////////////////////////////////////////////////////////////////////
  20. CPPDrawManager::CPPDrawManager()
  21. {
  22. }
  23. CPPDrawManager::~CPPDrawManager()
  24. {
  25. }
  26. void CPPDrawManager::GetSizeOfIcon(HICON hIcon, LPSIZE pSize) const
  27. {
  28. pSize->cx = 0;
  29. pSize->cy = 0;
  30. if (hIcon != NULL)
  31. {
  32. ICONINFO ii;
  33. // Gets icon dimension
  34. ::ZeroMemory(&ii, sizeof(ICONINFO));
  35. if (::GetIconInfo(hIcon, &ii))
  36. {
  37. pSize->cx = (DWORD)(ii.xHotspot * 2);
  38. pSize->cy = (DWORD)(ii.yHotspot * 2);
  39. //release icon mask bitmaps
  40. if(ii.hbmMask)
  41. ::DeleteObject(ii.hbmMask);
  42. if(ii.hbmColor)
  43. ::DeleteObject(ii.hbmColor);
  44. } //if
  45. } //if
  46. } //End GetSizeOfIcon
  47. void CPPDrawManager::GetSizeOfBitmap(HBITMAP hBitmap, LPSIZE pSize) const
  48. {
  49. pSize->cx = 0;
  50. pSize->cy = 0;
  51. if (hBitmap != NULL)
  52. {
  53. BITMAP csBitmapSize;
  54. // Get bitmap size
  55. int nRetValue = ::GetObject(hBitmap, sizeof(csBitmapSize), &csBitmapSize);
  56. if (nRetValue)
  57. {
  58. pSize->cx = (DWORD)csBitmapSize.bmWidth;
  59. pSize->cy = (DWORD)csBitmapSize.bmHeight;
  60. } //if
  61. } //if
  62. } //End GetSizeOfBitmap
  63. void CPPDrawManager::AlphaBitBlt(HDC hDestDC, int nDestX, int nDestY, DWORD dwWidth, DWORD dwHeight, HDC hSrcDC, int nSrcX, int nSrcY, int percent /* = 100 */)
  64. {
  65. _ASSERT ((NULL != hDestDC) || (NULL != hSrcDC));
  66. if (percent >= 100)
  67. {
  68. ::BitBlt(hDestDC, nDestX, nDestY, dwWidth, dwHeight, hSrcDC, nSrcX, nSrcY, SRCCOPY);
  69. return;
  70. } //if
  71. HDC hTempDC = ::CreateCompatibleDC(hDestDC);
  72. if (NULL == hTempDC)
  73. return;
  74. //Creates Source DIB
  75. LPBITMAPINFO lpbiSrc;
  76. // Fill in the BITMAPINFOHEADER
  77. lpbiSrc = (LPBITMAPINFO) new BYTE[sizeof(BITMAPINFOHEADER)];
  78. lpbiSrc->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  79. lpbiSrc->bmiHeader.biWidth = dwWidth;
  80. lpbiSrc->bmiHeader.biHeight = dwHeight;
  81. lpbiSrc->bmiHeader.biPlanes = 1;
  82. lpbiSrc->bmiHeader.biBitCount = 32;
  83. lpbiSrc->bmiHeader.biCompression = BI_RGB;
  84. lpbiSrc->bmiHeader.biSizeImage = dwWidth * dwHeight;
  85. lpbiSrc->bmiHeader.biXPelsPerMeter = 0;
  86. lpbiSrc->bmiHeader.biYPelsPerMeter = 0;
  87. lpbiSrc->bmiHeader.biClrUsed = 0;
  88. lpbiSrc->bmiHeader.biClrImportant = 0;
  89. COLORREF* pSrcBits = NULL;
  90. HBITMAP hSrcDib = CreateDIBSection (
  91. hSrcDC, lpbiSrc, DIB_RGB_COLORS, (void **)&pSrcBits,
  92. NULL, NULL);
  93. if ((NULL != hSrcDib) && (NULL != pSrcBits))
  94. {
  95. HBITMAP hOldTempBmp = (HBITMAP)::SelectObject (hTempDC, hSrcDib);
  96. ::BitBlt (hTempDC, 0, 0, dwWidth, dwHeight, hSrcDC, nSrcX, nSrcY, SRCCOPY);
  97. ::SelectObject (hTempDC, hOldTempBmp);
  98. //Creates Destination DIB
  99. LPBITMAPINFO lpbiDest;
  100. // Fill in the BITMAPINFOHEADER
  101. lpbiDest = (LPBITMAPINFO) new BYTE[sizeof(BITMAPINFOHEADER)];
  102. lpbiDest->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  103. lpbiDest->bmiHeader.biWidth = dwWidth;
  104. lpbiDest->bmiHeader.biHeight = dwHeight;
  105. lpbiDest->bmiHeader.biPlanes = 1;
  106. lpbiDest->bmiHeader.biBitCount = 32;
  107. lpbiDest->bmiHeader.biCompression = BI_RGB;
  108. lpbiDest->bmiHeader.biSizeImage = dwWidth * dwHeight;
  109. lpbiDest->bmiHeader.biXPelsPerMeter = 0;
  110. lpbiDest->bmiHeader.biYPelsPerMeter = 0;
  111. lpbiDest->bmiHeader.biClrUsed = 0;
  112. lpbiDest->bmiHeader.biClrImportant = 0;
  113. COLORREF* pDestBits = NULL;
  114. HBITMAP hDestDib = CreateDIBSection (
  115. hDestDC, lpbiDest, DIB_RGB_COLORS, (void **)&pDestBits,
  116. NULL, NULL);
  117. if ((NULL != hDestDib) && (NULL != pDestBits))
  118. {
  119. ::SelectObject (hTempDC, hDestDib);
  120. ::BitBlt (hTempDC, 0, 0, dwWidth, dwHeight, hDestDC, nDestX, nDestY, SRCCOPY);
  121. ::SelectObject (hTempDC, hOldTempBmp);
  122. double src_darken = (double)percent / 100.0;
  123. double dest_darken = 1.0 - src_darken;
  124. for (DWORD pixel = 0; pixel < dwWidth * dwHeight; pixel++, pSrcBits++, pDestBits++)
  125. {
  126. *pDestBits = PixelAlpha(*pSrcBits, src_darken, *pDestBits, dest_darken);
  127. } //for
  128. ::SelectObject (hTempDC, hDestDib);
  129. ::BitBlt (hDestDC, nDestX, nDestY, dwWidth, dwHeight, hTempDC, 0, 0, SRCCOPY);
  130. ::SelectObject (hTempDC, hOldTempBmp);
  131. delete lpbiDest;
  132. ::DeleteObject(hDestDib);
  133. } //if
  134. delete lpbiSrc;
  135. ::DeleteObject(hSrcDib);
  136. } //if
  137. ::DeleteDC(hTempDC);
  138. } //End AlphaBitBlt
  139. void CPPDrawManager::AlphaChannelBitBlt(HDC hDestDC, int nDestX, int nDestY, DWORD dwWidth, DWORD dwHeight, HDC hSrcDC, int nSrcX, int nSrcY)
  140. {
  141. _ASSERT ((NULL != hDestDC) || (NULL != hSrcDC));
  142. HDC hTempDC = ::CreateCompatibleDC(hDestDC);
  143. if (NULL == hTempDC)
  144. return;
  145. //Creates Source DIB
  146. LPBITMAPINFO lpbiSrc;
  147. // Fill in the BITMAPINFOHEADER
  148. lpbiSrc = (LPBITMAPINFO) new BYTE[sizeof(BITMAPINFOHEADER)];
  149. lpbiSrc->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  150. lpbiSrc->bmiHeader.biWidth = dwWidth;
  151. lpbiSrc->bmiHeader.biHeight = dwHeight;
  152. lpbiSrc->bmiHeader.biPlanes = 1;
  153. lpbiSrc->bmiHeader.biBitCount = 32;
  154. lpbiSrc->bmiHeader.biCompression = BI_RGB;
  155. lpbiSrc->bmiHeader.biSizeImage = dwWidth * dwHeight;
  156. lpbiSrc->bmiHeader.biXPelsPerMeter = 0;
  157. lpbiSrc->bmiHeader.biYPelsPerMeter = 0;
  158. lpbiSrc->bmiHeader.biClrUsed = 0;
  159. lpbiSrc->bmiHeader.biClrImportant = 0;
  160. COLORREF* pSrcBits = NULL;
  161. HBITMAP hSrcDib = CreateDIBSection (
  162. hSrcDC, lpbiSrc, DIB_RGB_COLORS, (void **)&pSrcBits,
  163. NULL, NULL);
  164. if ((NULL != hSrcDib) && (NULL != pSrcBits))
  165. {
  166. HBITMAP hOldTempBmp = (HBITMAP)::SelectObject (hTempDC, hSrcDib);
  167. ::BitBlt (hTempDC, 0, 0, dwWidth, dwHeight, hSrcDC, nSrcX, nSrcY, SRCCOPY);
  168. ::SelectObject (hTempDC, hOldTempBmp);
  169. //Creates Destination DIB
  170. LPBITMAPINFO lpbiDest;
  171. // Fill in the BITMAPINFOHEADER
  172. lpbiDest = (LPBITMAPINFO) new BYTE[sizeof(BITMAPINFOHEADER)];
  173. lpbiDest->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  174. lpbiDest->bmiHeader.biWidth = dwWidth;
  175. lpbiDest->bmiHeader.biHeight = dwHeight;
  176. lpbiDest->bmiHeader.biPlanes = 1;
  177. lpbiDest->bmiHeader.biBitCount = 32;
  178. lpbiDest->bmiHeader.biCompression = BI_RGB;
  179. lpbiDest->bmiHeader.biSizeImage = dwWidth * dwHeight;
  180. lpbiDest->bmiHeader.biXPelsPerMeter = 0;
  181. lpbiDest->bmiHeader.biYPelsPerMeter = 0;
  182. lpbiDest->bmiHeader.biClrUsed = 0;
  183. lpbiDest->bmiHeader.biClrImportant = 0;
  184. COLORREF* pDestBits = NULL;
  185. HBITMAP hDestDib = CreateDIBSection (
  186. hDestDC, lpbiDest, DIB_RGB_COLORS, (void **)&pDestBits,
  187. NULL, NULL);
  188. if ((NULL != hDestDib) && (NULL != pDestBits))
  189. {
  190. ::SelectObject (hTempDC, hDestDib);
  191. ::BitBlt (hTempDC, 0, 0, dwWidth, dwHeight, hDestDC, nDestX, nDestY, SRCCOPY);
  192. ::SelectObject (hTempDC, hOldTempBmp);
  193. double src_darken;
  194. BYTE nAlpha;
  195. for (DWORD pixel = 0; pixel < dwWidth * dwHeight; pixel++, pSrcBits++, pDestBits++)
  196. {
  197. nAlpha = LOBYTE(*pSrcBits >> 24);
  198. src_darken = (double)nAlpha / 255.0;
  199. *pDestBits = PixelAlpha(*pSrcBits, src_darken, *pDestBits, 1.0 - src_darken);
  200. } //for
  201. ::SelectObject (hTempDC, hDestDib);
  202. ::BitBlt (hDestDC, nDestX, nDestY, dwWidth, dwHeight, hTempDC, 0, 0, SRCCOPY);
  203. ::SelectObject (hTempDC, hOldTempBmp);
  204. delete lpbiDest;
  205. ::DeleteObject(hDestDib);
  206. } //if
  207. delete lpbiSrc;
  208. ::DeleteObject(hSrcDib);
  209. } //if
  210. ::DeleteDC(hTempDC);
  211. } //End of AlphaChannelBitBlt
  212. HBITMAP CPPDrawManager::CreateImageEffect(HBITMAP hBitmap, DWORD dwWidth, DWORD dwHeight, DWORD dwEffect, BOOL bUseMask /* = TRUE */, COLORREF clrMask /* = RGB(255, 0, 255) */, COLORREF clrMono /* = RGB(255, 255, 255) */)
  213. {
  214. HBITMAP hOldSrcBmp = NULL;
  215. HBITMAP hOldResBmp = NULL;  
  216. HDC hMainDC = NULL;
  217. HDC hSrcDC = NULL;
  218. HDC hResDC = NULL;
  219. hMainDC = ::GetDC(NULL);
  220. hSrcDC = ::CreateCompatibleDC(hMainDC);
  221. hResDC = ::CreateCompatibleDC(hMainDC);
  222. hOldSrcBmp = (HBITMAP)::SelectObject(hSrcDC, hBitmap);
  223. LPBITMAPINFO lpbi;
  224. // Fill in the BITMAPINFOHEADER
  225. lpbi = (LPBITMAPINFO) new BYTE[sizeof(BITMAPINFOHEADER)];
  226. lpbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  227. lpbi->bmiHeader.biWidth = dwWidth;
  228. lpbi->bmiHeader.biHeight = dwHeight;
  229. lpbi->bmiHeader.biPlanes = 1;
  230. lpbi->bmiHeader.biBitCount = 32;
  231. lpbi->bmiHeader.biCompression = BI_RGB;
  232. lpbi->bmiHeader.biSizeImage = dwWidth * dwHeight;
  233. lpbi->bmiHeader.biXPelsPerMeter = 0;
  234. lpbi->bmiHeader.biYPelsPerMeter = 0;
  235. lpbi->bmiHeader.biClrUsed = 0;
  236. lpbi->bmiHeader.biClrImportant = 0;
  237. COLORREF* pBits = NULL;
  238. HBITMAP hDibBmp = CreateDIBSection (
  239. hSrcDC, lpbi, DIB_RGB_COLORS, (void **)&pBits,
  240. NULL, NULL);
  241. if (hDibBmp == NULL || pBits == NULL)
  242. {
  243. delete lpbi;
  244. _ASSERT (FALSE);
  245. return NULL;
  246. } //if
  247. hOldResBmp = (HBITMAP)::SelectObject (hResDC, hDibBmp);
  248. ::BitBlt (hResDC, 0, 0, dwWidth, dwHeight, hSrcDC, 0, 0, SRCCOPY);
  249. clrMask = CLR_TO_RGBQUAD(clrMask);
  250. clrMono = CLR_TO_RGBQUAD(clrMono);
  251. DWORD dwAlpha;
  252. for (DWORD pixel = 0; pixel < dwWidth * dwHeight; pixel++, *pBits++)
  253. {
  254. COLORREF color = (COLORREF)*pBits;
  255. //ENG: Extract an original alpha value
  256. dwAlpha = color & 0xFF000000;
  257. if (dwAlpha != 0) 
  258. m_bIsAlpha = TRUE;
  259. if (bUseMask && (color == clrMask))
  260. {
  261. //This is transparent area
  262. color = RGB(0, 0, 0);
  263. }
  264. else 
  265. {
  266. //ENG: Color conversion
  267. if (dwEffect & IMAGE_EFFECT_GRAYEN) color = GrayMirrorColor(color);
  268. if (dwEffect & IMAGE_EFFECT_DARKEN) color = DarkenColor(color, 0.75);
  269. if (dwEffect & IMAGE_EFFECT_LIGHTEN) color = LightenColor(color, 0.25);
  270. if (dwEffect & IMAGE_EFFECT_MONOCHROME) color = clrMono;
  271. } //if
  272. if (dwEffect & IMAGE_EFFECT_INVERT) color = InvertColor(color);
  273. //ENG: Merges a color with an original alpha value
  274. *pBits = (color | dwAlpha);
  275. } //for
  276. ::SelectObject(hSrcDC, hOldSrcBmp);
  277. ::SelectObject(hResDC, hOldResBmp);
  278. ::DeleteDC(hSrcDC);
  279. ::DeleteDC(hResDC);
  280. ::ReleaseDC(NULL, hMainDC);
  281. delete lpbi;
  282. return hDibBmp;
  283. } //End CreateImageEffect
  284. //----------------------------------------------------------
  285. // CPPDrawManager::GrayMirrorColor()
  286. // Graying color in RGBQUAD format
  287. //----------------------------------------------------------
  288. // Parameter:
  289. // clrColor - RGBQUAD value from DIB
  290. // Return value:
  291. // A grayed color in the RGBQUAD format
  292. //----------------------------------------------------------
  293. COLORREF CPPDrawManager::GrayMirrorColor(COLORREF clrColor)
  294. {
  295. BYTE nGrayColor = (BYTE)((GetBValue(clrColor) * 0.299) + (GetGValue(clrColor) * 0.587) + (GetRValue(clrColor) * 0.114));
  296. return RGB(nGrayColor, nGrayColor, nGrayColor);
  297. } //End of GrayMirrorColor
  298. COLORREF CPPDrawManager::GrayColor(COLORREF clrColor)
  299. {
  300. BYTE nGrayColor = (BYTE)((GetRValue(clrColor) * 0.299) + (GetGValue(clrColor) * 0.587) + (GetBValue(clrColor) * 0.114));
  301. return RGB(nGrayColor, nGrayColor, nGrayColor);
  302. } //End GrayColor
  303. COLORREF CPPDrawManager::InvertColor(COLORREF clrColor)
  304. {
  305. return RGB(255 - GetRValue(clrColor), 255 - GetGValue(clrColor), 255 - GetBValue(clrColor));
  306. } //End InvertColor
  307. COLORREF CPPDrawManager::DarkenColor(COLORREF clrColor, double darken)
  308. {
  309. if (darken >= 0.0 && darken < 1.0)
  310. {
  311. BYTE color_r, color_g, color_b;
  312. color_r = (BYTE)(GetRValue(clrColor) * darken);
  313. color_g = (BYTE)(GetGValue(clrColor) * darken);
  314. color_b = (BYTE)(GetBValue(clrColor) * darken);
  315. clrColor = RGB(color_r, color_g, color_b);
  316. } //if
  317. return clrColor;
  318. } //End DarkenColor
  319. COLORREF CPPDrawManager::LightenColor(COLORREF clrColor, double lighten)
  320. {
  321. if (lighten > 0.0 && lighten <= 1.0)
  322. {
  323. BYTE color_r, color_g, color_b;
  324. lighten += 1.0;
  325. color_r = (BYTE)min((DWORD)GetRValue(clrColor) * lighten, 255.0);
  326. color_g = (BYTE)min((DWORD)GetGValue(clrColor) * lighten, 255.0);
  327. color_b = (BYTE)min((DWORD)GetBValue(clrColor) * lighten, 255.0);
  328. clrColor = RGB(color_r, color_g, color_b);
  329. /*
  330. lighten *= 255
  331. color_r = (BYTE)max(0, min(255, (int)((color_r - 128) * 2.0 + 128 + lighten)));
  332. color_g = (BYTE)max(0, min(255, (int)((color_g - 128) * 2.0 + 128 + lighten)));
  333. color_b = (BYTE)max(0, min(255, (int)((color_b - 128) * 2.0 + 128 + lighten)));
  334. clrColor = RGB(color_r, color_g, color_b);
  335. */
  336. } //if
  337. return clrColor;
  338. } //End LightenColor
  339. COLORREF CPPDrawManager::PixelAlpha(COLORREF clrSrc, double src_darken, COLORREF clrDest, double dest_darken)
  340. {
  341. return RGB (GetRValue (clrSrc) * src_darken + GetRValue (clrDest) * dest_darken, 
  342. GetGValue (clrSrc) * src_darken + GetGValue (clrDest) * dest_darken, 
  343. GetBValue (clrSrc) * src_darken + GetBValue (clrDest) * dest_darken);
  344. } //End PixelAlpha
  345. HICON CPPDrawManager::StretchIcon(HICON hIcon, DWORD dwWidth, DWORD dwHeight)
  346. {
  347. HICON hStretchedIcon = NULL;
  348. HDC   hMainDC = NULL;
  349. HDC   hSrcDC = NULL;
  350. HDC   hDestDC = NULL;
  351. BITMAP bmp;
  352. HBITMAP hOldSrcBitmap = NULL;
  353. HBITMAP hOldDestBitmap = NULL;
  354. ICONINFO csOriginal, csStretched;
  355. if (!::GetIconInfo(hIcon, &csOriginal))
  356. return FALSE;
  357. hMainDC = ::GetDC(NULL);
  358. hSrcDC = ::CreateCompatibleDC(hMainDC);
  359. hDestDC = ::CreateCompatibleDC(hMainDC);
  360. if ((NULL == hMainDC) || (NULL == hSrcDC) || (NULL == hDestDC))
  361. return NULL;
  362. if (::GetObject(csOriginal.hbmColor, sizeof(BITMAP), &bmp))
  363. {
  364. DWORD dwWidthOrg = csOriginal.xHotspot * 2;
  365. DWORD dwHeightOrg = csOriginal.yHotspot * 2;
  366. csStretched.hbmColor = ::CreateBitmap(dwWidth, dwHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
  367. if (NULL != csStretched.hbmColor)
  368. {
  369. hOldSrcBitmap = (HBITMAP)::SelectObject(hSrcDC, csOriginal.hbmColor);
  370. hOldDestBitmap = (HBITMAP)::SelectObject(hDestDC, csStretched.hbmColor);
  371. ::StretchBlt(hDestDC, 0, 0, dwWidth, dwHeight, hSrcDC, 0, 0, dwWidthOrg, dwHeightOrg, SRCCOPY);
  372. if (::GetObject(csOriginal.hbmMask, sizeof(BITMAP), &bmp))
  373. {
  374. csStretched.hbmMask = ::CreateBitmap(dwWidth, dwHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
  375. if (NULL != csStretched.hbmMask)
  376. {
  377. ::SelectObject(hSrcDC, csOriginal.hbmMask);
  378. ::SelectObject(hDestDC, csStretched.hbmMask);
  379. ::StretchBlt(hDestDC, 0, 0, dwWidth, dwHeight, hSrcDC, 0, 0, dwWidthOrg, dwHeightOrg, SRCCOPY);
  380. } //if
  381. } //if
  382. ::SelectObject(hSrcDC, hOldSrcBitmap);
  383. ::SelectObject(hDestDC, hOldDestBitmap);
  384. csStretched.fIcon = TRUE;
  385. hStretchedIcon = ::CreateIconIndirect(&csStretched);
  386. } //if
  387. ::DeleteObject(csStretched.hbmColor);
  388. ::DeleteObject(csStretched.hbmMask);
  389. } //if
  390. ::DeleteObject(csOriginal.hbmColor);
  391. ::DeleteObject(csOriginal.hbmMask);
  392. ::DeleteDC(hSrcDC);
  393. ::DeleteDC(hDestDC);
  394. ::ReleaseDC(NULL, hMainDC);
  395. return hStretchedIcon;
  396. } //End StretchIcon
  397. void CPPDrawManager::FillGradient (HDC hDC, LPCRECT lpRect, 
  398. COLORREF colorStart, COLORREF colorFinish, 
  399. BOOL bHorz/* = TRUE*/)
  400. {
  401.     // this will make 2^6 = 64 fountain steps
  402.     int nShift = 6;
  403.     int nSteps = 1 << nShift;
  404. RECT r2;
  405. r2.top = lpRect->top;
  406. r2.left = lpRect->left;
  407. r2.right = lpRect->right;
  408. r2.bottom = lpRect->bottom;
  409. int nHeight = lpRect->bottom - lpRect->top;
  410. int nWidth = lpRect->right - lpRect->left;
  411. for (int i = 0; i < nSteps; i++)
  412.     {
  413.         // do a little alpha blending
  414.         BYTE bR = (BYTE) ((GetRValue(colorStart) * (nSteps - i) +
  415.                    GetRValue(colorFinish) * i) >> nShift);
  416.         BYTE bG = (BYTE) ((GetGValue(colorStart) * (nSteps - i) +
  417.                    GetGValue(colorFinish) * i) >> nShift);
  418.         BYTE bB = (BYTE) ((GetBValue(colorStart) * (nSteps - i) +
  419.                    GetBValue(colorFinish) * i) >> nShift);
  420. HBRUSH hBrush = ::CreateSolidBrush(RGB(bR, bG, bB));
  421.         // then paint with the resulting color
  422.         if (!bHorz)
  423.         {
  424.             r2.top = lpRect->top + ((i * nHeight) >> nShift);
  425.             r2.bottom = lpRect->top + (((i + 1) * nHeight) >> nShift);
  426.             if ((r2.bottom - r2.top) > 0)
  427.                 ::FillRect(hDC, &r2, hBrush);
  428.         }
  429.         else
  430.         {
  431.             r2.left = lpRect->left + ((i * nWidth) >> nShift);
  432.             r2.right = lpRect->left + (((i + 1) * nWidth) >> nShift);
  433.             if ((r2.right - r2.left) > 0)
  434.                 ::FillRect(hDC, &r2, hBrush);
  435.         } //if
  436. if (NULL != hBrush)
  437. {
  438. ::DeleteObject(hBrush);
  439. hBrush = NULL;
  440. } //if
  441.     } //for
  442. } //End FillGradient
  443. #ifdef USE_SHADE
  444. void CPPDrawManager::SetShade(LPCRECT lpRect, UINT shadeID /* = 0 */, BYTE granularity /* = 8 */, 
  445.   BYTE coloring /* = 0 */, COLORREF hicr /* = 0 */, COLORREF midcr /* = 0 */, COLORREF locr /* = 0 */)
  446. {
  447. long sXSize,sYSize,bytes,j,i,k,h;
  448. BYTE *iDst ,*posDst;
  449. sYSize = lpRect->bottom - lpRect->top; 
  450. sXSize = lpRect->right - lpRect->left; 
  451. m_dNormal.Create(sXSize,sYSize,8); //create the default bitmap
  452. long r,g,b; //build the shaded palette
  453. for(i = 0; i < 129; i++)
  454. {
  455. r=((128-i)*GetRValue(locr)+i*GetRValue(midcr))/128;
  456. g=((128-i)*GetGValue(locr)+i*GetGValue(midcr))/128;
  457. b=((128-i)*GetBValue(locr)+i*GetBValue(midcr))/128;
  458. m_dNormal.SetPaletteIndex((BYTE)i,(BYTE)r,(BYTE)g,(BYTE)b);
  459. } //for
  460. for(i=1;i<129;i++){
  461. r=((128-i)*GetRValue(midcr)+i*GetRValue(hicr))/128;
  462. g=((128-i)*GetGValue(midcr)+i*GetGValue(hicr))/128;
  463. b=((128-i)*GetBValue(midcr)+i*GetBValue(hicr))/128;
  464. m_dNormal.SetPaletteIndex((BYTE)(i+127),(BYTE)r,(BYTE)g,(BYTE)b);
  465. } //for
  466. m_dNormal.BlendPalette(hicr,coloring); //color the palette
  467. bytes = m_dNormal.GetLineWidth();
  468. iDst = m_dNormal.GetBits();
  469. posDst =iDst;
  470. long a,x,y,d,xs,idxmax,idxmin;
  471. int grainx2 = RAND_MAX/(max(1,2*granularity));
  472. idxmax=255-granularity;
  473. idxmin=granularity;
  474. switch (shadeID)
  475. {
  476. //----------------------------------------------------
  477. case EFFECT_METAL:
  478. m_dNormal.Clear();
  479. // create the strokes
  480. k=40; //stroke granularity
  481. for(a=0;a<200;a++){
  482. x=rand()/(RAND_MAX/sXSize); //stroke postion
  483. y=rand()/(RAND_MAX/sYSize); //stroke position
  484. xs=rand()/(RAND_MAX/min(sXSize,sYSize))/2; //stroke lenght
  485. d=rand()/(RAND_MAX/k); //stroke color
  486. for(i=0;i<xs;i++){
  487. if (((x-i)>0)&&((y+i)<sYSize))
  488. m_dNormal.SetPixelIndex(x-i,y+i,(BYTE)d);
  489. if (((x+i)<sXSize)&&((y-i)>0))
  490. m_dNormal.SetPixelIndex(sXSize-x+i,y-i,(BYTE)d);
  491. } //for
  492. } //for
  493. //blend strokes with SHS_DIAGONAL
  494. posDst =iDst;
  495. a=(idxmax-idxmin-k)/2;
  496. for(i = 0; i < sYSize; i++) {
  497. for(j = 0; j < sXSize; j++) {
  498. d=posDst[j]+((a*i)/sYSize+(a*(sXSize-j))/sXSize);
  499. posDst[j]=(BYTE)d;
  500. posDst[j]+=rand()/grainx2;
  501. } //for
  502. posDst+=bytes;
  503. } //for
  504. break;
  505. //----------------------------------------------------
  506. case EFFECT_HARDBUMP: // 
  507. //set horizontal bump
  508. for(i = 0; i < sYSize; i++) {
  509. k=(255*i/sYSize)-127;
  510. k=(k*(k*k)/128)/128;
  511. k=(k*(128-granularity*2))/128+128;
  512. for(j = 0; j < sXSize; j++) {
  513. posDst[j]=(BYTE)k;
  514. posDst[j]+=rand()/grainx2-granularity;
  515. } //for
  516. posDst+=bytes;
  517. } //for
  518. //set vertical bump
  519. d=min(16,sXSize/6); //max edge=16
  520. a=sYSize*sYSize/4;
  521. posDst =iDst;
  522. for(i = 0; i < sYSize; i++) {
  523. y=i-sYSize/2;
  524. for(j = 0; j < sXSize; j++) {
  525. x=j-sXSize/2;
  526. xs=sXSize/2-d+(y*y*d)/a;
  527. if (x>xs) posDst[j]=(BYTE)idxmin+(BYTE)(((sXSize-j)*128)/d);
  528. if ((x+xs)<0) posDst[j]=(BYTE)idxmax-(BYTE)((j*128)/d);
  529. posDst[j]+=rand()/grainx2-granularity;
  530. } //for
  531. posDst+=bytes;
  532. } //for
  533. break;
  534. //----------------------------------------------------
  535. case EFFECT_SOFTBUMP: //
  536. for(i = 0; i < sYSize; i++) {
  537. h=(255*i/sYSize)-127;
  538. for(j = 0; j < sXSize; j++) {
  539. k=(255*(sXSize-j)/sXSize)-127;
  540. k=(h*(h*h)/128)/128+(k*(k*k)/128)/128;
  541. k=k*(128-granularity)/128+128;
  542. if (k<idxmin) k=idxmin;
  543. if (k>idxmax) k=idxmax;
  544. posDst[j]=(BYTE)k;
  545. posDst[j]+=rand()/grainx2-granularity;
  546. } //for
  547. posDst+=bytes;
  548. } //for
  549. break;
  550. //----------------------------------------------------
  551. case EFFECT_VBUMP: // 
  552. for(j = 0; j < sXSize; j++) {
  553. k=(255*(sXSize-j)/sXSize)-127;
  554. k=(k*(k*k)/128)/128;
  555. k=(k*(128-granularity))/128+128;
  556. for(i = 0; i < sYSize; i++) {
  557. posDst[j+i*bytes]=(BYTE)k;
  558. posDst[j+i*bytes]+=rand()/grainx2-granularity;
  559. } //for
  560. } //for
  561. break;
  562. //----------------------------------------------------
  563. case EFFECT_HBUMP: //
  564. for(i = 0; i < sYSize; i++) {
  565. k=(255*i/sYSize)-127;
  566. k=(k*(k*k)/128)/128;
  567. k=(k*(128-granularity))/128+128;
  568. for(j = 0; j < sXSize; j++) {
  569. posDst[j]=(BYTE)k;
  570. posDst[j]+=rand()/grainx2-granularity;
  571. } //for
  572. posDst+=bytes;
  573. } //for
  574. break;
  575. //----------------------------------------------------
  576. case EFFECT_DIAGSHADE: //
  577. a=(idxmax-idxmin)/2;
  578. for(i = 0; i < sYSize; i++) {
  579. for(j = 0; j < sXSize; j++) {
  580. posDst[j]=(BYTE)(idxmin+a*i/sYSize+a*(sXSize-j)/sXSize);
  581. posDst[j]+=rand()/grainx2-granularity;
  582. } //for
  583. posDst+=bytes;
  584. } //for
  585. break;
  586. //----------------------------------------------------
  587. case EFFECT_HSHADE: //
  588. a=idxmax-idxmin;
  589. for(i = 0; i < sYSize; i++) {
  590. k=a*i/sYSize+idxmin;
  591. for(j = 0; j < sXSize; j++) {
  592. posDst[j]=(BYTE)k;
  593. posDst[j]+=rand()/grainx2-granularity;
  594. } //for
  595. posDst+=bytes;
  596. } //for
  597. break;
  598. //----------------------------------------------------
  599. case EFFECT_VSHADE: //:
  600. a=idxmax-idxmin;
  601. for(j = 0; j < sXSize; j++) {
  602. k=a*(sXSize-j)/sXSize+idxmin;
  603. for(i = 0; i < sYSize; i++) {
  604. posDst[j+i*bytes]=(BYTE)k;
  605. posDst[j+i*bytes]+=rand()/grainx2-granularity;
  606. } //for
  607. } //for
  608. break;
  609. //----------------------------------------------------
  610. case EFFECT_NOISE:
  611. for(i = 0; i < sYSize; i++) {
  612. for(j = 0; j < sXSize; j++) {
  613. posDst[j]=128+rand()/grainx2-granularity;
  614. } //for
  615. posDst+=bytes;
  616. } //for
  617. } //switch
  618. //----------------------------------------------------
  619. } //End SetShade
  620. #endif
  621. void CPPDrawManager::FillEffect(HDC hDC, DWORD dwEffect, LPCRECT lpRect, COLORREF clrBegin, COLORREF clrMid /* = 0 */, COLORREF clrEnd /* = 0 */,  BYTE granularity /* = 0 */, BYTE coloring /* = 0 */)
  622. {
  623. HBRUSH hBrush = NULL;
  624. RECT rect;
  625. rect.left = lpRect->left;
  626. rect.top = lpRect->top;
  627. rect.right = lpRect->right;
  628. rect.bottom = lpRect->bottom;
  629. int nHeight = rect.bottom - rect.top;
  630. int nWidth = rect.right - rect.left;
  631. switch (dwEffect)
  632. {
  633. default:
  634. hBrush = ::CreateSolidBrush(clrBegin);
  635. ::FillRect(hDC, lpRect, hBrush);
  636. break;
  637. case EFFECT_HGRADIENT:
  638. FillGradient(hDC, lpRect, clrBegin, clrEnd, TRUE);
  639. break;
  640. case EFFECT_VGRADIENT:
  641. FillGradient(hDC, lpRect, clrBegin, clrEnd, FALSE);
  642. break;
  643. case EFFECT_HCGRADIENT:
  644. rect.right = rect.left + nWidth / 2;
  645. FillGradient(hDC, &rect, clrBegin, clrEnd, TRUE);
  646. rect.left = rect.right;
  647. rect.right = lpRect->right;
  648. FillGradient(hDC, &rect, clrEnd, clrBegin, TRUE);
  649. break;
  650. case EFFECT_3HGRADIENT:
  651. rect.right = rect.left + nWidth / 2;
  652. FillGradient(hDC, &rect, clrBegin, clrMid, TRUE);
  653. rect.left = rect.right;
  654. rect.right = lpRect->right;
  655. FillGradient(hDC, &rect, clrMid, clrEnd, TRUE);
  656. break;
  657. case EFFECT_VCGRADIENT:
  658. rect.bottom = rect.top + nHeight / 2;
  659. FillGradient(hDC, &rect, clrBegin, clrEnd, FALSE);
  660. rect.top = rect.bottom;
  661. rect.bottom = lpRect->bottom;
  662. FillGradient(hDC, &rect, clrEnd, clrBegin, FALSE);
  663. break;
  664. case EFFECT_3VGRADIENT:
  665. rect.bottom = rect.top + nHeight / 2;
  666. FillGradient(hDC, &rect, clrBegin, clrMid, FALSE);
  667. rect.top = rect.bottom;
  668. rect.bottom = lpRect->bottom;
  669. FillGradient(hDC, &rect, clrMid, clrEnd, FALSE);
  670. break;
  671. #ifdef USE_SHADE
  672. case EFFECT_NOISE:
  673. case EFFECT_DIAGSHADE:
  674. case EFFECT_HSHADE:
  675. case EFFECT_VSHADE:
  676. case EFFECT_HBUMP:
  677. case EFFECT_VBUMP:
  678. case EFFECT_SOFTBUMP:
  679. case EFFECT_HARDBUMP:
  680. case EFFECT_METAL:
  681. rect.left = 0;
  682. rect.top = 0;
  683. rect.right = nWidth;
  684. rect.bottom = nHeight;
  685. SetShade(&rect, dwEffect, granularity, coloring, clrBegin, clrMid, clrEnd);
  686. m_dNormal.Draw(hDC, lpRect->left, lpRect->top);
  687. break; 
  688. #endif
  689. } //switch
  690. if (NULL != hBrush)
  691. {
  692. ::DeleteObject(hBrush);
  693. hBrush = NULL;
  694. } //if
  695. } //End FillEffect
  696. void CPPDrawManager::MultipleCopy(HDC hDestDC, int nDestX, int nDestY, DWORD dwDestWidth, DWORD dwDestHeight, 
  697. HDC hSrcDC, int nSrcX, int nSrcY, DWORD dwSrcWidth, DWORD dwSrcHeight)
  698. {
  699. // Horizontal copying
  700. int right, bottom;
  701. int nDestRight = (int)(nDestX + dwDestWidth);
  702. int nDestBottom = (int)(nDestY + dwDestHeight);
  703. for (int x = nDestX; x < nDestRight; x+= dwSrcWidth)
  704. {
  705. right = min (x + (int)dwSrcWidth, nDestRight);
  706. // Vertical copying
  707. for (int y = nDestY; y < nDestBottom; y+= dwSrcHeight)
  708. {
  709. bottom = min (y + (int)dwSrcHeight, nDestBottom);
  710. ::BitBlt(hDestDC, x, y, right - x, bottom - y, hSrcDC, nSrcX, nSrcY, SRCCOPY);
  711. } //for
  712. } //for
  713. } //End MultipleCopy
  714. void CPPDrawManager::DrawBitmap(HDC hDC, int x, int y, DWORD dwWidth, DWORD dwHeight, HBITMAP hSrcBitmap,
  715. BOOL bUseMask, COLORREF crMask, 
  716. DWORD dwEffect /* = IMAGE_EFFECT_NONE */, 
  717. BOOL bShadow /* = FALSE */, 
  718. DWORD dwCxShadow /* = PPDRAWMANAGER_SHADOW_XOFFSET */, 
  719. DWORD dwCyShadow /* = PPDRAWMANAGER_SHADOW_YOFFSET */,
  720. DWORD dwCxDepth /* = PPDRAWMANAGER_SHADOW_XDEPTH */, 
  721. DWORD dwCyDepth /* = PPDRAWMANAGER_SHADOW_YDEPTH */,
  722. COLORREF clrShadow /* = PPDRAWMANAGER_SHADOW_COLOR */)
  723. {
  724. m_bIsAlpha = FALSE;
  725. if (NULL == hSrcBitmap)
  726. return;
  727. SIZE sz;
  728. GetSizeOfBitmap(hSrcBitmap, &sz);
  729. HDC hSrcDC = ::CreateCompatibleDC(hDC);
  730. HDC hDestDC = ::CreateCompatibleDC(hDC);
  731. HBITMAP hBitmapTemp = ::CreateCompatibleBitmap(hDC, dwWidth, dwHeight);
  732. HBITMAP hOldSrcBitmap = (HBITMAP)::SelectObject(hSrcDC, hSrcBitmap);
  733. HBITMAP hOldDestBitmap = (HBITMAP)::SelectObject(hDestDC, hBitmapTemp);
  734. //Scales a bitmap if need
  735. if (((DWORD)sz.cx != dwWidth) || ((DWORD)sz.cy != dwHeight))
  736. ::StretchBlt(hDestDC, 0, 0, dwWidth, dwHeight, hSrcDC, 0, 0, sz.cx, sz.cy, SRCCOPY);
  737. else
  738. ::BitBlt(hDestDC, 0, 0, dwWidth, dwHeight, hSrcDC, 0, 0, SRCCOPY);
  739. ::SelectObject(hDestDC, hOldDestBitmap);
  740. HBITMAP hMaskBmp = CreateImageEffect(hBitmapTemp, dwWidth, dwHeight, IMAGE_EFFECT_MASK, bUseMask, crMask);
  741. HBITMAP hBitmap = CreateImageEffect(hBitmapTemp, dwWidth, dwHeight, dwEffect, bUseMask, crMask, clrShadow);
  742. if (bShadow)
  743. {
  744. if (dwEffect & IMAGE_EFFECT_SHADOW)
  745. {
  746. POINT ptShadow;
  747. ptShadow.x = x + dwCxShadow;
  748. ptShadow.y = y + dwCyShadow;
  749. HBITMAP hShadowBmp =  CreateImageEffect(hBitmapTemp, dwWidth, dwHeight, IMAGE_EFFECT_MASK, bUseMask, crMask, InvertColor(clrShadow));
  750. DrawShadow(hDC, ptShadow.x, ptShadow.y, dwWidth, dwHeight, hShadowBmp, dwEffect & IMAGE_EFFECT_GRADIENT_SHADOW, dwCxDepth, dwCyDepth);
  751. ::DeleteObject(hShadowBmp);
  752. }
  753. else
  754. {
  755. x += dwCxShadow;
  756. y += dwCyShadow;
  757. } //if
  758. } //if
  759. if (m_bIsAlpha)
  760. {
  761. ::SelectObject(hSrcDC, hBitmap);
  762. AlphaChannelBitBlt(hDC, x, y, dwWidth, dwHeight, hSrcDC, 0, 0);
  763. }
  764. else
  765. {
  766. //Merge the image mask with background
  767. ::SelectObject(hSrcDC, hMaskBmp);
  768. ::BitBlt(hDC, x, y, dwWidth, dwHeight, hSrcDC, 0, 0, SRCAND);
  769. //Draw the image
  770. ::SelectObject(hSrcDC, hBitmap);
  771. ::BitBlt(hDC, x, y, dwWidth, dwHeight, hSrcDC, 0, 0, SRCPAINT);
  772. }
  773. ::SelectObject(hSrcDC, hOldSrcBitmap);
  774. ::DeleteDC(hDestDC);
  775. ::DeleteDC(hSrcDC);
  776. ::DeleteObject(hBitmap);
  777. ::DeleteObject(hMaskBmp);
  778. ::DeleteObject(hBitmapTemp);
  779. } //End DrawBitmap
  780. void CPPDrawManager::DrawIcon(HDC hDC, int x, int y, DWORD dwWidth, DWORD dwHeight, HICON hSrcIcon,
  781.    DWORD dwEffect /* = IMAGE_EFFECT_NONE */, 
  782. BOOL bShadow /* = FALSE */, 
  783. DWORD dwCxShadow /* = PPDRAWMANAGER_SHADOW_XOFFSET */, 
  784. DWORD dwCyShadow /* = PPDRAWMANAGER_SHADOW_YOFFSET */,
  785. DWORD dwCxDepth /* = PPDRAWMANAGER_SHADOW_XDEPTH */, 
  786. DWORD dwCyDepth /* = PPDRAWMANAGER_SHADOW_YDEPTH */,
  787. COLORREF clrShadow /* = PPDRAWMANAGER_SHADOW_COLOR */)
  788. {
  789. m_bIsAlpha = FALSE;
  790. if (NULL == hSrcIcon)
  791. return;
  792. SIZE sz;
  793. GetSizeOfIcon(hSrcIcon, &sz);
  794. HICON hIcon = NULL;
  795. if (((DWORD)sz.cx == dwWidth) && ((DWORD)sz.cy == dwHeight))
  796. hIcon = ::CopyIcon(hSrcIcon);
  797. else hIcon = StretchIcon(hSrcIcon, dwWidth, dwHeight);
  798. ICONINFO csOriginal;
  799. if (!::GetIconInfo(hIcon, &csOriginal))
  800. return;
  801. HDC hSrcDC = ::CreateCompatibleDC(hDC);
  802. HBITMAP hBitmap;
  803. if (dwEffect & IMAGE_EFFECT_MONOCHROME)
  804. hBitmap = CreateImageEffect(csOriginal.hbmMask, dwWidth, dwHeight, dwEffect, TRUE, RGB(255, 255, 255), clrShadow);
  805. else
  806. hBitmap = CreateImageEffect(csOriginal.hbmColor, dwWidth, dwHeight, dwEffect, TRUE, RGB(0, 0, 0), clrShadow);
  807. HBITMAP hOldSrcBitmap = (HBITMAP)::SelectObject(hSrcDC, hBitmap);
  808. if (bShadow)
  809. {
  810. if (dwEffect & IMAGE_EFFECT_SHADOW)
  811. {
  812. POINT ptShadow;
  813. ptShadow.x = x + dwCxShadow;
  814. ptShadow.y = y + dwCyShadow;
  815. HBITMAP hShadowBmp =  CreateImageEffect(csOriginal.hbmMask, dwWidth, dwHeight, IMAGE_EFFECT_MASK, TRUE, RGB(255, 255, 255), InvertColor(clrShadow));
  816. DrawShadow(hDC, ptShadow.x, ptShadow.y, dwWidth, dwHeight, hShadowBmp, dwEffect & IMAGE_EFFECT_GRADIENT_SHADOW, dwCxDepth, dwCyDepth);
  817. ::DeleteObject(hShadowBmp);
  818. }
  819. else
  820. {
  821. x += dwCxShadow;
  822. y += dwCyShadow;
  823. } //if
  824. } //if
  825. if (m_bIsAlpha)
  826. {
  827. // ::SelectObject(hSrcDC, hBitmap);
  828. AlphaChannelBitBlt(hDC, x, y, dwWidth, dwHeight, hSrcDC, 0, 0);
  829. }
  830. else
  831. {
  832. //-------------------------------------------------------------------
  833. // !!! ATTENTION !!!
  834. // I don't know why a icon uses text's color
  835. // Therefore I change a text's color to BLACK and after draw I restore
  836. // original color
  837. //-------------------------------------------------------------------
  838. COLORREF crOldColor = ::SetTextColor(hDC, RGB(0, 0, 0));
  839. //Merge the image mask with background
  840. ::SelectObject(hSrcDC, csOriginal.hbmMask);
  841. ::BitBlt(hDC, x, y, dwWidth, dwHeight, hSrcDC, 0, 0, SRCAND);
  842. //Draw the image
  843. ::SelectObject(hSrcDC, hBitmap);
  844. ::BitBlt(hDC, x, y, dwWidth, dwHeight, hSrcDC, 0, 0, SRCPAINT);
  845. ::SetTextColor(hDC, crOldColor);
  846. } //if
  847. ::SelectObject(hSrcDC, hOldSrcBitmap);
  848. ::DeleteDC(hSrcDC);
  849. ::DeleteObject(hBitmap);
  850. ::DestroyIcon(hIcon);
  851. ::DeleteObject(csOriginal.hbmColor);
  852. ::DeleteObject(csOriginal.hbmMask);
  853. } //End DrawIcon
  854. void CPPDrawManager::DrawShadow(HDC hDestDC, int nDestX, int nDestY, DWORD dwWidth, DWORD dwHeight, HBITMAP hMask, BOOL bGradient /* = FALSE */, DWORD dwDepthX /* = PPDRAWMANAGER_SHADOW_YOFFSET */, DWORD dwDepthY /* = PPDRAWMANAGER_SHADOW_XOFFSET */)
  855. {
  856. HDC hSrcDC = ::CreateCompatibleDC(hDestDC);
  857. if (NULL == hSrcDC)
  858. return;
  859. HDC hTempDC = ::CreateCompatibleDC(hDestDC);
  860. if (NULL == hTempDC)
  861. {
  862. ::DeleteDC(hSrcDC);
  863. return;
  864. } // if
  865. //Creates Source DIB
  866. LPBITMAPINFO lpbiSrc;
  867. // Fill in the BITMAPINFOHEADER
  868. lpbiSrc = (LPBITMAPINFO) new BYTE[sizeof(BITMAPINFOHEADER)];
  869. lpbiSrc->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  870. lpbiSrc->bmiHeader.biWidth = dwWidth;
  871. lpbiSrc->bmiHeader.biHeight = dwHeight;
  872. lpbiSrc->bmiHeader.biPlanes = 1;
  873. lpbiSrc->bmiHeader.biBitCount = 32;
  874. lpbiSrc->bmiHeader.biCompression = BI_RGB;
  875. lpbiSrc->bmiHeader.biSizeImage = dwWidth * dwHeight;
  876. lpbiSrc->bmiHeader.biXPelsPerMeter = 0;
  877. lpbiSrc->bmiHeader.biYPelsPerMeter = 0;
  878. lpbiSrc->bmiHeader.biClrUsed = 0;
  879. lpbiSrc->bmiHeader.biClrImportant = 0;
  880. COLORREF* pSrcBits = NULL;
  881. HBITMAP hSrcDib = CreateDIBSection (
  882. hSrcDC, lpbiSrc, DIB_RGB_COLORS, (void **)&pSrcBits,
  883. NULL, NULL);
  884. if ((NULL != hSrcDib) && (NULL != pSrcBits))
  885. {
  886. HBITMAP hOldSrcBmp = (HBITMAP)::SelectObject (hSrcDC, hSrcDib);
  887. HBITMAP hOldTempBmp = (HBITMAP)::SelectObject (hTempDC, hMask);
  888. if (bGradient)
  889. {
  890. if (!(dwDepthX & 0x1)) dwDepthX++;
  891. if (!(dwDepthY & 0x1)) dwDepthY++;
  892. ::BitBlt(hSrcDC, 0, 0, dwWidth, dwHeight, hTempDC, 0, 0, WHITENESS);
  893. ::StretchBlt (hSrcDC, dwDepthX / 2, dwDepthY / 2, dwWidth - dwDepthX, dwHeight - dwDepthY, hTempDC, 0, 0, dwWidth, dwHeight, SRCCOPY);
  894. }
  895. else
  896. {
  897. ::BitBlt(hSrcDC, 0, 0, dwWidth, dwHeight, hTempDC, 0, 0, SRCCOPY);
  898. } //if
  899. ::SelectObject (hTempDC, hOldTempBmp);
  900. ::SelectObject (hSrcDC, hOldSrcBmp);
  901. //Creates Destination DIB
  902. LPBITMAPINFO lpbiDest;
  903. // Fill in the BITMAPINFOHEADER
  904. lpbiDest = (LPBITMAPINFO) new BYTE[sizeof(BITMAPINFOHEADER)];
  905. lpbiDest->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  906. lpbiDest->bmiHeader.biWidth = dwWidth;
  907. lpbiDest->bmiHeader.biHeight = dwHeight;
  908. lpbiDest->bmiHeader.biPlanes = 1;
  909. lpbiDest->bmiHeader.biBitCount = 32;
  910. lpbiDest->bmiHeader.biCompression = BI_RGB;
  911. lpbiDest->bmiHeader.biSizeImage = dwWidth * dwHeight;
  912. lpbiDest->bmiHeader.biXPelsPerMeter = 0;
  913. lpbiDest->bmiHeader.biYPelsPerMeter = 0;
  914. lpbiDest->bmiHeader.biClrUsed = 0;
  915. lpbiDest->bmiHeader.biClrImportant = 0;
  916. COLORREF* pDestBits = NULL;
  917. HBITMAP hDestDib = CreateDIBSection (
  918. hDestDC, lpbiDest, DIB_RGB_COLORS, (void **)&pDestBits,
  919. NULL, NULL);
  920. if ((NULL != hDestDib) && (NULL != pDestBits))
  921. {
  922. ::SelectObject (hTempDC, hDestDib);
  923. ::BitBlt (hTempDC, 0, 0, dwWidth, dwHeight, hDestDC, nDestX, nDestY, SRCCOPY);
  924. ::SelectObject (hTempDC, hOldTempBmp);
  925. if (bGradient)
  926. {
  927. double * depth = new double [dwWidth * dwHeight];
  928. SmoothMaskImage(dwWidth, dwHeight, pSrcBits, dwDepthX, dwDepthY, depth);
  929. for(DWORD pixel = 0; pixel < dwWidth * dwHeight; pixel++, pDestBits++)
  930. *pDestBits = DarkenColor(*pDestBits, *(depth + pixel));
  931. delete [] depth;
  932. }
  933. else
  934. {
  935. for(DWORD pixel = 0; pixel < dwWidth * dwHeight; pixel++, pSrcBits++, pDestBits++)
  936. *pDestBits = DarkenColor(*pDestBits, (double)GetRValue(*pSrcBits) / 255.0);
  937. } //if
  938. ::SelectObject (hTempDC, hDestDib);
  939. ::BitBlt (hDestDC, nDestX, nDestY, dwWidth, dwHeight, hTempDC, 0, 0, SRCCOPY);
  940. ::SelectObject (hTempDC, hOldTempBmp);
  941. delete lpbiDest;
  942. ::DeleteObject(hDestDib);
  943. } //if
  944. delete lpbiSrc;
  945. ::DeleteObject(hSrcDib);
  946. } //if
  947. ::DeleteDC(hTempDC);
  948. ::DeleteDC(hSrcDC);
  949. } //End DrawIcon
  950. void CPPDrawManager::DrawImageList(HDC hDC, int x, int y, DWORD dwWidth, DWORD dwHeight, HBITMAP hSrcBitmap,
  951. int nIndex, int cx, int cy,
  952. BOOL bUseMask, COLORREF crMask, 
  953. DWORD dwEffect /*= IMAGE_EFFECT_NONE*/, 
  954. BOOL bShadow /*= FALSE*/, 
  955. DWORD dwCxShadow /*= PPDRAWMANAGER_SHADOW_XOFFSET*/, 
  956. DWORD dwCyShadow /*= PPDRAWMANAGER_SHADOW_YOFFSET*/,
  957. DWORD dwCxDepth /*= PPDRAWMANAGER_SHADOW_XDEPTH*/, 
  958. DWORD dwCyDepth /*= PPDRAWMANAGER_SHADOW_YDEPTH*/,
  959. COLORREF clrShadow /*= PPDRAWMANAGER_SHADOW_COLOR*/)
  960. {
  961. if ((NULL == hSrcBitmap) || !cx || !cy)
  962. return;
  963. SIZE sz;
  964. GetSizeOfBitmap(hSrcBitmap, &sz);
  965. //ENG: Gets a max columns and rows of the images on the bitmap
  966. //RUS: 项塍鬣屐 爨犟桁嚯