From 285addaaa632ebfd3bc6bdccbe8b114c0bb83882 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Tue, 22 Sep 2009 18:10:07 +0200 Subject: fix QPixmap::fromWinHICON for Windows CE mobile On WinCE GetIconInfo returns a 0 hotspot for the system icons, thus we cannot use this value to determine width / height of the icon. Instead, we use the icon's bitmap to get this information. --- src/gui/image/qpixmap_win.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/gui/image/qpixmap_win.cpp b/src/gui/image/qpixmap_win.cpp index 87cb46c..1b61484 100644 --- a/src/gui/image/qpixmap_win.cpp +++ b/src/gui/image/qpixmap_win.cpp @@ -387,12 +387,29 @@ QPixmap QPixmap::fromWinHICON(HICON icon) ReleaseDC(0, screenDevice); ICONINFO iconinfo; - bool result = GetIconInfo(icon, &iconinfo); //x and y Hotspot describes the icon center + bool result = GetIconInfo(icon, &iconinfo); if (!result) qWarning("QPixmap::fromWinHICON(), failed to GetIconInfo()"); - int w = iconinfo.xHotspot * 2; - int h = iconinfo.yHotspot * 2; + int w = 0; + int h = 0; + if (!iconinfo.xHotspot || !iconinfo.yHotspot) { + // We could not retrieve the icon size via GetIconInfo, + // so we try again using the icon bitmap. + BITMAP bm; + int result = GetObject(iconinfo.hbmColor, sizeof(BITMAP), &bm); + if (!result) result = GetObject(iconinfo.hbmMask, sizeof(BITMAP), &bm); + if (!result) { + qWarning("QPixmap::fromWinHICON(), failed to retrieve icon size"); + return QPixmap(); + } + w = bm.bmWidth; + h = bm.bmHeight; + } else { + // x and y Hotspot describes the icon center + w = iconinfo.xHotspot * 2; + h = iconinfo.yHotspot * 2; + } const DWORD dwImageSize = w * h * 4; BITMAPINFO bmi; -- cgit v0.12