Commit be8501ac authored by Dmitry Timoshkov's avatar Dmitry Timoshkov Committed by Alexandre Julliard

user32: Check control type in the STM_SETIMAGE/STM_SETICON handlers before calling the helpers.

parent 9b7faf98
...@@ -103,7 +103,6 @@ static HICON STATIC_SetIcon( HWND hwnd, HICON hicon, DWORD style ) ...@@ -103,7 +103,6 @@ static HICON STATIC_SetIcon( HWND hwnd, HICON hicon, DWORD style )
HICON prevIcon; HICON prevIcon;
SIZE size; SIZE size;
if ((style & SS_TYPEMASK) != SS_ICON) return 0;
if (hicon && !get_icon_size( hicon, &size )) if (hicon && !get_icon_size( hicon, &size ))
{ {
WARN("hicon != 0, but invalid\n"); WARN("hicon != 0, but invalid\n");
...@@ -138,7 +137,6 @@ static HBITMAP STATIC_SetBitmap( HWND hwnd, HBITMAP hBitmap, DWORD style ) ...@@ -138,7 +137,6 @@ static HBITMAP STATIC_SetBitmap( HWND hwnd, HBITMAP hBitmap, DWORD style )
{ {
HBITMAP hOldBitmap; HBITMAP hOldBitmap;
if ((style & SS_TYPEMASK) != SS_BITMAP) return 0;
if (hBitmap && GetObjectType(hBitmap) != OBJ_BITMAP) { if (hBitmap && GetObjectType(hBitmap) != OBJ_BITMAP) {
WARN("hBitmap != 0, but it's not a bitmap\n"); WARN("hBitmap != 0, but it's not a bitmap\n");
return 0; return 0;
...@@ -174,7 +172,6 @@ static HBITMAP STATIC_SetBitmap( HWND hwnd, HBITMAP hBitmap, DWORD style ) ...@@ -174,7 +172,6 @@ static HBITMAP STATIC_SetBitmap( HWND hwnd, HBITMAP hBitmap, DWORD style )
*/ */
static HENHMETAFILE STATIC_SetEnhMetaFile( HWND hwnd, HENHMETAFILE hEnhMetaFile, DWORD style ) static HENHMETAFILE STATIC_SetEnhMetaFile( HWND hwnd, HENHMETAFILE hEnhMetaFile, DWORD style )
{ {
if ((style & SS_TYPEMASK) != SS_ENHMETAFILE) return 0;
if (hEnhMetaFile && GetObjectType(hEnhMetaFile) != OBJ_ENHMETAFILE) { if (hEnhMetaFile && GetObjectType(hEnhMetaFile) != OBJ_ENHMETAFILE) {
WARN("hEnhMetaFile != 0, but it's not an enhanced metafile\n"); WARN("hEnhMetaFile != 0, but it's not an enhanced metafile\n");
return 0; return 0;
...@@ -501,13 +498,16 @@ LRESULT StaticWndProc_common( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ...@@ -501,13 +498,16 @@ LRESULT StaticWndProc_common( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam
case STM_SETIMAGE: case STM_SETIMAGE:
switch(wParam) { switch(wParam) {
case IMAGE_BITMAP: case IMAGE_BITMAP:
if (style != SS_BITMAP) return 0;
lResult = (LRESULT)STATIC_SetBitmap( hwnd, (HBITMAP)lParam, full_style ); lResult = (LRESULT)STATIC_SetBitmap( hwnd, (HBITMAP)lParam, full_style );
break; break;
case IMAGE_ENHMETAFILE: case IMAGE_ENHMETAFILE:
if (style != SS_ENHMETAFILE) return 0;
lResult = (LRESULT)STATIC_SetEnhMetaFile( hwnd, (HENHMETAFILE)lParam, full_style ); lResult = (LRESULT)STATIC_SetEnhMetaFile( hwnd, (HENHMETAFILE)lParam, full_style );
break; break;
case IMAGE_ICON: case IMAGE_ICON:
case IMAGE_CURSOR: case IMAGE_CURSOR:
if (style != SS_ICON) return 0;
lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)lParam, full_style ); lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)lParam, full_style );
break; break;
default: default:
...@@ -518,6 +518,7 @@ LRESULT StaticWndProc_common( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ...@@ -518,6 +518,7 @@ LRESULT StaticWndProc_common( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam
break; break;
case STM_SETICON: case STM_SETICON:
if (style != SS_ICON) return 0;
lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)wParam, full_style ); lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)wParam, full_style );
STATIC_TryPaintFcn( hwnd, full_style ); STATIC_TryPaintFcn( hwnd, full_style );
break; break;
......
...@@ -20,9 +20,11 @@ ...@@ -20,9 +20,11 @@
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#define STRICT #include "windef.h"
#define WIN32_LEAN_AND_MEAN #include "winbase.h"
#include <windows.h> #include "wingdi.h"
#define OEMRESOURCE
#include "winuser.h"
#include "wine/test.h" #include "wine/test.h"
...@@ -189,6 +191,118 @@ static void test_set_image(void) ...@@ -189,6 +191,118 @@ static void test_set_image(void)
DeleteObject(image); DeleteObject(image);
} }
static void test_STM_SETIMAGE(void)
{
DWORD type;
HWND hwnd;
HICON icon, old_image;
HBITMAP bmp;
HENHMETAFILE emf;
HDC dc;
icon = LoadIconW(0, (LPCWSTR)IDI_APPLICATION);
bmp = LoadBitmapW(0, (LPCWSTR)OBM_CLOSE);
dc = CreateEnhMetaFileW(0, NULL, NULL, NULL);
LineTo(dc, 1, 1);
emf = CloseEnhMetaFile(dc);
DeleteDC(dc);
for (type = SS_LEFT; type < SS_ETCHEDFRAME; type++)
{
winetest_push_context("%u", type);
hwnd = build_static(type);
ok(hwnd != 0, "failed to create static type %#x\n", type);
/* set icon */
g_nReceivedColorStatic = 0;
old_image = (HICON)SendMessageW(hwnd, STM_SETIMAGE, IMAGE_ICON, (LPARAM)icon);
ok(!old_image, "got %p\n", old_image);
if (type == SS_ICON)
ok(g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
else
ok(!g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
g_nReceivedColorStatic = 0;
old_image = (HICON)SendMessageW(hwnd, STM_SETIMAGE, IMAGE_ICON, (LPARAM)icon);
if (type == SS_ICON)
{
ok(old_image != 0, "got %p\n", old_image);
ok(g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
}
else
{
ok(!old_image, "got %p\n", old_image);
ok(!g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
}
g_nReceivedColorStatic = 0;
old_image = (HICON)SendMessageW(hwnd, STM_SETICON, (WPARAM)icon, 0);
if (type == SS_ICON)
{
ok(old_image != 0, "got %p\n", old_image);
ok(g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
}
else
{
ok(!old_image, "got %p\n", old_image);
ok(!g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
}
/* set bitmap */
g_nReceivedColorStatic = 0;
old_image = (HICON)SendMessageW(hwnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)bmp);
ok(!old_image, "got %p\n", old_image);
if (type == SS_BITMAP)
ok(g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
else
ok(!g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
g_nReceivedColorStatic = 0;
old_image = (HICON)SendMessageW(hwnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)bmp);
if (type == SS_BITMAP)
{
ok(old_image != 0, "got %p\n", old_image);
ok(g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
}
else
{
ok(!old_image, "got %p\n", old_image);
ok(!g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
}
/* set EMF */
g_nReceivedColorStatic = 0;
old_image = (HICON)SendMessageW(hwnd, STM_SETIMAGE, IMAGE_ENHMETAFILE, (LPARAM)emf);
ok(!old_image, "got %p\n", old_image);
if (type == SS_ENHMETAFILE)
ok(g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
else
ok(!g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
g_nReceivedColorStatic = 0;
old_image = (HICON)SendMessageW(hwnd, STM_SETIMAGE, IMAGE_ENHMETAFILE, (LPARAM)emf);
if (type == SS_ENHMETAFILE)
{
ok(old_image != 0, "got %p\n", old_image);
ok(g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
}
else
{
ok(!old_image, "got %p\n", old_image);
ok(!g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
}
DestroyWindow(hwnd);
winetest_pop_context();
}
DestroyIcon(icon);
DeleteObject(bmp);
DeleteEnhMetaFile(emf);
}
START_TEST(static) START_TEST(static)
{ {
static const char szClassName[] = "testclass"; static const char szClassName[] = "testclass";
...@@ -222,6 +336,7 @@ START_TEST(static) ...@@ -222,6 +336,7 @@ START_TEST(static)
test_updates(SS_ETCHEDVERT, TODO_COUNT); test_updates(SS_ETCHEDVERT, TODO_COUNT);
test_set_text(); test_set_text();
test_set_image(); test_set_image();
test_STM_SETIMAGE();
DestroyWindow(hMainWnd); DestroyWindow(hMainWnd);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment