@@ -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
0 commit comments