user32: Windows allows to delete a busy DC, add a test case.
Dmitry Timoshkov
dmitry at codeweavers.com
Wed Feb 24 03:11:03 CST 2010
The test passes under XP SP3.
---
dlls/gdi32/tests/dc.c | 43 ++++++++++++++++++++++++++++++++++++++++++-
dlls/user32/painting.c | 17 ++++-------------
2 files changed, 46 insertions(+), 14 deletions(-)
diff --git a/dlls/gdi32/tests/dc.c b/dlls/gdi32/tests/dc.c
index 1efde38..ce8f5a4 100644
--- a/dlls/gdi32/tests/dc.c
+++ b/dlls/gdi32/tests/dc.c
@@ -69,7 +69,7 @@ static void test_savedc_2(void)
assert(hrgn != 0);
hdc = GetDC(hwnd);
- ok(hdc != NULL, "CreateDC rets %p\n", hdc);
+ ok(hdc != NULL, "GetDC failed\n");
ret = GetClipBox(hdc, &rc_clip);
ok(ret == SIMPLEREGION, "GetClipBox returned %d instead of SIMPLEREGION\n", ret);
@@ -328,6 +328,46 @@ static void test_DC_bitmap(void)
ReleaseDC( 0, hdc );
}
+static void test_DeleteDC(void)
+{
+ HWND hwnd;
+ HDC hdc;
+ int ret;
+
+ hwnd = CreateWindowExA(0, "static", "", 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, "GetObjectType should fail for a deleted DC\n");
+
+ DestroyWindow(hwnd);
+
+ 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);
+ ok(!ret, "GetObjectType should fail for a deleted DC\n");
+}
+
START_TEST(dc)
{
test_savedc();
@@ -335,4 +375,5 @@ START_TEST(dc)
test_GdiConvertToDevmodeW();
test_CreateCompatibleDC();
test_DC_bitmap();
+ test_DeleteDC();
}
diff --git a/dlls/user32/painting.c b/dlls/user32/painting.c
index cde642c..c9c3d9f 100644
--- a/dlls/user32/painting.c
+++ b/dlls/user32/painting.c
@@ -490,22 +490,13 @@ static BOOL CALLBACK dc_hook( HDC hDC, WORD code, DWORD_PTR data, LPARAM lParam
WARN("DC is not in use!\n");
break;
case DCHC_DELETEDC:
- /*
- * Windows will not let you delete a DC that is busy
- * (between GetDC and ReleaseDC)
- */
USER_Lock();
if (dce->count)
- {
WARN("Application trying to delete a busy DC %p\n", dce->hdc);
- retv = FALSE;
- }
- else
- {
- list_remove( &dce->entry );
- if (dce->clip_rgn) DeleteObject( dce->clip_rgn );
- HeapFree( GetProcessHeap(), 0, dce );
- }
+
+ list_remove( &dce->entry );
+ if (dce->clip_rgn) DeleteObject( dce->clip_rgn );
+ HeapFree( GetProcessHeap(), 0, dce );
USER_Unlock();
break;
}
--
1.7.0
More information about the wine-patches
mailing list