From 76fb69bf3da2b179bbd54b4eeeb3726788be4559 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Fri, 28 Jan 2011 12:44:21 +0100 Subject: [PATCH] user32: Fix LoadImage behavior with zero size and no LR_DEFAULTSIZE. Based on a patch by Marcus Meissner. --- dlls/user32/cursoricon.c | 48 ++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/dlls/user32/cursoricon.c b/dlls/user32/cursoricon.c index dd5d1bb943..d014711789 100644 --- a/dlls/user32/cursoricon.c +++ b/dlls/user32/cursoricon.c @@ -422,7 +422,20 @@ static int CURSORICON_FindBestIcon( LPCVOID dir, fnGetCIEntry get_entry, /* Find Best Fit */ iTotalDiff = 0xFFFFFFFF; iColorDiff = 0xFFFFFFFF; - for ( i = 0; get_entry( dir, i, &cx, &cy, &bits ); i++ ) + + if (loadflags & LR_DEFAULTSIZE) + { + if (!width) width = GetSystemMetrics( SM_CXICON ); + if (!height) height = GetSystemMetrics( SM_CYICON ); + } + else if (!width && !height) + { + /* use the size of the first entry */ + if (!get_entry( dir, 0, &width, &height, &bits )) return -1; + iTotalDiff = 0; + } + + for ( i = 0; iTotalDiff && get_entry( dir, i, &cx, &cy, &bits ); i++ ) { iTempXDiff = abs(width - cx); iTempYDiff = abs(height - cy); @@ -479,6 +492,18 @@ static int CURSORICON_FindBestCursor( LPCVOID dir, fnGetCIEntry get_entry, { int i, maxwidth, maxheight, cx, cy, bits, bestEntry = -1; + if (loadflags & LR_DEFAULTSIZE) + { + if (!width) width = GetSystemMetrics( SM_CXCURSOR ); + if (!height) height = GetSystemMetrics( SM_CYCURSOR ); + } + else if (!width && !height) + { + /* use the first entry */ + if (!get_entry( dir, 0, &width, &height, &bits )) return -1; + return 0; + } + /* Double height to account for AND and XOR masks */ height *= 2; @@ -782,8 +807,16 @@ static HICON CURSORICON_CreateIconFromBMI( BITMAPINFO *bmi, HMODULE module, LPCW return 0; } - if (!width) width = bmi->bmiHeader.biWidth; - if (!height) height = bmi->bmiHeader.biHeight/2; + if (cFlag & LR_DEFAULTSIZE) + { + if (!width) width = GetSystemMetrics( bIcon ? SM_CXICON : SM_CXCURSOR ); + if (!height) height = GetSystemMetrics( bIcon ? SM_CYICON : SM_CYCURSOR ); + } + else + { + if (!width) width = bmi->bmiHeader.biWidth; + if (!height) height = bmi->bmiHeader.biHeight/2; + } do_stretch = (bmi->bmiHeader.biHeight/2 != height) || (bmi->bmiHeader.biWidth != width); @@ -2274,15 +2307,6 @@ HANDLE WINAPI LoadImageW( HINSTANCE hinst, LPCWSTR name, UINT type, TRACE_(resource)("(%p,%s,%d,%d,%d,0x%08x)\n", hinst,debugstr_w(name),type,desiredx,desiredy,loadflags); - if (loadflags & LR_DEFAULTSIZE) { - if (type == IMAGE_ICON) { - if (!desiredx) desiredx = GetSystemMetrics(SM_CXICON); - if (!desiredy) desiredy = GetSystemMetrics(SM_CYICON); - } else if (type == IMAGE_CURSOR) { - if (!desiredx) desiredx = GetSystemMetrics(SM_CXCURSOR); - if (!desiredy) desiredy = GetSystemMetrics(SM_CYCURSOR); - } - } if (loadflags & LR_LOADFROMFILE) loadflags &= ~LR_SHARED; switch (type) { case IMAGE_BITMAP: -- 2.32.0.93.g670b81a890