dc.c 50.4 KB
Newer Older
1 2 3 4
/*
 * Unit tests for dc functions
 *
 * Copyright (c) 2005 Huw Davies
5
 * Copyright (c) 2005 Dmitry Timoshkov
6 7 8 9 10 11 12 13 14 15 16 17 18
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 21
 */

22

23 24 25 26
#define WINVER 0x0501 /* request latest DEVMODE */
#define NONAMELESSSTRUCT
#define NONAMELESSUNION

27 28 29
#include <assert.h>
#include <stdio.h>

30 31 32 33
#include "wine/test.h"
#include "winbase.h"
#include "wingdi.h"
#include "winuser.h"
34
#include "winspool.h"
35 36
#include "winerror.h"

37 38 39 40
#ifndef LAYOUT_LTR
#define LAYOUT_LTR 0
#endif

41 42
static DWORD (WINAPI *pSetLayout)(HDC hdc, DWORD layout);

43 44 45 46 47 48 49 50 51 52 53 54 55 56
static void dump_region(HRGN hrgn)
{
    DWORD i, size;
    RGNDATA *data = NULL;
    RECT *rect;

    if (!hrgn)
    {
        printf( "(null) region\n" );
        return;
    }
    if (!(size = GetRegionData( hrgn, 0, NULL ))) return;
    if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return;
    GetRegionData( hrgn, size, data );
57
    printf( "%d rects:", data->rdh.nCount );
58
    for (i = 0, rect = (RECT *)data->Buffer; i < data->rdh.nCount; i++, rect++)
59
        printf( " (%d,%d)-(%d,%d)", rect->left, rect->top, rect->right, rect->bottom );
60 61 62 63
    printf( "\n" );
    HeapFree( GetProcessHeap(), 0, data );
}

64 65 66 67
static void test_dc_values(void)
{
    HDC hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
    COLORREF color;
68
    int extra;
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96

    ok( hdc != NULL, "CreateDC failed\n" );
    color = SetBkColor( hdc, 0x12345678 );
    ok( color == 0xffffff, "initial color %08x\n", color );
    color = GetBkColor( hdc );
    ok( color == 0x12345678, "wrong color %08x\n", color );
    color = SetBkColor( hdc, 0xffffffff );
    ok( color == 0x12345678, "wrong color %08x\n", color );
    color = GetBkColor( hdc );
    ok( color == 0xffffffff, "wrong color %08x\n", color );
    color = SetBkColor( hdc, 0 );
    ok( color == 0xffffffff, "wrong color %08x\n", color );
    color = GetBkColor( hdc );
    ok( color == 0, "wrong color %08x\n", color );

    color = SetTextColor( hdc, 0xffeeddcc );
    ok( color == 0, "initial color %08x\n", color );
    color = GetTextColor( hdc );
    ok( color == 0xffeeddcc, "wrong color %08x\n", color );
    color = SetTextColor( hdc, 0xffffffff );
    ok( color == 0xffeeddcc, "wrong color %08x\n", color );
    color = GetTextColor( hdc );
    ok( color == 0xffffffff, "wrong color %08x\n", color );
    color = SetTextColor( hdc, 0 );
    ok( color == 0xffffffff, "wrong color %08x\n", color );
    color = GetTextColor( hdc );
    ok( color == 0, "wrong color %08x\n", color );

97 98 99 100 101 102 103 104 105 106 107 108
    extra = GetTextCharacterExtra( hdc );
    ok( extra == 0, "initial extra %d\n", extra );
    SetTextCharacterExtra( hdc, 123 );
    extra = GetTextCharacterExtra( hdc );
    ok( extra == 123, "initial extra %d\n", extra );
    SetMapMode( hdc, MM_LOMETRIC );
    extra = GetTextCharacterExtra( hdc );
    ok( extra == 123, "initial extra %d\n", extra );
    SetMapMode( hdc, MM_TEXT );
    extra = GetTextCharacterExtra( hdc );
    ok( extra == 123, "initial extra %d\n", extra );

109 110 111
    DeleteDC( hdc );
}

112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
static void test_savedc_2(void)
{
    HWND hwnd;
    HDC hdc;
    HRGN hrgn;
    RECT rc, rc_clip;
    int ret;

    hwnd = CreateWindowExA(0, "static", "", WS_POPUP, 0,0,100,100,
                           0, 0, 0, NULL);
    assert(hwnd != 0);
    ShowWindow(hwnd, SW_SHOW);
    UpdateWindow(hwnd);

    hrgn = CreateRectRgn(0, 0, 0, 0);
    assert(hrgn != 0);

    hdc = GetDC(hwnd);
130
    ok(hdc != NULL, "GetDC failed\n");
131 132

    ret = GetClipBox(hdc, &rc_clip);
133
    ok(ret == SIMPLEREGION || broken(ret == COMPLEXREGION), "GetClipBox returned %d instead of SIMPLEREGION\n", ret);
134 135 136
    ret = GetClipRgn(hdc, hrgn);
    ok(ret == 0, "GetClipRgn returned %d instead of 0\n", ret);
    ret = GetRgnBox(hrgn, &rc);
137 138
    ok(ret == NULLREGION, "GetRgnBox returned %d %s instead of NULLREGION\n",
       ret, wine_dbgstr_rect(&rc));
139 140
    /*dump_region(hrgn);*/
    SetRect(&rc, 0, 0, 100, 100);
141 142
    ok(EqualRect(&rc, &rc_clip), "rects are not equal: %s - %s\n", wine_dbgstr_rect(&rc),
       wine_dbgstr_rect(&rc_clip));
143 144 145 146 147

    ret = SaveDC(hdc);
    ok(ret == 1, "ret = %d\n", ret);

    ret = IntersectClipRect(hdc, 0, 0, 50, 50);
148
    if (ret == COMPLEXREGION)
149
    {
150
        /* XP returns COMPLEXREGION although dump_region reports only 1 rect */
151 152 153 154 155 156
        trace("Windows BUG: IntersectClipRect returned %d instead of SIMPLEREGION\n", ret);
        /* let's make sure that it's a simple region */
        ret = GetClipRgn(hdc, hrgn);
        ok(ret == 1, "GetClipRgn returned %d instead of 1\n", ret);
        dump_region(hrgn);
    }
157 158
    else
        ok(ret == SIMPLEREGION, "IntersectClipRect returned %d instead of SIMPLEREGION\n", ret);
159 160

    ret = GetClipBox(hdc, &rc_clip);
161
    ok(ret == SIMPLEREGION || broken(ret == COMPLEXREGION), "GetClipBox returned %d instead of SIMPLEREGION\n", ret);
162
    SetRect(&rc, 0, 0, 50, 50);
163 164
    ok(EqualRect(&rc, &rc_clip), "rects are not equal: %s - %s\n", wine_dbgstr_rect(&rc),
       wine_dbgstr_rect(&rc_clip));
165 166 167 168 169

    ret = RestoreDC(hdc, 1);
    ok(ret, "ret = %d\n", ret);

    ret = GetClipBox(hdc, &rc_clip);
170
    ok(ret == SIMPLEREGION || broken(ret == COMPLEXREGION), "GetClipBox returned %d instead of SIMPLEREGION\n", ret);
171
    SetRect(&rc, 0, 0, 100, 100);
172 173
    ok(EqualRect(&rc, &rc_clip), "rects are not equal: %s - %s\n", wine_dbgstr_rect(&rc),
       wine_dbgstr_rect(&rc_clip));
174 175 176 177 178

    DeleteObject(hrgn);
    ReleaseDC(hwnd, hdc);
    DestroyWindow(hwnd);
}
179

180
static void test_savedc(void)
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
{
    HDC hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
    int ret;

    ok(hdc != NULL, "CreateDC rets %p\n", hdc);

    ret = SaveDC(hdc);
    ok(ret == 1, "ret = %d\n", ret);
    ret = SaveDC(hdc);
    ok(ret == 2, "ret = %d\n", ret);
    ret = SaveDC(hdc);
    ok(ret == 3, "ret = %d\n", ret);
    ret = RestoreDC(hdc, -1);
    ok(ret, "ret = %d\n", ret);
    ret = SaveDC(hdc);
    ok(ret == 3, "ret = %d\n", ret);
    ret = RestoreDC(hdc, 1);
    ok(ret, "ret = %d\n", ret);
    ret = SaveDC(hdc);
    ok(ret == 1, "ret = %d\n", ret);
    ret = SaveDC(hdc);
    ok(ret == 2, "ret = %d\n", ret);
    ret = SaveDC(hdc);
    ok(ret == 3, "ret = %d\n", ret);
    ret = RestoreDC(hdc, -2);
    ok(ret, "ret = %d\n", ret);
    ret = SaveDC(hdc);
    ok(ret == 2, "ret = %d\n", ret);
    ret = RestoreDC(hdc, -2);
    ok(ret, "ret = %d\n", ret);
    ret = SaveDC(hdc);
    ok(ret == 1, "ret = %d\n", ret);
    ret = SaveDC(hdc);
    ok(ret == 2, "ret = %d\n", ret); 
    ret = RestoreDC(hdc, -4);
    ok(!ret, "ret = %d\n", ret);
    ret = RestoreDC(hdc, 3);
    ok(!ret, "ret = %d\n", ret);

220 221 222 223 224 225 226
    /* Under Win9x the following RestoreDC call succeeds and clears the save stack. */
    ret = RestoreDC(hdc, -3);
    ok(!ret ||
       broken(ret), /* Win9x */
       "ret = %d\n", ret);

    /* Trying to clear an empty save stack fails. */
227 228
    ret = RestoreDC(hdc, -3);
    ok(!ret, "ret = %d\n", ret);
229 230 231 232 233 234 235 236 237 238 239 240 241

    ret = SaveDC(hdc);
    ok(ret == 3 ||
       broken(ret == 1), /* Win9x */
       "ret = %d\n", ret);

    /* Under Win9x the following RestoreDC call succeeds and clears the save stack. */
    ret = RestoreDC(hdc, 0);
    ok(!ret ||
       broken(ret), /* Win9x */
       "ret = %d\n", ret);

    /* Trying to clear an empty save stack fails. */
242 243 244 245
    ret = RestoreDC(hdc, 0);
    ok(!ret, "ret = %d\n", ret);

    ret = RestoreDC(hdc, 1);
246 247 248
    ok(ret ||
       broken(!ret), /* Win9x */
       "ret = %d\n", ret);
249 250 251 252

    DeleteDC(hdc);
}

253 254 255 256 257 258 259 260 261 262
static void test_GdiConvertToDevmodeW(void)
{
    DEVMODEW * (WINAPI *pGdiConvertToDevmodeW)(const DEVMODEA *);
    DEVMODEA dmA;
    DEVMODEW *dmW;
    BOOL ret;

    pGdiConvertToDevmodeW = (void *)GetProcAddress(GetModuleHandleA("gdi32.dll"), "GdiConvertToDevmodeW");
    if (!pGdiConvertToDevmodeW)
    {
263
        win_skip("GdiConvertToDevmodeW is not available on this platform\n");
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
        return;
    }

    ret = EnumDisplaySettingsA(NULL, ENUM_CURRENT_SETTINGS, &dmA);
    ok(ret, "EnumDisplaySettingsExA error %u\n", GetLastError());
    ok(dmA.dmSize >= FIELD_OFFSET(DEVMODEA, dmICMMethod), "dmSize is too small: %04x\n", dmA.dmSize);
    ok(dmA.dmSize <= sizeof(DEVMODEA), "dmSize is too large: %04x\n", dmA.dmSize);

    dmW = pGdiConvertToDevmodeW(&dmA);
    ok(dmW->dmSize >= FIELD_OFFSET(DEVMODEW, dmICMMethod), "dmSize is too small: %04x\n", dmW->dmSize);
    ok(dmW->dmSize <= sizeof(DEVMODEW), "dmSize is too large: %04x\n", dmW->dmSize);
    HeapFree(GetProcessHeap(), 0, dmW);

    dmA.dmSize = FIELD_OFFSET(DEVMODEA, dmFields) + sizeof(dmA.dmFields);
    dmW = pGdiConvertToDevmodeW(&dmA);
    ok(dmW->dmSize == FIELD_OFFSET(DEVMODEW, dmFields) + sizeof(dmW->dmFields),
280
       "wrong size %u\n", dmW->dmSize);
281 282 283 284 285 286
    HeapFree(GetProcessHeap(), 0, dmW);

    dmA.dmICMMethod = DMICMMETHOD_NONE;
    dmA.dmSize = FIELD_OFFSET(DEVMODEA, dmICMMethod) + sizeof(dmA.dmICMMethod);
    dmW = pGdiConvertToDevmodeW(&dmA);
    ok(dmW->dmSize == FIELD_OFFSET(DEVMODEW, dmICMMethod) + sizeof(dmW->dmICMMethod),
287
       "wrong size %u\n", dmW->dmSize);
288 289 290 291 292 293 294
    ok(dmW->dmICMMethod == DMICMMETHOD_NONE,
       "expected DMICMMETHOD_NONE, got %u\n", dmW->dmICMMethod);
    HeapFree(GetProcessHeap(), 0, dmW);

    dmA.dmSize = 1024;
    dmW = pGdiConvertToDevmodeW(&dmA);
    ok(dmW->dmSize == FIELD_OFFSET(DEVMODEW, dmPanningHeight) + sizeof(dmW->dmPanningHeight),
295
       "wrong size %u\n", dmW->dmSize);
296
    HeapFree(GetProcessHeap(), 0, dmW);
297 298 299 300 301 302 303 304 305 306 307 308 309

    SetLastError(0xdeadbeef);
    dmA.dmSize = 0;
    dmW = pGdiConvertToDevmodeW(&dmA);
    ok(!dmW, "GdiConvertToDevmodeW should fail\n");
    ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %u\n", GetLastError());

    /* this is the minimal dmSize that XP accepts */
    dmA.dmSize = FIELD_OFFSET(DEVMODEA, dmFields);
    dmW = pGdiConvertToDevmodeW(&dmA);
    ok(dmW->dmSize == FIELD_OFFSET(DEVMODEW, dmFields),
       "expected %04x, got %04x\n", FIELD_OFFSET(DEVMODEW, dmFields), dmW->dmSize);
    HeapFree(GetProcessHeap(), 0, dmW);
310 311
}

312
static void test_device_caps( HDC hdc, HDC ref_dc, const char *descr, int scale )
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
{
    static const int caps[] =
    {
        DRIVERVERSION,
        TECHNOLOGY,
        HORZSIZE,
        VERTSIZE,
        HORZRES,
        VERTRES,
        BITSPIXEL,
        PLANES,
        NUMBRUSHES,
        NUMPENS,
        NUMMARKERS,
        NUMFONTS,
        NUMCOLORS,
        PDEVICESIZE,
        CURVECAPS,
        LINECAPS,
        POLYGONALCAPS,
333
        /* TEXTCAPS broken on printer DC on winxp */
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
        CLIPCAPS,
        RASTERCAPS,
        ASPECTX,
        ASPECTY,
        ASPECTXY,
        LOGPIXELSX,
        LOGPIXELSY,
        SIZEPALETTE,
        NUMRESERVED,
        COLORRES,
        PHYSICALWIDTH,
        PHYSICALHEIGHT,
        PHYSICALOFFSETX,
        PHYSICALOFFSETY,
        SCALINGFACTORX,
        SCALINGFACTORY,
        VREFRESH,
        DESKTOPVERTRES,
        DESKTOPHORZRES,
        BLTALIGNMENT,
354
        SHADEBLENDCAPS
355 356
    };
    unsigned int i;
357 358
    WORD ramp[3][256];
    BOOL ret;
359
    RECT rect;
360
    UINT type;
361 362

    if (GetObjectType( hdc ) == OBJ_METADC)
363
    {
364 365 366 367
        for (i = 0; i < sizeof(caps)/sizeof(caps[0]); i++)
            ok( GetDeviceCaps( hdc, caps[i] ) == (caps[i] == TECHNOLOGY ? DT_METAFILE : 0),
                "wrong caps on %s for %u: %u\n", descr, caps[i],
                GetDeviceCaps( hdc, caps[i] ) );
368 369 370 371 372 373

        SetLastError( 0xdeadbeef );
        ret = GetDeviceGammaRamp( hdc, &ramp );
        ok( !ret, "GetDeviceGammaRamp succeeded on %s\n", descr );
        ok( GetLastError() == ERROR_INVALID_PARAMETER || broken(GetLastError() == 0xdeadbeef), /* nt4 */
            "wrong error %u on %s\n", GetLastError(), descr );
374
        type = GetClipBox( hdc, &rect );
375
        ok( type == ERROR, "GetClipBox returned %d on %s\n", type, descr );
376 377 378 379 380 381

        SetBoundsRect( hdc, NULL, DCB_RESET | DCB_ENABLE );
        SetMapMode( hdc, MM_TEXT );
        Rectangle( hdc, 2, 2, 5, 5 );
        type = GetBoundsRect( hdc, &rect, DCB_RESET );
        ok( !type, "GetBoundsRect succeeded on %s\n", descr );
382 383
        type = SetBoundsRect( hdc, &rect, DCB_RESET | DCB_ENABLE );
        ok( !type, "SetBoundsRect succeeded on %s\n", descr );
384
    }
385
    else
386
    {
387
        for (i = 0; i < sizeof(caps)/sizeof(caps[0]); i++)
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408
        {
            INT precision = 0;
            INT hdc_caps = GetDeviceCaps( hdc, caps[i] );

            switch (caps[i])
            {
            case HORZSIZE:
            case VERTSIZE:
                hdc_caps /= scale;
                precision = 1;
                break;
            case LOGPIXELSX:
            case LOGPIXELSY:
                hdc_caps *= scale;
                break;
            }

            ok( abs(hdc_caps - GetDeviceCaps( ref_dc, caps[i] )) <= precision,
                "mismatched caps on %s for %u: %u/%u (scale %d)\n", descr, caps[i],
                hdc_caps, GetDeviceCaps( ref_dc, caps[i] ), scale );
        }
409

410 411
        SetLastError( 0xdeadbeef );
        ret = GetDeviceGammaRamp( hdc, &ramp );
412 413 414 415 416 417 418 419
        if (GetObjectType( hdc ) != OBJ_DC || GetDeviceCaps( hdc, TECHNOLOGY ) == DT_RASPRINTER)
        {
            ok( !ret, "GetDeviceGammaRamp succeeded on %s (type %d)\n", descr, GetObjectType( hdc ) );
            ok( GetLastError() == ERROR_INVALID_PARAMETER || broken(GetLastError() == 0xdeadbeef), /* nt4 */
                "wrong error %u on %s\n", GetLastError(), descr );
        }
        else
            ok( ret || broken(!ret) /* NT4 */, "GetDeviceGammaRamp failed on %s (type %d), error %u\n", descr, GetObjectType( hdc ), GetLastError() );
420
        type = GetClipBox( hdc, &rect );
421
        todo_wine_if (GetObjectType( hdc ) == OBJ_ENHMETADC)
422
            ok( type == SIMPLEREGION, "GetClipBox returned %d on memdc for %s\n", type, descr );
423

424 425 426 427 428
        type = GetBoundsRect( hdc, &rect, 0 );
        ok( type == DCB_RESET || broken(type == DCB_SET) /* XP */,
            "GetBoundsRect returned type %x for %s\n", type, descr );
        if (type == DCB_RESET)
            ok( rect.left == 0 && rect.top == 0 && rect.right == 0 && rect.bottom == 0,
429 430
                "GetBoundsRect returned %s type %x for %s\n", wine_dbgstr_rect( &rect ),
                type, descr );
431
        type = SetBoundsRect( hdc, NULL, DCB_RESET | DCB_ENABLE );
432 433 434
        ok( type == (DCB_RESET | DCB_DISABLE) || broken(type == (DCB_SET | DCB_ENABLE)) /* XP */,
            "SetBoundsRect returned %x for %s (hdc type %d)\n", type, descr, GetObjectType( hdc ) );

435 436 437
        SetMapMode( hdc, MM_TEXT );
        Rectangle( hdc, 2, 2, 4, 4 );
        type = GetBoundsRect( hdc, &rect, DCB_RESET );
438
        todo_wine_if (GetObjectType( hdc ) == OBJ_ENHMETADC || (GetObjectType( hdc ) == OBJ_DC && GetDeviceCaps( hdc, TECHNOLOGY ) == DT_RASPRINTER))
439
            ok( rect.left == 2 && rect.top == 2 && rect.right == 4 && rect.bottom == 4 && type == DCB_SET,
440 441
                "GetBoundsRect returned %s type %x for %s\n", wine_dbgstr_rect( &rect ),
                type, descr );
442 443
    }

444
    type = GetClipBox( ref_dc, &rect );
445
    if (type != COMPLEXREGION && type != ERROR)  /* region can be complex on multi-monitor setups */
446
    {
447 448
        RECT ref_rect;

449
        ok( type == SIMPLEREGION, "GetClipBox returned %d on %s\n", type, descr );
450 451
        if (GetDeviceCaps( ref_dc, TECHNOLOGY ) == DT_RASDISPLAY)
        {
452
            todo_wine_if (GetSystemMetrics( SM_CXSCREEN ) != GetSystemMetrics( SM_CXVIRTUALSCREEN ))
453 454 455 456
                ok( GetDeviceCaps( ref_dc, DESKTOPHORZRES ) == GetSystemMetrics( SM_CXSCREEN ),
                    "Got DESKTOPHORZRES %d on %s, expected %d\n",
                    GetDeviceCaps( ref_dc, DESKTOPHORZRES ), descr, GetSystemMetrics( SM_CXSCREEN ) );

457
            todo_wine_if (GetSystemMetrics( SM_CYSCREEN ) != GetSystemMetrics( SM_CYVIRTUALSCREEN ))
458 459 460 461 462 463 464 465 466 467 468 469 470 471
                ok( GetDeviceCaps( ref_dc, DESKTOPVERTRES ) == GetSystemMetrics( SM_CYSCREEN ),
                    "Got DESKTOPVERTRES %d on %s, expected %d\n",
                    GetDeviceCaps( ref_dc, DESKTOPVERTRES ), descr, GetSystemMetrics( SM_CYSCREEN ) );

            SetRect( &ref_rect, GetSystemMetrics( SM_XVIRTUALSCREEN ), GetSystemMetrics( SM_YVIRTUALSCREEN ),
                     GetSystemMetrics( SM_XVIRTUALSCREEN ) + GetSystemMetrics( SM_CXVIRTUALSCREEN ),
                     GetSystemMetrics( SM_YVIRTUALSCREEN ) + GetSystemMetrics( SM_CYVIRTUALSCREEN ) );
        }
        else
        {
            SetRect( &ref_rect, 0, 0, GetDeviceCaps( ref_dc, DESKTOPHORZRES ),
                     GetDeviceCaps( ref_dc, DESKTOPVERTRES ) );
        }

472
        todo_wine_if (GetDeviceCaps( ref_dc, TECHNOLOGY ) == DT_RASDISPLAY && GetObjectType( hdc ) != OBJ_ENHMETADC &&
473
            (GetSystemMetrics( SM_XVIRTUALSCREEN ) || GetSystemMetrics( SM_YVIRTUALSCREEN )))
474 475
            ok( EqualRect( &rect, &ref_rect ), "GetClipBox returned %s on %s\n",
                wine_dbgstr_rect( &rect ), descr );
476
    }
477 478 479 480 481 482 483 484

    SetBoundsRect( ref_dc, NULL, DCB_RESET | DCB_ACCUMULATE );
    SetMapMode( ref_dc, MM_TEXT );
    Rectangle( ref_dc, 3, 3, 5, 5 );
    type = GetBoundsRect( ref_dc, &rect, DCB_RESET );
    /* it may or may not work on non-memory DCs */
    ok( (rect.left == 0 && rect.top == 0 && rect.right == 0 && rect.bottom == 0 && type == DCB_RESET) ||
        (rect.left == 3 && rect.top == 3 && rect.right == 5 && rect.bottom == 5 && type == DCB_SET),
485
        "GetBoundsRect returned %s type %x on %s\n", wine_dbgstr_rect( &rect ), type, descr );
486

487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
    if (GetObjectType( hdc ) == OBJ_MEMDC)
    {
        char buffer[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)];
        BITMAPINFO *info = (BITMAPINFO *)buffer;
        HBITMAP dib, old;

        memset( buffer, 0, sizeof(buffer) );
        info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
        info->bmiHeader.biWidth = 16;
        info->bmiHeader.biHeight = 16;
        info->bmiHeader.biPlanes = 1;
        info->bmiHeader.biBitCount = 8;
        info->bmiHeader.biCompression = BI_RGB;
        dib = CreateDIBSection( ref_dc, info, DIB_RGB_COLORS, NULL, NULL, 0 );
        old = SelectObject( hdc, dib );

        for (i = 0; i < sizeof(caps)/sizeof(caps[0]); i++)
            ok( GetDeviceCaps( hdc, caps[i] ) == GetDeviceCaps( ref_dc, caps[i] ),
                "mismatched caps on %s and DIB for %u: %u/%u\n", descr, caps[i],
                GetDeviceCaps( hdc, caps[i] ), GetDeviceCaps( ref_dc, caps[i] ) );

508 509 510 511 512 513
        SetLastError( 0xdeadbeef );
        ret = GetDeviceGammaRamp( hdc, &ramp );
        ok( !ret, "GetDeviceGammaRamp succeeded on %s\n", descr );
        ok( GetLastError() == ERROR_INVALID_PARAMETER || broken(GetLastError() == 0xdeadbeef), /* nt4 */
            "wrong error %u on %s\n", GetLastError(), descr );

514
        type = GetClipBox( hdc, &rect );
515
        ok( type == SIMPLEREGION, "GetClipBox returned %d on memdc for %s\n", type, descr );
516
        ok( rect.left == 0 && rect.top == 0 && rect.right == 16 && rect.bottom == 16,
517
            "GetClipBox returned %s on memdc for %s\n", wine_dbgstr_rect( &rect ), descr );
518 519 520 521 522 523

        SetBoundsRect( hdc, NULL, DCB_RESET | DCB_ENABLE );
        SetMapMode( hdc, MM_TEXT );
        Rectangle( hdc, 5, 5, 12, 14 );
        type = GetBoundsRect( hdc, &rect, DCB_RESET );
        ok( rect.left == 5 && rect.top == 5 && rect.right == 12 && rect.bottom == 14 && type == DCB_SET,
524 525
            "GetBoundsRect returned %s type %x on memdc for %s\n", wine_dbgstr_rect( &rect ),
            type, descr );
526

527 528 529
        SelectObject( hdc, old );
        DeleteObject( dib );
    }
530 531 532 533

    /* restore hdc state */
    SetBoundsRect( hdc, NULL, DCB_RESET | DCB_DISABLE );
    SetBoundsRect( ref_dc, NULL, DCB_RESET | DCB_DISABLE );
534 535
}

536 537 538
static void test_CreateCompatibleDC(void)
{
    BOOL bRet;
539
    HDC hdc, hNewDC, hdcMetafile, screen_dc;
540 541
    HBITMAP bitmap;
    INT caps;
542
    DEVMODEA dm;
543 544

    bitmap = CreateBitmap( 10, 10, 1, 1, NULL );
545

546
    bRet = EnumDisplaySettingsA(NULL, ENUM_CURRENT_SETTINGS, &dm);
547 548 549
    ok(bRet, "EnumDisplaySettingsEx failed\n");
    dm.u1.s1.dmScale = 200;
    dm.dmFields |= DM_SCALE;
550
    hdc = CreateDCA( "DISPLAY", NULL, NULL, &dm );
551

552
    screen_dc = CreateDCA( "DISPLAY", NULL, NULL, NULL );
553
    test_device_caps( hdc, screen_dc, "display dc", 1 );
554
    ResetDCA( hdc, &dm );
555 556 557
    test_device_caps( hdc, screen_dc, "display dc", 1 );
    DeleteDC( hdc );

558
    /* Create a DC compatible with the screen */
559 560 561 562 563
    hdc = CreateCompatibleDC(NULL);
    ok(hdc != NULL, "CreateCompatibleDC returned %p\n", hdc);
    ok( SelectObject( hdc, bitmap ) != 0, "SelectObject failed\n" );
    caps = GetDeviceCaps( hdc, TECHNOLOGY );
    ok( caps == DT_RASDISPLAY, "wrong caps %u\n", caps );
564

565
    test_device_caps( hdc, screen_dc, "display dc", 1 );
566

567
    /* Delete this DC, this should succeed */
568
    bRet = DeleteDC(hdc);
569 570 571
    ok(bRet == TRUE, "DeleteDC returned %u\n", bRet);

    /* Try to create a DC compatible to the deleted DC. This has to fail */
572
    hNewDC = CreateCompatibleDC(hdc);
573
    ok(hNewDC == NULL, "CreateCompatibleDC returned %p\n", hNewDC);
574 575 576 577 578 579 580 581 582

    hdc = GetDC( 0 );
    hdcMetafile = CreateEnhMetaFileA(hdc, NULL, NULL, NULL);
    ok(hdcMetafile != 0, "CreateEnhMetaFileA failed\n");
    hNewDC = CreateCompatibleDC( hdcMetafile );
    ok(hNewDC != NULL, "CreateCompatibleDC failed\n");
    ok( SelectObject( hNewDC, bitmap ) != 0, "SelectObject failed\n" );
    caps = GetDeviceCaps( hdcMetafile, TECHNOLOGY );
    ok( caps == DT_RASDISPLAY, "wrong caps %u\n", caps );
583
    test_device_caps( hdcMetafile, hdc, "enhmetafile dc", 1 );
584
    ResetDCA( hdcMetafile, &dm );
585
    test_device_caps( hdcMetafile, hdc, "enhmetafile dc", 1 );
586 587 588 589 590 591 592 593 594 595
    DeleteDC( hNewDC );
    DeleteEnhMetaFile( CloseEnhMetaFile( hdcMetafile ));
    ReleaseDC( 0, hdc );

    hdcMetafile = CreateMetaFileA(NULL);
    ok(hdcMetafile != 0, "CreateEnhMetaFileA failed\n");
    hNewDC = CreateCompatibleDC( hdcMetafile );
    ok(hNewDC == NULL, "CreateCompatibleDC succeeded\n");
    caps = GetDeviceCaps( hdcMetafile, TECHNOLOGY );
    ok( caps == DT_METAFILE, "wrong caps %u\n", caps );
596
    test_device_caps( hdcMetafile, screen_dc, "metafile dc", 1 );
597
    ResetDCA( hdcMetafile, &dm );
598
    test_device_caps( hdcMetafile, screen_dc, "metafile dc", 1 );
599 600 601
    DeleteMetaFile( CloseMetaFile( hdcMetafile ));

    DeleteObject( bitmap );
602
    DeleteDC( screen_dc );
603 604
}

605 606
static void test_DC_bitmap(void)
{
607
    PIXELFORMATDESCRIPTOR descr;
608 609 610 611 612
    HDC hdc, hdcmem;
    DWORD bits[64];
    HBITMAP hbmp, oldhbmp;
    COLORREF col;
    int i, bitspixel;
613
    int ret, ret2;
614 615 616 617 618 619 620 621 622 623

    /* fill bitmap data with b&w pattern */
    for( i = 0; i < 64; i++) bits[i] = i & 1 ? 0 : 0xffffff;

    hdc = GetDC(0);
    ok( hdc != NULL, "CreateDC rets %p\n", hdc);
    bitspixel = GetDeviceCaps( hdc, BITSPIXEL);
    /* create a memory dc */
    hdcmem = CreateCompatibleDC( hdc);
    ok( hdcmem != NULL, "CreateCompatibleDC rets %p\n", hdcmem);
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648

    /* test DescribePixelFormat with descr == NULL */
    ret2 = DescribePixelFormat(hdcmem, 0, sizeof(descr), NULL);
    ok(ret2 > 0, "expected ret2 > 0, got %d\n", ret2);
    ret = DescribePixelFormat(hdcmem, 1, sizeof(descr), NULL);
    ok(ret == ret2, "expected ret == %d, got %d\n", ret2, ret);
    ret = DescribePixelFormat(hdcmem, 0x10000, sizeof(descr), NULL);
    ok(ret == ret2, "expected ret == %d, got %d\n", ret2, ret);

    /* test DescribePixelFormat with descr != NULL */
    memset(&descr, 0, sizeof(descr));
    ret = DescribePixelFormat(hdcmem, 0, sizeof(descr), &descr);
    ok(ret == 0, "expected ret == 0, got %d\n", ret);
    ok(descr.nSize == 0, "expected descr.nSize == 0, got %d\n", descr.nSize);

    memset(&descr, 0, sizeof(descr));
    ret = DescribePixelFormat(hdcmem, 1, sizeof(descr), &descr);
    ok(ret == ret2, "expected ret == %d, got %d\n", ret2, ret);
    ok(descr.nSize == sizeof(descr), "expected desc.nSize == sizeof(descr), got %d\n", descr.nSize);

    memset(&descr, 0, sizeof(descr));
    ret = DescribePixelFormat(hdcmem, 0x10000, sizeof(descr), &descr);
    ok(ret == 0, "expected ret == 0, got %d\n", ret);
    ok(descr.nSize == 0, "expected descr.nSize == 0, got %d\n", descr.nSize);

649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705
    /* test monochrome bitmap: should always work */
    hbmp = CreateBitmap(32, 32, 1, 1, bits);
    ok( hbmp != NULL, "CreateBitmap returns %p\n", hbmp);
    oldhbmp = SelectObject( hdcmem, hbmp);
    ok( oldhbmp != NULL, "SelectObject returned NULL\n" ); /* a memdc always has a bitmap selected */
    col = GetPixel( hdcmem, 0, 0);
    ok( col == 0xffffff, "GetPixel returned %08x, expected 00ffffff\n", col);
    col = GetPixel( hdcmem, 1, 1);
    ok( col == 0x000000, "GetPixel returned %08x, expected 00000000\n", col);
    col = GetPixel( hdcmem, 100, 1);
    ok( col == CLR_INVALID, "GetPixel returned %08x, expected ffffffff\n", col);
    SelectObject( hdcmem, oldhbmp);
    DeleteObject( hbmp);

    /* test with 2 bits color depth, not likely to succeed */
    hbmp = CreateBitmap(16, 16, 1, 2, bits);
    ok( hbmp != NULL, "CreateBitmap returns %p\n", hbmp);
    oldhbmp = SelectObject( hdcmem, hbmp);
    if( bitspixel != 2)
        ok( !oldhbmp, "SelectObject of a bitmap with 2 bits/pixel should return  NULL\n");
    if( oldhbmp) SelectObject( hdcmem, oldhbmp);
    DeleteObject( hbmp);

    /* test with 16 bits color depth, might succeed */
    hbmp = CreateBitmap(6, 6, 1, 16, bits);
    ok( hbmp != NULL, "CreateBitmap returns %p\n", hbmp);
    oldhbmp = SelectObject( hdcmem, hbmp);
    if( bitspixel == 16) {
        ok( oldhbmp != NULL, "SelectObject returned NULL\n" );
        col = GetPixel( hdcmem, 0, 0);
        ok( col == 0xffffff,
            "GetPixel of a bitmap with 16 bits/pixel returned %08x, expected 00ffffff\n", col);
        col = GetPixel( hdcmem, 1, 1);
        ok( col == 0x000000,
            "GetPixel of a bitmap with 16 bits/pixel returned returned %08x, expected 00000000\n", col);
    }
    if( oldhbmp) SelectObject( hdcmem, oldhbmp);
    DeleteObject( hbmp);

    /* test with 32 bits color depth, probably succeed */
    hbmp = CreateBitmap(4, 4, 1, 32, bits);
    ok( hbmp != NULL, "CreateBitmap returns %p\n", hbmp);
    oldhbmp = SelectObject( hdcmem, hbmp);
    if( bitspixel == 32) {
        ok( oldhbmp != NULL, "SelectObject returned NULL\n" );
        col = GetPixel( hdcmem, 0, 0);
        ok( col == 0xffffff,
            "GetPixel of a bitmap with 32 bits/pixel returned %08x, expected 00ffffff\n", col);
        col = GetPixel( hdcmem, 1, 1);
        ok( col == 0x000000,
            "GetPixel of a bitmap with 32 bits/pixel returned returned %08x, expected 00000000\n", col);
    }
    if( oldhbmp) SelectObject( hdcmem, oldhbmp);
    DeleteObject( hbmp);
    ReleaseDC( 0, hdc );
}

706 707 708 709
static void test_DeleteDC(void)
{
    HWND hwnd;
    HDC hdc, hdc_test;
710
    WNDCLASSEXA cls;
711 712 713 714 715 716 717 718 719 720 721 722 723 724
    int ret;

    /* window DC */
    hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0,0,100,100,
                           0, 0, 0, NULL);
    ok(hwnd != 0, "CreateWindowExA failed\n");

    hdc = GetDC(hwnd);
    ok(hdc != 0, "GetDC failed\n");
    ret = GetObjectType(hdc);
    ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);
    ret = DeleteDC(hdc);
    ok(ret, "DeleteDC failed\n");
    ret = GetObjectType(hdc);
725
    ok(!ret || broken(ret) /* win9x */, "GetObjectType should fail for a deleted DC\n");
726 727 728 729 730 731 732 733

    hdc = GetWindowDC(hwnd);
    ok(hdc != 0, "GetDC failed\n");
    ret = GetObjectType(hdc);
    ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);
    ret = DeleteDC(hdc);
    ok(ret, "DeleteDC failed\n");
    ret = GetObjectType(hdc);
734
    ok(!ret || broken(ret) /* win9x */, "GetObjectType should fail for a deleted DC\n");
735 736 737 738 739 740 741 742 743 744 745 746 747 748

    DestroyWindow(hwnd);

    /* desktop window DC */
    hwnd = GetDesktopWindow();
    ok(hwnd != 0, "GetDesktopWindow failed\n");

    hdc = GetDC(hwnd);
    ok(hdc != 0, "GetDC failed\n");
    ret = GetObjectType(hdc);
    ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);
    ret = DeleteDC(hdc);
    ok(ret, "DeleteDC failed\n");
    ret = GetObjectType(hdc);
749
    ok(!ret || broken(ret) /* win9x */, "GetObjectType should fail for a deleted DC\n");
750 751 752 753 754 755 756 757

    hdc = GetWindowDC(hwnd);
    ok(hdc != 0, "GetDC failed\n");
    ret = GetObjectType(hdc);
    ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);
    ret = DeleteDC(hdc);
    ok(ret, "DeleteDC failed\n");
    ret = GetObjectType(hdc);
758
    ok(!ret || broken(ret) /* win9x */, "GetObjectType should fail for a deleted DC\n");
759 760 761 762 763

    /* CS_CLASSDC */
    memset(&cls, 0, sizeof(cls));
    cls.cbSize = sizeof(cls);
    cls.style = CS_CLASSDC;
764
    cls.hInstance = GetModuleHandleA(NULL);
765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795
    cls.lpszClassName = "Wine class DC";
    cls.lpfnWndProc = DefWindowProcA;
    ret = RegisterClassExA(&cls);
    ok(ret, "RegisterClassExA failed\n");

    hwnd = CreateWindowExA(0, "Wine class DC", NULL, WS_POPUP|WS_VISIBLE, 0,0,100,100,
                           0, 0, 0, NULL);
    ok(hwnd != 0, "CreateWindowExA failed\n");

    hdc = GetDC(hwnd);
    ok(hdc != 0, "GetDC failed\n");
    ret = GetObjectType(hdc);
    ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);
    ret = DeleteDC(hdc);
    ok(ret, "DeleteDC failed\n");
    ret = GetObjectType(hdc);
    ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);
    ret = ReleaseDC(hwnd, hdc);
    ok(ret, "ReleaseDC failed\n");
    ret = GetObjectType(hdc);
    ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);

    hdc_test = hdc;

    hdc = GetWindowDC(hwnd);
    ok(hdc != 0, "GetDC failed\n");
    ret = GetObjectType(hdc);
    ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);
    ret = DeleteDC(hdc);
    ok(ret, "DeleteDC failed\n");
    ret = GetObjectType(hdc);
796
    ok(!ret || broken(ret) /* win9x */, "GetObjectType should fail for a deleted DC\n");
797 798 799 800 801 802

    DestroyWindow(hwnd);

    ret = GetObjectType(hdc_test);
    ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);

803
    ret = UnregisterClassA("Wine class DC", GetModuleHandleA(NULL));
804 805 806 807 808 809 810 811 812
    ok(ret, "UnregisterClassA failed\n");

    ret = GetObjectType(hdc_test);
    ok(!ret, "GetObjectType should fail for a deleted DC\n");

    /* CS_OWNDC */
    memset(&cls, 0, sizeof(cls));
    cls.cbSize = sizeof(cls);
    cls.style = CS_OWNDC;
813
    cls.hInstance = GetModuleHandleA(NULL);
814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842
    cls.lpszClassName = "Wine own DC";
    cls.lpfnWndProc = DefWindowProcA;
    ret = RegisterClassExA(&cls);
    ok(ret, "RegisterClassExA failed\n");

    hwnd = CreateWindowExA(0, "Wine own DC", NULL, WS_POPUP|WS_VISIBLE, 0,0,100,100,
                           0, 0, 0, NULL);
    ok(hwnd != 0, "CreateWindowExA failed\n");

    hdc = GetDC(hwnd);
    ok(hdc != 0, "GetDC failed\n");
    ret = GetObjectType(hdc);
    ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);
    ret = DeleteDC(hdc);
    ok(ret, "DeleteDC failed\n");
    ret = GetObjectType(hdc);
    ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);
    ret = ReleaseDC(hwnd, hdc);
    ok(ret, "ReleaseDC failed\n");
    ret = GetObjectType(hdc);
    ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);

    hdc = GetWindowDC(hwnd);
    ok(hdc != 0, "GetDC failed\n");
    ret = GetObjectType(hdc);
    ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);
    ret = DeleteDC(hdc);
    ok(ret, "DeleteDC failed\n");
    ret = GetObjectType(hdc);
843
    ok(!ret || broken(ret) /* win9x */, "GetObjectType should fail for a deleted DC\n");
844 845 846

    DestroyWindow(hwnd);

847
    ret = UnregisterClassA("Wine own DC", GetModuleHandleA(NULL));
848 849 850
    ok(ret, "UnregisterClassA failed\n");
}

851
static void test_boundsrect(void)
852
{
853 854
    char buffer[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)];
    BITMAPINFO *info = (BITMAPINFO *)buffer;
855
    HDC hdc;
856
    HBITMAP bitmap, dib, old;
857
    RECT rect, expect, set_rect;
858
    UINT ret;
859
    int i, level;
860

861 862 863
    hdc = CreateCompatibleDC(0);
    ok(hdc != NULL, "CreateCompatibleDC failed\n");
    bitmap = CreateCompatibleBitmap( hdc, 200, 200 );
864
    old = SelectObject( hdc, bitmap );
865 866

    ret = GetBoundsRect(hdc, NULL, 0);
867
    ok(ret == 0, "Expected GetBoundsRect to return 0, got %u\n", ret);
868 869

    ret = GetBoundsRect(hdc, NULL, ~0U);
870 871 872 873 874 875 876 877 878 879
    ok(ret == 0, "Expected GetBoundsRect to return 0, got %u\n", ret);

    /* Test parameter handling order. */
    SetRect(&set_rect, 10, 20, 40, 50);
    ret = SetBoundsRect(hdc, &set_rect, DCB_SET);
    ok(ret & DCB_RESET,
       "Expected return flag DCB_RESET to be set, got %u\n", ret);

    ret = GetBoundsRect(hdc, NULL, DCB_RESET);
    ok(ret == 0,
880 881
       "Expected GetBoundsRect to return 0, got %u\n", ret);

882 883 884
    ret = GetBoundsRect(hdc, &rect, 0);
    ok(ret == DCB_RESET,
       "Expected GetBoundsRect to return DCB_RESET, got %u\n", ret);
885
    SetRectEmpty(&expect);
886 887
    ok(EqualRect(&rect, &expect), "Expected output rectangle (0,0)-(0,0), got %s\n",
       wine_dbgstr_rect(&rect));
888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907

    ret = GetBoundsRect(NULL, NULL, 0);
    ok(ret == 0, "Expected GetBoundsRect to return 0, got %u\n", ret);

    ret = GetBoundsRect(NULL, NULL, ~0U);
    ok(ret == 0, "Expected GetBoundsRect to return 0, got %u\n", ret);

    ret = SetBoundsRect(NULL, NULL, 0);
    ok(ret == 0, "Expected SetBoundsRect to return 0, got %u\n", ret);

    ret = SetBoundsRect(NULL, NULL, ~0U);
    ok(ret == 0, "Expected SetBoundsRect to return 0, got %u\n", ret);

    SetRect(&set_rect, 10, 20, 40, 50);
    ret = SetBoundsRect(hdc, &set_rect, DCB_SET);
    ok(ret == (DCB_RESET | DCB_DISABLE), "SetBoundsRect returned %x\n", ret);

    ret = GetBoundsRect(hdc, &rect, 0);
    ok(ret == DCB_SET, "GetBoundsRect returned %x\n", ret);
    SetRect(&expect, 10, 20, 40, 50);
908
    ok(EqualRect(&rect, &expect), "Got %s\n", wine_dbgstr_rect(&rect));
909 910 911 912 913 914

    SetMapMode( hdc, MM_ANISOTROPIC );
    SetViewportExtEx( hdc, 2, 2, NULL );
    ret = GetBoundsRect(hdc, &rect, 0);
    ok(ret == DCB_SET, "GetBoundsRect returned %x\n", ret);
    SetRect(&expect, 5, 10, 20, 25);
915
    ok(EqualRect(&rect, &expect), "Got %s\n", wine_dbgstr_rect(&rect));
916 917 918 919 920

    SetViewportOrgEx( hdc, 20, 30, NULL );
    ret = GetBoundsRect(hdc, &rect, 0);
    ok(ret == DCB_SET, "GetBoundsRect returned %x\n", ret);
    SetRect(&expect, -5, -5, 10, 10);
921
    ok(EqualRect(&rect, &expect), "Got %s\n", wine_dbgstr_rect(&rect));
922 923 924 925 926 927 928 929

    SetRect(&set_rect, 10, 20, 40, 50);
    ret = SetBoundsRect(hdc, &set_rect, DCB_SET);
    ok(ret == (DCB_SET | DCB_DISABLE), "SetBoundsRect returned %x\n", ret);

    ret = GetBoundsRect(hdc, &rect, 0);
    ok(ret == DCB_SET, "GetBoundsRect returned %x\n", ret);
    SetRect(&expect, 10, 20, 40, 50);
930
    ok(EqualRect(&rect, &expect), "Got %s\n", wine_dbgstr_rect(&rect));
931 932 933 934 935 936

    SetMapMode( hdc, MM_TEXT );
    SetViewportOrgEx( hdc, 0, 0, NULL );
    ret = GetBoundsRect(hdc, &rect, 0);
    ok(ret == DCB_SET, "GetBoundsRect returned %x\n", ret);
    SetRect(&expect, 40, 70, 100, 130);
937
    ok(EqualRect(&rect, &expect), "Got %s\n", wine_dbgstr_rect(&rect));
938 939

    if (pSetLayout)
940
    {
941 942 943 944
        pSetLayout( hdc, LAYOUT_RTL );
        ret = GetBoundsRect(hdc, &rect, 0);
        ok(ret == DCB_SET, "GetBoundsRect returned %x\n", ret);
        SetRect(&expect, 159, 70, 99, 130);
945
        ok(EqualRect(&rect, &expect), "Got %s\n", wine_dbgstr_rect(&rect));
946
        SetRect(&set_rect, 50, 25, 30, 35);
947
        ret = SetBoundsRect(hdc, &set_rect, DCB_SET);
948 949 950 951
        ok(ret == (DCB_SET | DCB_DISABLE), "SetBoundsRect returned %x\n", ret);
        ret = GetBoundsRect(hdc, &rect, 0);
        ok(ret == DCB_SET, "GetBoundsRect returned %x\n", ret);
        SetRect(&expect, 50, 25, 30, 35);
952
        ok(EqualRect(&rect, &expect), "Got %s\n", wine_dbgstr_rect(&rect));
953

954
        pSetLayout( hdc, LAYOUT_LTR );
955
        ret = GetBoundsRect(hdc, &rect, 0);
956 957
        ok(ret == DCB_SET, "GetBoundsRect returned %x\n", ret);
        SetRect(&expect, 149, 25, 169, 35);
958
        ok(EqualRect(&rect, &expect), "Got %s\n", wine_dbgstr_rect(&rect));
959 960
    }

961 962 963 964 965 966 967 968
    /* empty rect resets, except on nt4 */
    SetRect(&expect, 20, 20, 10, 10);
    ret = SetBoundsRect(hdc, &set_rect, DCB_SET);
    ok(ret == (DCB_SET | DCB_DISABLE), "SetBoundsRect returned %x\n", ret);
    ret = GetBoundsRect(hdc, &rect, 0);
    ok(ret == DCB_RESET || broken(ret == DCB_SET)  /* nt4 */,
       "GetBoundsRect returned %x\n", ret);
    if (ret == DCB_RESET)
969
    {
970
        SetRectEmpty(&expect);
971
        ok(EqualRect(&rect, &expect), "Got %s\n", wine_dbgstr_rect(&rect));
972

973 974 975 976 977
        SetRect(&expect, 20, 20, 20, 20);
        ret = SetBoundsRect(hdc, &set_rect, DCB_SET);
        ok(ret == (DCB_RESET | DCB_DISABLE), "SetBoundsRect returned %x\n", ret);
        ret = GetBoundsRect(hdc, &rect, 0);
        ok(ret == DCB_RESET, "GetBoundsRect returned %x\n", ret);
978
        SetRectEmpty(&expect);
979
        ok(EqualRect(&rect, &expect), "Got %s\n", wine_dbgstr_rect(&rect));
980 981
    }

982 983 984 985 986 987
    SetBoundsRect( hdc, NULL, DCB_RESET | DCB_ENABLE );
    MoveToEx( hdc, 10, 10, NULL );
    LineTo( hdc, 20, 20 );
    ret = GetBoundsRect( hdc, &rect, 0 );
    ok( ret == DCB_SET, "GetBoundsRect returned %x\n", ret );
    SetRect( &expect, 10, 10, 21, 21 );
988
    ok( EqualRect(&rect, &expect), "Got %s\n", wine_dbgstr_rect(&rect));
989 990 991 992 993
    SetRect( &rect, 8, 8, 23, 23 );
    expect = rect;
    SetBoundsRect( hdc, &rect, DCB_ACCUMULATE );
    ret = GetBoundsRect( hdc, &rect, 0 );
    ok( ret == DCB_SET, "GetBoundsRect returned %x\n", ret );
994
    ok(EqualRect(&rect, &expect), "Got %s\n", wine_dbgstr_rect(&rect));
995 996 997 998 999 1000

    level = SaveDC( hdc );
    LineTo( hdc, 30, 25 );
    ret = GetBoundsRect( hdc, &rect, 0 );
    ok( ret == DCB_SET, "GetBoundsRect returned %x\n", ret );
    SetRect( &expect, 8, 8, 31, 26 );
1001
    ok(EqualRect(&rect, &expect), "Got %s\n", wine_dbgstr_rect(&rect));
1002 1003 1004 1005 1006
    SetBoundsRect( hdc, NULL, DCB_DISABLE );
    LineTo( hdc, 40, 40 );
    ret = GetBoundsRect( hdc, &rect, 0 );
    ok( ret == DCB_SET, "GetBoundsRect returned %x\n", ret );
    SetRect( &expect, 8, 8, 31, 26 );
1007
    ok(EqualRect(&rect, &expect), "Got %s\n", wine_dbgstr_rect(&rect));
1008 1009 1010 1011 1012
    SetRect( &rect, 6, 6, 30, 30 );
    SetBoundsRect( hdc, &rect, DCB_ACCUMULATE );
    ret = GetBoundsRect( hdc, &rect, 0 );
    ok( ret == DCB_SET, "GetBoundsRect returned %x\n", ret );
    SetRect( &expect, 6, 6, 31, 30 );
1013
    ok(EqualRect(&rect, &expect), "Got %s\n", wine_dbgstr_rect(&rect));
1014 1015 1016 1017

    RestoreDC( hdc, level );
    ret = GetBoundsRect( hdc, &rect, 0 );
    ok( ret == DCB_SET, "GetBoundsRect returned %x\n", ret );
1018
    ok(EqualRect(&rect, &expect), "Got %s\n", wine_dbgstr_rect(&rect));
1019 1020 1021
    LineTo( hdc, 40, 40 );
    ret = GetBoundsRect( hdc, &rect, 0 );
    ok( ret == DCB_SET, "GetBoundsRect returned %x\n", ret );
1022
    ok(EqualRect(&rect, &expect), "Got %s\n", wine_dbgstr_rect(&rect));
1023 1024 1025 1026 1027

    SelectObject( hdc, old );
    ret = GetBoundsRect( hdc, &rect, 0 );
    ok( ret == DCB_SET, "GetBoundsRect returned %x\n", ret );
    SetRect( &expect, 6, 6, 1, 1 );
1028
    ok(EqualRect(&rect, &expect), "Got %s\n", wine_dbgstr_rect(&rect));
1029 1030 1031 1032 1033 1034 1035
    SetBoundsRect( hdc, NULL, DCB_ENABLE );
    LineTo( hdc, 50, 40 );

    SelectObject( hdc, bitmap );
    ret = GetBoundsRect( hdc, &rect, 0 );
    ok( ret == DCB_SET, "GetBoundsRect returned %x\n", ret );
    SetRect( &expect, 6, 6, 51, 41 );
1036
    ok(EqualRect(&rect, &expect), "Got %s\n", wine_dbgstr_rect(&rect));
1037 1038 1039 1040 1041
    SelectObject( hdc, GetStockObject( NULL_PEN ));
    LineTo( hdc, 50, 50 );
    ret = GetBoundsRect( hdc, &rect, 0 );
    ok( ret == DCB_SET, "GetBoundsRect returned %x\n", ret );
    SetRect( &expect, 6, 6, 51, 51 );
1042
    ok(EqualRect(&rect, &expect), "Got %s\n", wine_dbgstr_rect(&rect));
1043 1044 1045

    memset( buffer, 0, sizeof(buffer) );
    info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1046 1047
    info->bmiHeader.biWidth = 256;
    info->bmiHeader.biHeight = 256;
1048 1049 1050 1051 1052 1053 1054 1055 1056
    info->bmiHeader.biPlanes = 1;
    info->bmiHeader.biBitCount = 8;
    info->bmiHeader.biCompression = BI_RGB;
    dib = CreateDIBSection( 0, info, DIB_RGB_COLORS, NULL, NULL, 0 );
    ok( dib != 0, "failed to create DIB\n" );
    SelectObject( hdc, dib );
    ret = GetBoundsRect( hdc, &rect, 0 );
    ok( ret == DCB_SET, "GetBoundsRect returned %x\n", ret );
    SetRect( &expect, 6, 6, 51, 51 );
1057
    ok(EqualRect(&rect, &expect), "Got %s\n", wine_dbgstr_rect(&rect));
1058 1059 1060 1061
    LineTo( hdc, 55, 30 );
    ret = GetBoundsRect( hdc, &rect, 0 );
    ok( ret == DCB_SET, "GetBoundsRect returned %x\n", ret );
    SetRect( &expect, 6, 6, 56, 51 );
1062
    ok(EqualRect(&rect, &expect), "Got %s\n", wine_dbgstr_rect(&rect));
1063
    LineTo( hdc, 300, 30 );
1064 1065
    ret = GetBoundsRect( hdc, &rect, 0 );
    ok( ret == DCB_SET, "GetBoundsRect returned %x\n", ret );
1066
    SetRect( &expect, 6, 6, 256, 51 );
1067
    ok(EqualRect(&rect, &expect), "Got %s\n", wine_dbgstr_rect(&rect));
1068
    LineTo( hdc, -300, -300 );
1069 1070
    ret = GetBoundsRect( hdc, &rect, 0 );
    ok( ret == DCB_SET, "GetBoundsRect returned %x\n", ret );
1071
    SetRect( &expect, 0, 0, 256, 51 );
1072
    ok(EqualRect(&rect, &expect), "Got %s\n", wine_dbgstr_rect(&rect));
1073

1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112
    /* test the wide pen heuristics */
    SetBoundsRect( hdc, NULL, DCB_ENABLE | DCB_RESET );
    for (i = 0; i < 1000; i++)
    {
        static const UINT endcaps[3] = { PS_ENDCAP_ROUND, PS_ENDCAP_SQUARE, PS_ENDCAP_FLAT };
        static const UINT joins[3] = { PS_JOIN_ROUND, PS_JOIN_BEVEL, PS_JOIN_MITER };
        LOGBRUSH brush = { BS_SOLID, RGB(0,0,0), 0 };
        UINT join = joins[i % 3];
        UINT endcap = endcaps[(i / 3) % 3];
        INT inflate, width = 1 + i / 9;
        HPEN pen = ExtCreatePen( PS_GEOMETRIC | join | endcap | PS_SOLID, width, &brush, 0, NULL );
        HPEN old = SelectObject( hdc, pen );
        MoveToEx( hdc, 100, 100, NULL );
        LineTo( hdc, 160, 100 );
        LineTo( hdc, 100, 160 );
        LineTo( hdc, 160, 160 );
        GetBoundsRect( hdc, &rect, DCB_RESET );
        SetRect( &expect, 100, 100, 161, 161 );

        inflate = width + 2;
        if (join == PS_JOIN_MITER)
        {
            inflate *= 5;
            if (endcap == PS_ENDCAP_SQUARE)
                InflateRect( &expect, (inflate * 3 + 1) / 2, (inflate * 3 + 1) / 2 );
            else
                InflateRect( &expect, inflate, inflate );
        }
        else
        {
            if (endcap == PS_ENDCAP_SQUARE)
                InflateRect( &expect, inflate - inflate / 4, inflate - inflate / 4 );
            else
                InflateRect( &expect, (inflate + 1) / 2, (inflate + 1) / 2 );
        }
        expect.left   = max( expect.left, 0 );
        expect.top    = max( expect.top, 0 );
        expect.right  = min( expect.right, 256 );
        expect.bottom = min( expect.bottom, 256 );
1113 1114
        ok(EqualRect(&rect, &expect), "Got %s expected %s %u/%x/%x\n", wine_dbgstr_rect(&rect),
           wine_dbgstr_rect(&expect), width, endcap, join);
1115 1116 1117
        DeleteObject( SelectObject( hdc, old ));
    }

1118 1119
    DeleteDC( hdc );
    DeleteObject( bitmap );
1120
    DeleteObject( dib );
1121 1122
}

1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158
static void test_desktop_colorres(void)
{
    HDC hdc = GetDC(NULL);
    int bitspixel, colorres;

    bitspixel = GetDeviceCaps(hdc, BITSPIXEL);
    ok(bitspixel != 0, "Expected to get valid BITSPIXEL capability value\n");

    colorres = GetDeviceCaps(hdc, COLORRES);
    ok(colorres != 0 ||
       broken(colorres == 0), /* Win9x */
       "Expected to get valid COLORRES capability value\n");

    if (colorres)
    {
        switch (bitspixel)
        {
        case 8:
            ok(colorres == 18,
               "Expected COLORRES to be 18, got %d\n", colorres);
            break;
        case 16:
            ok(colorres == 16,
               "Expected COLORRES to be 16, got %d\n", colorres);
            break;
        case 24:
        case 32:
            ok(colorres == 24,
               "Expected COLORRES to be 24, got %d\n", bitspixel);
            break;
        default:
            ok(0, "Got unknown BITSPIXEL %d with COLORRES %d\n", bitspixel, colorres);
            break;
        }
    }

1159
    ReleaseDC(NULL, hdc);
1160 1161
}

1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200
static void test_gamma(void)
{
    BOOL ret;
    HDC hdc = GetDC(NULL);
    WORD oldramp[3][256], ramp[3][256];
    INT i;

    ret = GetDeviceGammaRamp(hdc, &oldramp);
    if (!ret)
    {
        win_skip("GetDeviceGammaRamp failed, skipping tests\n");
        goto done;
    }

    /* try to set back old ramp */
    ret = SetDeviceGammaRamp(hdc, &oldramp);
    if (!ret)
    {
        win_skip("SetDeviceGammaRamp failed, skipping tests\n");
        goto done;
    }

    memcpy(ramp, oldramp, sizeof(ramp));

    /* set one color ramp to zeros */
    memset(ramp[0], 0, sizeof(ramp[0]));
    ret = SetDeviceGammaRamp(hdc, &ramp);
    ok(!ret, "SetDeviceGammaRamp succeeded\n");

    /* set one color ramp to a flat straight rising line */
    for (i = 0; i < 256; i++) ramp[0][i] = i;
    ret = SetDeviceGammaRamp(hdc, &ramp);
    todo_wine ok(!ret, "SetDeviceGammaRamp succeeded\n");

    /* set one color ramp to a steep straight rising line */
    for (i = 0; i < 256; i++) ramp[0][i] = i * 256;
    ret = SetDeviceGammaRamp(hdc, &ramp);
    ok(ret, "SetDeviceGammaRamp failed\n");

1201 1202 1203 1204 1205 1206 1207
    /* try a bright gamma ramp */
    ramp[0][0] = 0;
    ramp[0][1] = 0x7FFF;
    for (i = 2; i < 256; i++) ramp[0][i] = 0xFFFF;
    ret = SetDeviceGammaRamp(hdc, &ramp);
    ok(!ret, "SetDeviceGammaRamp succeeded\n");

1208
    /* try ramps which are not uniform */
1209 1210 1211
    ramp[0][0] = 0;
    for (i = 1; i < 256; i++) ramp[0][i] = ramp[0][i - 1] + 512;
    ret = SetDeviceGammaRamp(hdc, &ramp);
1212
    ok(ret, "SetDeviceGammaRamp failed\n");
1213 1214 1215 1216 1217 1218 1219 1220
    ramp[0][0] = 0;
    for (i = 2; i < 256; i+=2)
    {
        ramp[0][i - 1] = ramp[0][i - 2];
        ramp[0][i] = ramp[0][i - 2] + 512;
    }
    ret = SetDeviceGammaRamp(hdc, &ramp);
    ok(ret, "SetDeviceGammaRamp failed\n");
1221

1222 1223 1224 1225 1226 1227 1228 1229
    /* cleanup: set old ramp again */
    ret = SetDeviceGammaRamp(hdc, &oldramp);
    ok(ret, "SetDeviceGammaRamp failed\n");

done:
    ReleaseDC(NULL, hdc);
}

1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240
static BOOL is_postscript_printer(HDC hdc)
{
    char tech[256];

    if (ExtEscape(hdc, GETTECHNOLOGY, 0, NULL, sizeof(tech), tech) > 0)
        return strcmp(tech, "PostScript") == 0;

    return FALSE;
}

static HDC create_printer_dc(int scale, BOOL reset)
1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275
{
    char buffer[260];
    DWORD len;
    PRINTER_INFO_2A *pbuf = NULL;
    DRIVER_INFO_3A *dbuf = NULL;
    HANDLE hprn = 0;
    HDC hdc = 0;
    HMODULE winspool = LoadLibraryA( "winspool.drv" );
    BOOL (WINAPI *pOpenPrinterA)(LPSTR, HANDLE *, LPPRINTER_DEFAULTSA);
    BOOL (WINAPI *pGetDefaultPrinterA)(LPSTR, LPDWORD);
    BOOL (WINAPI *pGetPrinterA)(HANDLE, DWORD, LPBYTE, DWORD, LPDWORD);
    BOOL (WINAPI *pGetPrinterDriverA)(HANDLE, LPSTR, DWORD, LPBYTE, DWORD, LPDWORD);
    BOOL (WINAPI *pClosePrinter)(HANDLE);

    pGetDefaultPrinterA = (void *)GetProcAddress( winspool, "GetDefaultPrinterA" );
    pOpenPrinterA = (void *)GetProcAddress( winspool, "OpenPrinterA" );
    pGetPrinterA = (void *)GetProcAddress( winspool, "GetPrinterA" );
    pGetPrinterDriverA = (void *)GetProcAddress( winspool, "GetPrinterDriverA" );
    pClosePrinter = (void *)GetProcAddress( winspool, "ClosePrinter" );

    if (!pGetDefaultPrinterA || !pOpenPrinterA || !pGetPrinterA || !pGetPrinterDriverA || !pClosePrinter)
        goto done;

    len = sizeof(buffer);
    if (!pGetDefaultPrinterA( buffer, &len )) goto done;
    if (!pOpenPrinterA( buffer, &hprn, NULL )) goto done;

    pGetPrinterA( hprn, 2, NULL, 0, &len );
    pbuf = HeapAlloc( GetProcessHeap(), 0, len );
    if (!pGetPrinterA( hprn, 2, (LPBYTE)pbuf, len, &len )) goto done;

    pGetPrinterDriverA( hprn, NULL, 3, NULL, 0, &len );
    dbuf = HeapAlloc( GetProcessHeap(), 0, len );
    if (!pGetPrinterDriverA( hprn, NULL, 3, (LPBYTE)dbuf, len, &len )) goto done;

1276 1277 1278
    pbuf->pDevMode->u1.s1.dmScale = scale;
    pbuf->pDevMode->dmFields |= DM_SCALE;

1279
    hdc = CreateDCA( dbuf->pDriverPath, pbuf->pPrinterName, pbuf->pPortName, pbuf->pDevMode );
1280 1281 1282 1283
    trace( "hdc %p for driver '%s' printer '%s' port '%s' is %sPostScript\n", hdc,
           dbuf->pDriverPath, pbuf->pPrinterName, pbuf->pPortName,
           is_postscript_printer(hdc) ? "" : "NOT " );

1284
    if (reset) ResetDCA( hdc, pbuf->pDevMode );
1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295
done:
    HeapFree( GetProcessHeap(), 0, dbuf );
    HeapFree( GetProcessHeap(), 0, pbuf );
    if (hprn) pClosePrinter( hprn );
    if (winspool) FreeLibrary( winspool );
    if (!hdc) skip( "could not create a DC for the default printer\n" );
    return hdc;
}

static void test_printer_dc(void)
{
1296
    HDC memdc, display_memdc, enhmf_dc;
1297 1298
    HBITMAP orig, bmp;
    DWORD ret;
1299 1300 1301 1302 1303 1304 1305 1306 1307
    HDC hdc, hdc_200;

    hdc = create_printer_dc(100, FALSE);
    hdc_200 = create_printer_dc(200, FALSE);

    if (!hdc || !hdc_200) return;

    test_device_caps( hdc, hdc_200, "printer dc", is_postscript_printer(hdc) ? 2 : 1 );
    DeleteDC( hdc_200 );
1308

1309 1310 1311
    hdc_200 = create_printer_dc(200, TRUE);
    test_device_caps( hdc, hdc_200, "printer dc", is_postscript_printer(hdc) ? 2 : 1 );
    DeleteDC( hdc_200 );
1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332

    memdc = CreateCompatibleDC( hdc );
    display_memdc = CreateCompatibleDC( 0 );

    ok( memdc != NULL, "CreateCompatibleDC failed for printer\n" );
    ok( display_memdc != NULL, "CreateCompatibleDC failed for screen\n" );

    ret = GetDeviceCaps( hdc, TECHNOLOGY );
    ok( ret == DT_RASPRINTER, "wrong type %u\n", ret );

    ret = GetDeviceCaps( memdc, TECHNOLOGY );
    ok( ret == DT_RASPRINTER, "wrong type %u\n", ret );

    ret = GetDeviceCaps( display_memdc, TECHNOLOGY );
    ok( ret == DT_RASDISPLAY, "wrong type %u\n", ret );

    bmp = CreateBitmap( 100, 100, 1, GetDeviceCaps( hdc, BITSPIXEL ), NULL );
    orig = SelectObject( memdc, bmp );
    ok( orig != NULL, "SelectObject failed\n" );
    ok( BitBlt( hdc, 10, 10, 20, 20, memdc, 0, 0, SRCCOPY ), "BitBlt failed\n" );

1333
    test_device_caps( memdc, hdc, "printer dc", 1 );
1334

1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346
    ok( !SelectObject( display_memdc, bmp ), "SelectObject succeeded\n" );
    SelectObject( memdc, orig );
    DeleteObject( bmp );

    bmp = CreateBitmap( 100, 100, 1, 1, NULL );
    orig = SelectObject( display_memdc, bmp );
    ok( orig != NULL, "SelectObject failed\n" );
    ok( !SelectObject( memdc, bmp ), "SelectObject succeeded\n" );
    ok( BitBlt( hdc, 10, 10, 20, 20, display_memdc, 0, 0, SRCCOPY ), "BitBlt failed\n" );
    ok( BitBlt( memdc, 10, 10, 20, 20, display_memdc, 0, 0, SRCCOPY ), "BitBlt failed\n" );
    ok( BitBlt( display_memdc, 10, 10, 20, 20, memdc, 0, 0, SRCCOPY ), "BitBlt failed\n" );

1347 1348 1349
    ret = GetPixel( hdc, 0, 0 );
    ok( ret == CLR_INVALID, "wrong pixel value %x\n", ret );

1350 1351
    enhmf_dc = CreateEnhMetaFileA( hdc, NULL, NULL, NULL );
    ok(enhmf_dc != 0, "CreateEnhMetaFileA failed\n");
1352 1353 1354 1355 1356 1357
    test_device_caps( enhmf_dc, hdc, "enhmetafile printer dc", 1 );
    DeleteEnhMetaFile( CloseEnhMetaFile( enhmf_dc ));

    enhmf_dc = CreateEnhMetaFileA( hdc, NULL, NULL, NULL );
    ok(enhmf_dc != 0, "CreateEnhMetaFileA failed\n");
    test_device_caps( enhmf_dc, hdc, "enhmetafile printer dc", 1 );
1358 1359
    DeleteEnhMetaFile( CloseEnhMetaFile( enhmf_dc ));

1360 1361 1362 1363 1364 1365
    DeleteDC( memdc );
    DeleteDC( display_memdc );
    DeleteDC( hdc );
    DeleteObject( bmp );
}

1366 1367
START_TEST(dc)
{
1368
    pSetLayout = (void *)GetProcAddress( GetModuleHandleA("gdi32.dll"), "SetLayout");
1369
    test_dc_values();
1370
    test_savedc();
1371
    test_savedc_2();
1372
    test_GdiConvertToDevmodeW();
1373
    test_CreateCompatibleDC();
1374
    test_DC_bitmap();
1375
    test_DeleteDC();
1376
    test_boundsrect();
1377
    test_desktop_colorres();
1378
    test_gamma();
1379
    test_printer_dc();
1380
}