From c1db36686c7adb1f117e2aeecbd024949fc1e6ae Mon Sep 17 00:00:00 2001 From: Lorenzo Ferrillo Date: Sat, 3 Sep 2022 19:25:45 +0200 Subject: [PATCH] comctl32: Support passing bitmap and icon resource ID as a string when creating static control. Follow Up of Merge request !693 by Jacek Caban. The pull request changed properly the static control of user32, but didn't address the comctl32 static control. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=53581 --- dlls/comctl32/static.c | 10 ++++++++-- dlls/comctl32/tests/static.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/dlls/comctl32/static.c b/dlls/comctl32/static.c index c09655da903..25eee289204 100644 --- a/dlls/comctl32/static.c +++ b/dlls/comctl32/static.c @@ -437,6 +437,7 @@ static BOOL hasTextStyle( DWORD style ) static LRESULT CALLBACK STATIC_WindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { + const WCHAR *window_name; LRESULT lResult = 0; LONG full_style = GetWindowLongW( hwnd, GWL_STYLE ); LONG style = full_style & SS_TYPEMASK; @@ -549,13 +550,18 @@ static LRESULT CALLBACK STATIC_WindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, SetWindowPos(hwnd, NULL, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER); } + if (cs->lpszName && cs->lpszName[0] == 0xffff) + window_name = MAKEINTRESOURCEW(cs->lpszName[1]); + else + window_name = cs->lpszName; + switch (style) { case SS_ICON: { HICON hIcon; - hIcon = STATIC_LoadIconW(cs->hInstance, cs->lpszName, full_style); + hIcon = STATIC_LoadIconW(cs->hInstance, window_name, full_style); STATIC_SetIcon(hwnd, hIcon, full_style); } break; @@ -563,7 +569,7 @@ static LRESULT CALLBACK STATIC_WindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, if ((ULONG_PTR)cs->hInstance >> 16) { HBITMAP hBitmap; - hBitmap = LoadBitmapW(cs->hInstance, cs->lpszName); + hBitmap = LoadBitmapW(cs->hInstance, window_name); STATIC_SetBitmap(hwnd, hBitmap, full_style); } break; diff --git a/dlls/comctl32/tests/static.c b/dlls/comctl32/tests/static.c index 756fed86fe0..551aca2720f 100644 --- a/dlls/comctl32/tests/static.c +++ b/dlls/comctl32/tests/static.c @@ -216,6 +216,8 @@ static void test_image(HBITMAP image, BOOL is_dib, BOOL is_premult, BOOL is_alph static void test_set_image(void) { + char resource[4]; + WCHAR resource_unicode[3]; HWND hwnd = create_static(SS_BITMAP); HBITMAP bmp1, bmp2, image; @@ -270,6 +272,33 @@ static void test_set_image(void) test_image(image, TRUE, FALSE, FALSE); + resource[0] = '\xff'; + resource[1] = PtrToUlong(MAKEINTRESOURCEW(IDB_BITMAP_1x1_32BPP)); + resource[2] = PtrToUlong(MAKEINTRESOURCEW(IDB_BITMAP_1x1_32BPP)) >> 8; + resource[3] = 0; + + resource_unicode[0] = 0xffff; + resource_unicode[1] = PtrToUlong(MAKEINTRESOURCEW(IDB_BITMAP_1x1_32BPP)); + resource_unicode[2] = 0; + + hwnd = CreateWindowW(L"Static", resource_unicode, WS_VISIBLE|WS_CHILD|SS_BITMAP, 5, 5, 100, 100, + hMainWnd, (HMENU)CTRL_ID, GetModuleHandleW(NULL), 0); + + bmp1 = (HBITMAP)SendMessageW(hwnd, STM_GETIMAGE, IMAGE_BITMAP, 0); + ok(bmp1 != NULL, "got NULL\n"); + ok(bmp1 != image, "bmp == image\n"); + test_image(bmp1, TRUE, TRUE, TRUE); + DestroyWindow(hwnd); + + hwnd = CreateWindowA("Static", resource, WS_VISIBLE|WS_CHILD|SS_BITMAP, 5, 5, 100, 100, + hMainWnd, (HMENU)CTRL_ID, GetModuleHandleW(NULL), 0); + + bmp1 = (HBITMAP)SendMessageA(hwnd, STM_GETIMAGE, IMAGE_BITMAP, 0); + ok(bmp1 != NULL, "got NULL\n"); + ok(bmp1 != image, "bmp == image\n"); + test_image(bmp1, TRUE, TRUE, TRUE); + DestroyWindow(hwnd); + DeleteObject(image); }