Skip to content

Commit aa627ad

Browse files
committed
Bitmap device-independent (DIP) transparency
1 parent 02fcca0 commit aa627ad

File tree

7 files changed

+32
-3
lines changed

7 files changed

+32
-3
lines changed

ci/appveyor/install_googletest.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ echo Compiling...
2626
echo ============================================================================
2727
mkdir build >NUL 2>NUL
2828
cd build
29-
cmake -Wno-dev -DCMAKE_GENERATOR_PLATFORM=%Platform% -T %PlatformToolset% -DCMAKE_INSTALL_PREFIX=%GTEST_ROOT% -Dgtest_force_shared_crt=ON -DBUILD_GMOCK=OFF -DBUILD_GTEST=ON ..
29+
cmake -Wno-dev -DCMAKE_GENERATOR_PLATFORM=%Platform% -T %PlatformToolset% -DCMAKE_INSTALL_PREFIX=%GTEST_ROOT% -Dgtest_force_shared_crt=ON -DBUILD_GMOCK=OFF -DBUILD_GTEST=ON -DCMAKE_CXX_FLAGS=/D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING ..
3030
if %errorlevel% neq 0 exit /b %errorlevel%
3131
cmake --build . --config %Configuration%
3232
if %errorlevel% neq 0 exit /b %errorlevel%

src/Win32Utils.cpp

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

160+
HBITMAP CreateBitmap(int biWidth, int biHeight, UINT biPlanes, UINT biBitCount, HDC hDc)
161+
{
162+
BITMAPINFO bmi;
163+
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
164+
bmi.bmiHeader.biWidth = biWidth;
165+
bmi.bmiHeader.biHeight = biHeight;
166+
bmi.bmiHeader.biPlanes = biPlanes;
167+
bmi.bmiHeader.biBitCount = biBitCount;
168+
bmi.bmiHeader.biCompression = BI_RGB;
169+
bmi.bmiHeader.biSizeImage = biWidth * biHeight * 4;
170+
VOID* pvBits;
171+
return CreateDIBSection(hDc, &bmi, DIB_RGB_COLORS, &pvBits, NULL, 0x0);;
172+
}
173+
160174
HBITMAP CopyAsBitmap(HICON hIcon, const int bitmap_width, const int bitmap_height)
161175
{
162176
//According to https://devblogs.microsoft.com/oldnewthing/20101021-00/?p=12483, using DrawIconEx()
@@ -194,7 +208,7 @@ namespace Win32Utils
194208
HDC hDcMem = CreateCompatibleDC(hdcDesktop);
195209

196210
// Create a 32bbp bitmap and select it.
197-
HBITMAP hBitmap = CreateBitmap(bitmap_width, bitmap_height, 1, BITS_PER_PIXEL, NULL);
211+
HBITMAP hBitmap = CreateBitmap(bitmap_width, bitmap_height, 1, BITS_PER_PIXEL, hDcMem);
198212
HBITMAP hbmOld = (HBITMAP)SelectObject(hDcMem, hBitmap);
199213

200214
#if 0
@@ -270,7 +284,7 @@ namespace Win32Utils
270284

271285
return hBitmap;
272286
}
273-
287+
274288
HBITMAP CopyAsBitmap(HICON hIcon)
275289
{
276290
//Get properties related to Windows Menu

src/Win32Utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +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);
3839
HBITMAP CopyAsBitmap(HICON hIcon, const int bitmap_width, const int bitmap_height);
3940
HBITMAP CopyAsBitmap(HICON hIcon);
4041
bool CreateBmpFile(const char * path, HBITMAP hBitmap);

src/shellext.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,11 @@ 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
359360
//Remove the invisible background and replace by the default popup menu color
360361
COLORREF menu_background_color = GetSysColor(COLOR_MENU);
361362
Win32Utils::FillTransparentPixels(hBitmap, menu_background_color);
363+
#endif
362364

363365
DestroyIcon(hIconLarge);
364366
DestroyIcon(hIconSmall);

test/TestBitmapCache.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ 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
4344
//Remove the invisible background and replace by red color
4445
COLORREF background_color = RGB(255,0,255); //pink
4546
Win32Utils::FillTransparentPixels(hBitmap, background_color);
47+
#endif
4648

4749
DestroyIcon(hIconLarge);
4850
DestroyIcon(hIconSmall);
@@ -61,9 +63,11 @@ namespace shellanything { namespace test
6163
SIZE icon_size = Win32Utils::GetIconSize(hIconLarge);
6264
HBITMAP hBitmap = Win32Utils::CopyAsBitmap(hIconLarge, icon_size.cx, icon_size.cy);
6365

66+
#if 0
6467
//Remove the invisible background and replace by red color
6568
COLORREF background_color = RGB(255,0,255); //pink
6669
Win32Utils::FillTransparentPixels(hBitmap, background_color);
70+
#endif
6771

6872
DestroyIcon(hIconLarge);
6973
DestroyIcon(hIconSmall);

test/TestWin32Registry.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,11 @@ 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
237238
//Remove the invisible background and replace by red color
238239
COLORREF background_color = RGB(255,0,255); //pink
239240
Win32Utils::FillTransparentPixels(hBitmap, background_color);
241+
#endif
240242

241243
DestroyIcon(hIconLarge);
242244
DestroyIcon(hIconSmall);
@@ -319,9 +321,11 @@ namespace shellanything { namespace test
319321
SIZE icon_size = Win32Utils::GetIconSize(hIconLarge);
320322
HBITMAP hBitmap = Win32Utils::CopyAsBitmap(hIconLarge, icon_size.cx, icon_size.cy);
321323

324+
#if 0
322325
//Remove the invisible background and replace by red color
323326
COLORREF background_color = RGB(255,0,255); //pink
324327
Win32Utils::FillTransparentPixels(hBitmap, background_color);
328+
#endif
325329

326330
DestroyIcon(hIconLarge);
327331
DestroyIcon(hIconSmall);

test/TestWin32Utils.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ 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
6263
//Remove the invisible background and replace by red color
6364
COLORREF background_color = RGB(255,0,255); //pink
6465
Win32Utils::FillTransparentPixels(hBitmap, background_color);
66+
#endif
6567

6668
DestroyIcon(hIconLarge);
6769
DestroyIcon(hIconSmall);
@@ -112,10 +114,12 @@ namespace shellanything { namespace test
112114
SIZE icon_size = Win32Utils::GetIconSize(hIconLarge);
113115
HBITMAP hBitmap = Win32Utils::CopyAsBitmap(hIconLarge, icon_size.cx, icon_size.cy);
114116

117+
#if 0
115118
//Remove the invisible background and replace by red color
116119
static const COLORREF color_pink = RGB(255, 0,255);
117120
static const COLORREF color_white = RGB(255,255,255);
118121
Win32Utils::FillTransparentPixels(hBitmap, color_pink);
122+
#endif
119123

120124
DestroyIcon(hIconLarge);
121125
DestroyIcon(hIconSmall);

0 commit comments

Comments
 (0)