ui/winui/icons.cpp

branch
newapi
changeset 218
d06e7e8e53e1
parent 217
b9798109c7d2
equal deleted inserted replaced
217:b9798109c7d2 218:d06e7e8e53e1
346 if (ExtractIconExA(dll, iconindex, &hicon_large, &hicon_small, 1) > 0) { 346 if (ExtractIconExA(dll, iconindex, &hicon_large, &hicon_small, 1) > 0) {
347 HICON hicon = large ? hicon_large : hicon_small; 347 HICON hicon = large ? hicon_large : hicon_small;
348 348
349 // convert icon to (gdi) bitmap 349 // convert icon to (gdi) bitmap
350 ICONINFO info; 350 ICONINFO info;
351 info.hbmColor = nullptr;
352 info.hbmMask = nullptr;
351 if (GetIconInfo(hicon, &info)) { 353 if (GetIconInfo(hicon, &info)) {
352 BITMAP bitmap; 354 BITMAP bitmap;
353 if (GetObjectW(info.hbmColor, sizeof(BITMAP), &bitmap) != 0) { 355 if (GetObjectW(info.hbmColor, sizeof(BITMAP), &bitmap) != 0) {
354 size_t bitmap_size = bitmap.bmWidthBytes * bitmap.bmHeight; 356 size_t bitmap_size = bitmap.bmWidthBytes * bitmap.bmHeight;
355 char *bitmap_data = (char*)malloc(bitmap_size); 357 char *bitmap_data = (char*)malloc(bitmap_size);
359 WriteableBitmap wb = WriteableBitmap(bitmap.bmWidth, bitmap.bmHeight); 361 WriteableBitmap wb = WriteableBitmap(bitmap.bmWidth, bitmap.bmHeight);
360 void *wb_data = wb.PixelBuffer().data(); 362 void *wb_data = wb.PixelBuffer().data();
361 memcpy(wb_data, bitmap_data, bitmap_size); 363 memcpy(wb_data, bitmap_data, bitmap_size);
362 wbitmap = wb; 364 wbitmap = wb;
363 } 365 }
364 DeleteObject(info.hbmColor);
365 free(bitmap_data); 366 free(bitmap_data);
366 } 367 }
368 if (info.hbmMask) {
369 DeleteObject(info.hbmMask);
370 }
371 if (info.hbmColor) {
372 DeleteObject(info.hbmColor);
373 }
367 } 374 }
368 DeleteObject(info.hbmMask);
369 375
370 DestroyIcon(hicon_small); 376 DestroyIcon(hicon_small);
371 DestroyIcon(hicon_large); 377 DestroyIcon(hicon_large);
372 } 378 }
373 379

mercurial