Signed-off-by: Jeff Smith whydoubt@gmail.com --- Testing revealed that SetBkMode() does not treat 'invalid' values as one might assume. Discovered this when working on another issue. Note that fixing this to match Windows simplifies one of the tests for that bug.
dlls/gdi32/dc.c | 12 ++---------- dlls/gdi32/tests/dc.c | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 11 deletions(-)
diff --git a/dlls/gdi32/dc.c b/dlls/gdi32/dc.c index 230f1949e8d..0bac9c27d16 100644 --- a/dlls/gdi32/dc.c +++ b/dlls/gdi32/dc.c @@ -1598,20 +1598,12 @@ INT WINAPI SetBkMode( HDC hdc, INT mode ) INT ret = 0; DC *dc;
- if ((mode <= 0) || (mode > BKMODE_LAST)) - { - SetLastError(ERROR_INVALID_PARAMETER); - return 0; - } if ((dc = get_dc_ptr( hdc ))) { PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetBkMode ); mode = physdev->funcs->pSetBkMode( physdev, mode ); - if (mode) - { - ret = dc->backgroundMode; - dc->backgroundMode = mode; - } + ret = dc->backgroundMode; + dc->backgroundMode = mode; release_dc_ptr( dc ); } return ret; diff --git a/dlls/gdi32/tests/dc.c b/dlls/gdi32/tests/dc.c index b4a89b213d2..ce9fca1653f 100644 --- a/dlls/gdi32/tests/dc.c +++ b/dlls/gdi32/tests/dc.c @@ -40,7 +40,7 @@ static void test_dc_values(void) { HDC hdc = CreateDCA("DISPLAY", NULL, NULL, NULL); COLORREF color; - int extra; + int extra, mode;
ok( hdc != NULL, "CreateDC failed\n" ); color = SetBkColor( hdc, 0x12345678 ); @@ -81,6 +81,23 @@ static void test_dc_values(void) extra = GetTextCharacterExtra( hdc ); ok( extra == 123, "initial extra %d\n", extra );
+ mode = SetBkMode( hdc, TRANSPARENT ); + ok( mode == OPAQUE, "initial mode %08x\n", mode ); + mode = GetBkMode( hdc ); + ok( mode == TRANSPARENT, "wrong mode %08x\n", mode ); + mode = SetBkMode( hdc, OPAQUE ); + ok( mode == TRANSPARENT, "wrong mode %08x\n", mode ); + mode = GetBkMode( hdc ); + ok( mode == OPAQUE, "wrong mode %08x\n", mode ); + mode = SetBkMode( hdc, 0 ); + ok( mode == OPAQUE, "wrong mode %08x\n", mode ); + mode = GetBkMode( hdc ); + ok( mode == 0, "wrong mode %08x\n", mode ); + mode = SetBkMode( hdc, BKMODE_LAST + 1 ); + ok( mode == 0, "wrong mode %08x\n", mode ); + mode = GetBkMode( hdc ); + ok( mode == BKMODE_LAST + 1, "wrong mode %08x\n", mode ); + DeleteDC( hdc ); }