forked from NTDLS/NSWFL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NSWFL_Graphics.Cpp
77 lines (61 loc) · 2.64 KB
/
NSWFL_Graphics.Cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright © NetworkDLS 2023, All rights reserved
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef _NSWFL_GRAPHICS_CPP_
#define _NSWFL_GRAPHICS_CPP_
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "NSWFL.H"
#ifdef _USE_GLOBAL_MEMPOOL
extern NSWFL::Memory::MemoryPool *pMem; //pMem must be defined and initalized elsewhere.
#endif
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
namespace NSWFL {
namespace Graphics {
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
Replaces all occurrences of the first pixil's color with the suppled color.
//Example:
MakeBitmapTransparent(hBitmap, GetSysColor(COLOR_MENU))
*/
HBITMAP MakeBitmapTransparent(HBITMAP hbmSrc, COLORREF backGroundColor)
{
HDC hdcSrc, hdcDst;
HBITMAP hbmOld, hbmNew;
BITMAP bm;
COLORREF clrTP;
if ((hdcSrc = CreateCompatibleDC(NULL)) != NULL)
{
if ((hdcDst = CreateCompatibleDC(NULL)) != NULL)
{
int nRow, nCol;
GetObject(hbmSrc, sizeof(bm), &bm);
hbmOld = (HBITMAP)SelectObject(hdcSrc, hbmSrc);
hbmNew = CreateBitmap(bm.bmWidth, bm.bmHeight, bm.bmPlanes, bm.bmBitsPixel, NULL);
SelectObject(hdcDst, hbmNew);
BitBlt(hdcDst, 0, 0, bm.bmWidth, bm.bmHeight, hdcSrc, 0, 0, SRCCOPY);
clrTP = GetPixel(hdcDst, 0, 0);// Get color of first pixel at 0,0
for (nRow = 0; nRow < bm.bmHeight; nRow++)// work our way through all the pixels changing their color
{
for (nCol = 0; nCol < bm.bmWidth; nCol++)// when we hit our set transparency color.
{
if (GetPixel(hdcDst, nCol, nRow) == clrTP)
{
SetPixel(hdcDst, nCol, nRow, backGroundColor);
}
}
}
DeleteDC(hdcDst);
}
DeleteDC(hdcSrc);
}
return hbmNew;// return our transformed bitmap.
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
} //namespace::Graphics
} //namespace::NSWFL
#endif