Skip to content

Commit 8659617

Browse files
committed
Bitmap device-independent (DIP) transparency corrections
1 parent aa627ad commit 8659617

File tree

6 files changed

+8
-51
lines changed

6 files changed

+8
-51
lines changed

src/Win32Utils.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,14 @@ namespace Win32Utils
157157
}
158158
#endif
159159

160-
HBITMAP CreateBitmap(int biWidth, int biHeight, UINT biPlanes, UINT biBitCount, HDC hDc)
160+
HBITMAP CreateBitmapWithAlphaChannel(int biWidth, int biHeight, HDC hDc)
161161
{
162162
BITMAPINFO bmi;
163163
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
164164
bmi.bmiHeader.biWidth = biWidth;
165165
bmi.bmiHeader.biHeight = biHeight;
166-
bmi.bmiHeader.biPlanes = biPlanes;
167-
bmi.bmiHeader.biBitCount = biBitCount;
166+
bmi.bmiHeader.biPlanes = 1;
167+
bmi.bmiHeader.biBitCount = 32;
168168
bmi.bmiHeader.biCompression = BI_RGB;
169169
bmi.bmiHeader.biSizeImage = biWidth * biHeight * 4;
170170
VOID* pvBits;
@@ -204,11 +204,11 @@ namespace Win32Utils
204204
return NULL;
205205

206206
HWND hWndDesktop = GetDesktopWindow();
207-
HDC hdcDesktop = GetDC(hWndDesktop);
208-
HDC hDcMem = CreateCompatibleDC(hdcDesktop);
207+
HDC hDcDesktop = GetDC(hWndDesktop);
208+
HDC hDcMem = CreateCompatibleDC(hDcDesktop);
209209

210210
// Create a 32bbp bitmap and select it.
211-
HBITMAP hBitmap = CreateBitmap(bitmap_width, bitmap_height, 1, BITS_PER_PIXEL, hDcMem);
211+
HBITMAP hBitmap = CreateBitmapWithAlphaChannel(bitmap_width, bitmap_height, hDcMem);
212212
HBITMAP hbmOld = (HBITMAP)SelectObject(hDcMem, hBitmap);
213213

214214
#if 0
@@ -280,7 +280,7 @@ namespace Win32Utils
280280
// Clean up.
281281
SelectObject(hDcMem, hbmOld);
282282
DeleteDC(hDcMem);
283-
ReleaseDC(hWndDesktop, hdcDesktop);
283+
ReleaseDC(hWndDesktop, hDcDesktop);
284284

285285
return hBitmap;
286286
}

src/Win32Utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace Win32Utils
3535
RGBQUAD ToRgbQuad(const DWORD & iColor);
3636
SIZE GetBitmapSize(HBITMAP hBitmap);
3737
BOOL FillTransparentPixels(HBITMAP hBitmap, COLORREF background_color);
38-
HBITMAP CreateBitmap(int biWidth, int biHeight, UINT biPlanes, UINT biBitCount, HDC hDc);
38+
HBITMAP CreateBitmapWithAlphaChannel(int biWidth, int biHeight, HDC hDc);
3939
HBITMAP CopyAsBitmap(HICON hIcon, const int bitmap_width, const int bitmap_height);
4040
HBITMAP CopyAsBitmap(HICON hIcon);
4141
bool CreateBmpFile(const char * path, HBITMAP hBitmap);

src/shellext.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -356,12 +356,6 @@ void CContextMenu::BuildMenuTree(HMENU hMenu, shellanything::Menu * menu, UINT &
356356
//Convert the icon to a bitmap (with invisible background)
357357
hBitmap = Win32Utils::CopyAsBitmap(hIcon);
358358

359-
#if 0
360-
//Remove the invisible background and replace by the default popup menu color
361-
COLORREF menu_background_color = GetSysColor(COLOR_MENU);
362-
Win32Utils::FillTransparentPixels(hBitmap, menu_background_color);
363-
#endif
364-
365359
DestroyIcon(hIconLarge);
366360
DestroyIcon(hIconSmall);
367361

test/TestBitmapCache.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@ namespace shellanything { namespace test
4040
SIZE icon_size = Win32Utils::GetIconSize(hIconLarge);
4141
HBITMAP hBitmap = Win32Utils::CopyAsBitmap(hIconLarge, icon_size.cx, icon_size.cy);
4242

43-
#if 0
44-
//Remove the invisible background and replace by red color
45-
COLORREF background_color = RGB(255,0,255); //pink
46-
Win32Utils::FillTransparentPixels(hBitmap, background_color);
47-
#endif
48-
4943
DestroyIcon(hIconLarge);
5044
DestroyIcon(hIconSmall);
5145

@@ -63,12 +57,6 @@ namespace shellanything { namespace test
6357
SIZE icon_size = Win32Utils::GetIconSize(hIconLarge);
6458
HBITMAP hBitmap = Win32Utils::CopyAsBitmap(hIconLarge, icon_size.cx, icon_size.cy);
6559

66-
#if 0
67-
//Remove the invisible background and replace by red color
68-
COLORREF background_color = RGB(255,0,255); //pink
69-
Win32Utils::FillTransparentPixels(hBitmap, background_color);
70-
#endif
71-
7260
DestroyIcon(hIconLarge);
7361
DestroyIcon(hIconSmall);
7462

test/TestWin32Registry.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,6 @@ namespace shellanything { namespace test
234234
SIZE icon_size = Win32Utils::GetIconSize(hIconBest);
235235
HBITMAP hBitmap = Win32Utils::CopyAsBitmap(hIconBest, icon_size.cx, icon_size.cy);
236236

237-
#if 0
238-
//Remove the invisible background and replace by red color
239-
COLORREF background_color = RGB(255,0,255); //pink
240-
Win32Utils::FillTransparentPixels(hBitmap, background_color);
241-
#endif
242-
243237
DestroyIcon(hIconLarge);
244238
DestroyIcon(hIconSmall);
245239

@@ -321,12 +315,6 @@ namespace shellanything { namespace test
321315
SIZE icon_size = Win32Utils::GetIconSize(hIconLarge);
322316
HBITMAP hBitmap = Win32Utils::CopyAsBitmap(hIconLarge, icon_size.cx, icon_size.cy);
323317

324-
#if 0
325-
//Remove the invisible background and replace by red color
326-
COLORREF background_color = RGB(255,0,255); //pink
327-
Win32Utils::FillTransparentPixels(hBitmap, background_color);
328-
#endif
329-
330318
DestroyIcon(hIconLarge);
331319
DestroyIcon(hIconSmall);
332320

test/TestWin32Utils.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,6 @@ namespace shellanything { namespace test
5959
SIZE icon_size = Win32Utils::GetIconSize(hIconLarge);
6060
HBITMAP hBitmap = Win32Utils::CopyAsBitmap(hIconLarge, icon_size.cx, icon_size.cy);
6161

62-
#if 0
63-
//Remove the invisible background and replace by red color
64-
COLORREF background_color = RGB(255,0,255); //pink
65-
Win32Utils::FillTransparentPixels(hBitmap, background_color);
66-
#endif
67-
6862
DestroyIcon(hIconLarge);
6963
DestroyIcon(hIconSmall);
7064

@@ -114,13 +108,6 @@ namespace shellanything { namespace test
114108
SIZE icon_size = Win32Utils::GetIconSize(hIconLarge);
115109
HBITMAP hBitmap = Win32Utils::CopyAsBitmap(hIconLarge, icon_size.cx, icon_size.cy);
116110

117-
#if 0
118-
//Remove the invisible background and replace by red color
119-
static const COLORREF color_pink = RGB(255, 0,255);
120-
static const COLORREF color_white = RGB(255,255,255);
121-
Win32Utils::FillTransparentPixels(hBitmap, color_pink);
122-
#endif
123-
124111
DestroyIcon(hIconLarge);
125112
DestroyIcon(hIconSmall);
126113

0 commit comments

Comments
 (0)