Windows often reuses the DC handle for a different window (which may be in another process).
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/user32/tests/dce.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/dlls/user32/tests/dce.c b/dlls/user32/tests/dce.c index 18ded3357de..017506d9aa4 100644 --- a/dlls/user32/tests/dce.c +++ b/dlls/user32/tests/dce.c @@ -54,7 +54,7 @@ static void test_dc_attributes(void)
ok( WindowFromDC( hdc ) == hwnd_cache, "wrong window\n" ); ReleaseDC( hwnd_cache, hdc ); - ok( WindowFromDC( hdc ) == 0, "wrong window\n" ); + ok( WindowFromDC( hdc ) != hwnd_cache, "wrong window\n" ); hdc = GetDC( hwnd_cache ); rop = GetROP2( hdc ); ok( rop == def_rop, "wrong ROP2 %d after release\n", rop ); @@ -124,7 +124,7 @@ static void test_dc_attributes(void) ok( caps == 0, "got %d\n", caps ); caps = GetDeviceCaps( old_hdc, NUMCOLORS ); ok( caps == 0, "got %d\n", caps ); - ok( WindowFromDC( old_hdc ) == 0, "wrong window\n" ); + ok( WindowFromDC( old_hdc ) != hwnd_cache, "wrong window\n" );
hdc = GetDC(0); caps = GetDeviceCaps( hdc, HORZRES ); @@ -645,7 +645,7 @@ static void test_destroyed_window(void) DestroyWindow( hwnd_cache ); rop = GetROP2( dc ); ok( rop == 0, "wrong ROP2 %d\n", rop ); - ok( WindowFromDC( dc ) == 0, "wrong window\n" ); + ok( WindowFromDC( dc ) != hwnd_cache, "wrong window\n" ); ok( !ReleaseDC( hwnd_cache, dc ), "ReleaseDC succeeded\n" ); dc = GetDC( hwnd_cache ); ok( !dc, "Got a non-NULL DC (%p) for a destroyed window\n", dc ); @@ -674,7 +674,7 @@ static void test_destroyed_window(void)
rop = GetROP2( dc ); ok( rop == R2_WHITE, "wrong ROP2 %d\n", rop ); - ok( WindowFromDC( dc ) == 0, "wrong window\n" ); + ok( WindowFromDC( dc ) != hwnd_classdc2, "wrong window\n" ); ok( !ReleaseDC( hwnd_classdc2, dc ), "ReleaseDC succeeded\n" ); dc = GetDC( hwnd_classdc2 ); ok( !dc, "Got a non-NULL DC (%p) for a destroyed window\n", dc ); @@ -688,7 +688,7 @@ static void test_destroyed_window(void)
rop = GetROP2( dc ); ok( rop == R2_WHITE, "wrong ROP2 %d\n", rop ); - ok( WindowFromDC( dc ) == 0, "wrong window\n" ); + ok( WindowFromDC( dc ) != hwnd_classdc, "wrong window\n" ); ok( !ReleaseDC( hwnd_classdc, dc ), "ReleaseDC succeeded\n" ); dc = GetDC( hwnd_classdc ); ok( !dc, "Got a non-NULL DC (%p) for a destroyed window\n", dc ); @@ -702,7 +702,7 @@ static void test_destroyed_window(void)
rop = GetROP2( dc ); ok( rop == 0, "wrong ROP2 %d\n", rop ); - ok( WindowFromDC( dc ) == 0, "wrong window\n" ); + ok( WindowFromDC( dc ) != hwnd_owndc, "wrong window\n" ); ok( !ReleaseDC( hwnd_owndc, dc ), "ReleaseDC succeeded\n" ); dc = GetDC( hwnd_owndc ); ok( !dc, "Got a non-NULL DC (%p) for a destroyed window\n", dc );
It may be useful for demonstrating cache behaviour, but fails too frequently on Windows to be reliable.
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- Interestingly enough, I see the same reuse behaviour even without DCX_CACHE. Only removing DCX_USESTYLE is enough to prevent the same handle from being reassigned.
dlls/user32/tests/dce.c | 8 -------- 1 file changed, 8 deletions(-)
diff --git a/dlls/user32/tests/dce.c b/dlls/user32/tests/dce.c index 017506d9aa4..fd33c9078dd 100644 --- a/dlls/user32/tests/dce.c +++ b/dlls/user32/tests/dce.c @@ -650,14 +650,6 @@ static void test_destroyed_window(void) dc = GetDC( hwnd_cache ); ok( !dc, "Got a non-NULL DC (%p) for a destroyed window\n", dc );
- for (i = 0; i < 30; i++) - { - dc = hdcs[i] = GetDCEx( hwnd_parent, 0, DCX_CACHE | DCX_USESTYLE ); - if (dc == old_dc) break; - } - ok( i < 30, "DC for destroyed window not reused\n" ); - while (i > 0) ReleaseDC( hwnd_parent, hdcs[--i] ); - dc = GetDC( hwnd_classdc ); SetROP2( dc, R2_WHITE ); rop = GetROP2( dc );