From c7b3ccd6eb6ba2973b2e732eab2cb3f0e03c977b Mon Sep 17 00:00:00 2001 From: Andrew Riedi Date: Tue, 12 Feb 2008 00:13:44 -0800 Subject: [PATCH] user32: Check for .ico and .cur magic. --- dlls/user32/cursoricon.c | 7 +++++- dlls/user32/tests/cursoricon.c | 42 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletions(-) diff --git a/dlls/user32/cursoricon.c b/dlls/user32/cursoricon.c index 8e5e8d6..d6f87ab 100644 --- a/dlls/user32/cursoricon.c +++ b/dlls/user32/cursoricon.c @@ -902,8 +902,13 @@ static HICON CURSORICON_LoadFromFile( LPCWSTR filename, if (!bits) return hIcon; + /* fCursor is ignored if the .ico or .cur magic exists. */ + if (memcmp( bits, "\x00\x00\x01\x00", 4 ) == 0) + fCursor = FALSE; + else if (memcmp( bits, "\x00\x00\x02\x00", 4 ) == 0) + fCursor = TRUE; /* Check for .ani. */ - if (memcmp( bits, "RIFF", 4 ) == 0) + else if (memcmp( bits, "RIFF", 4 ) == 0) { FIXME("No support for .ani cursors.\n"); goto end; diff --git a/dlls/user32/tests/cursoricon.c b/dlls/user32/tests/cursoricon.c index ca4b118..7085a07 100644 --- a/dlls/user32/tests/cursoricon.c +++ b/dlls/user32/tests/cursoricon.c @@ -559,6 +559,47 @@ static void test_CreateIcon(void) DeleteObject(hbmColor); } +static void test_LoadImage(void) +{ + HANDLE handle; + BOOL ret; + DWORD error; + BYTE icon_data[4286]; + DWORD bytes_written; + + /* Set icon data. */ + memset( icon_data, '\xff', sizeof(icon_data) ); + memcpy( icon_data, + "\x00\x00\x01\x00\x01\x00\x20\x20\x00\x00\x01\x00\x20\x00\xa8\x10" + "\x00\x00\x16\x00\x00\x00\x28\x00\x00\x00\x20\x00\x00\x00\x40\x00" + "\x00\x00\x01\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 62 ); + memset( icon_data + sizeof(icon_data) - 128, '\x00', 128 ); + + /* Create the icon. */ + handle = CreateFileA( "icon.ico", FILE_ALL_ACCESS, 0, NULL, + CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL ); + ok(handle != INVALID_HANDLE_VALUE, "CreateFileA failed. %u\n", GetLastError()); + ret = WriteFile( handle, icon_data, sizeof(icon_data), &bytes_written, NULL ); + ok(bytes_written == 4286, "icon.ico created improperly.\n"); + CloseHandle( handle ); + + /* Test loading an icon as a cursor. */ + SetLastError(0xdeadbeef); + handle = LoadImageA(NULL, "icon.ico", IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE); + ok(handle != NULL, "LoadImage() failed.\n"); + error = GetLastError(); + ok(error == 0, "Last error: %u\n", error); + + ret = DestroyIcon(handle); + ok(ret, "DestroyIcon() failed.\n"); + error = GetLastError(); + ok(error == 0, "Last error: %u\n", error); + + /* Delete the icon. */ + DeleteFileA( "icon.ico" ); +} + static void test_DestroyCursor(void) { static const BYTE bmp_bits[4096]; @@ -662,6 +703,7 @@ START_TEST(cursoricon) test_CopyImage_Bitmap(32); test_initial_cursor(); test_CreateIcon(); + test_LoadImage(); test_DestroyCursor(); do_parent(); test_child_process(); -- 1.4.4.2