ReactOS 0.4.15-dev-8131-g4988de4
GetDCEx.c File Reference
#include "precomp.h"
Include dependency graph for GetDCEx.c:

Go to the source code of this file.

Macros

#define DCX_USESTYLE   0x00010000
 

Functions

void Test_GetDCEx_Params ()
 
static LRESULT CALLBACK WndProc (_In_ HWND hwnd, _In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam)
 
static ATOM RegisterClassHelper (PSTR pszClassName, UINT style, WNDPROC pfnWndProc)
 
static HWND CreateWindowHelper (PSZ pszClassName, PSZ pszTitle)
 
static void Test_GetDCEx_Cached ()
 
static void Test_GetDCEx_CS_OWNDC ()
 
static void Test_GetDCEx_CS_CLASSDC ()
 
static void Test_GetDCEx_CS_Mixed ()
 
static void Test_GetDCEx_CS_SwitchedStyle ()
 
 START_TEST (GetDCEx)
 

Macro Definition Documentation

◆ DCX_USESTYLE

#define DCX_USESTYLE   0x00010000

Definition at line 10 of file GetDCEx.c.

Function Documentation

◆ CreateWindowHelper()

static HWND CreateWindowHelper ( PSZ  pszClassName,
PSZ  pszTitle 
)
static

Definition at line 54 of file GetDCEx.c.

57{
58 return CreateWindowA(pszClassName,
59 pszTitle,
63 100,
64 100,
65 NULL,
66 NULL,
67 0,
68 NULL);
69}
#define NULL
Definition: types.h:112
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
#define CreateWindowA(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4315
#define CW_USEDEFAULT
Definition: winuser.h:225

Referenced by Test_GetDCEx_Cached(), Test_GetDCEx_CS_CLASSDC(), Test_GetDCEx_CS_Mixed(), Test_GetDCEx_CS_OWNDC(), and Test_GetDCEx_CS_SwitchedStyle().

◆ RegisterClassHelper()

static ATOM RegisterClassHelper ( PSTR  pszClassName,
UINT  style,
WNDPROC  pfnWndProc 
)
static

Definition at line 31 of file GetDCEx.c.

35{
36 WNDCLASSA cls;
37
38 cls.style = style;
39 cls.lpfnWndProc = pfnWndProc;
40 cls.cbClsExtra = 0;
41 cls.cbWndExtra = 0;
43 cls.hIcon = 0;
46 cls.lpszMenuName = NULL;
47 cls.lpszClassName = pszClassName;
48
49 return RegisterClassA(&cls);
50}
Arabic default style
Definition: afstyles.h:94
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
HBRUSH hbrBackground
Definition: winuser.h:3170
HICON hIcon
Definition: winuser.h:3168
HINSTANCE hInstance
Definition: winuser.h:3167
HCURSOR hCursor
Definition: winuser.h:3169
int cbWndExtra
Definition: winuser.h:3166
UINT style
Definition: winuser.h:3163
LPCSTR lpszMenuName
Definition: winuser.h:3171
LPCSTR lpszClassName
Definition: winuser.h:3172
WNDPROC lpfnWndProc
Definition: winuser.h:3164
int cbClsExtra
Definition: winuser.h:3165
HGDIOBJ WINAPI GetStockObject(_In_ int)
#define WHITE_BRUSH
Definition: wingdi.h:902
#define IDC_ARROW
Definition: winuser.h:687
ATOM WINAPI RegisterClassA(_In_ CONST WNDCLASSA *)
HCURSOR WINAPI LoadCursorA(_In_opt_ HINSTANCE, _In_ LPCSTR)
Definition: cursoricon.c:2121

Referenced by Test_GetDCEx_Cached(), Test_GetDCEx_CS_CLASSDC(), Test_GetDCEx_CS_Mixed(), Test_GetDCEx_CS_OWNDC(), and Test_GetDCEx_CS_SwitchedStyle().

◆ START_TEST()

START_TEST ( GetDCEx  )

Definition at line 473 of file GetDCEx.c.

474{
481}
static void Test_GetDCEx_Cached()
Definition: GetDCEx.c:73
static void Test_GetDCEx_CS_Mixed()
Definition: GetDCEx.c:256
static void Test_GetDCEx_CS_OWNDC()
Definition: GetDCEx.c:143
static void Test_GetDCEx_CS_SwitchedStyle()
Definition: GetDCEx.c:414
void Test_GetDCEx_Params()
Definition: GetDCEx.c:12
static void Test_GetDCEx_CS_CLASSDC()
Definition: GetDCEx.c:204

◆ Test_GetDCEx_Cached()

static void Test_GetDCEx_Cached ( )
static

Definition at line 73 of file GetDCEx.c.

74{
75 static const PSTR pszClassName = "TestClass_Cached";
76 ATOM atomClass;
77 HWND hwnd;
78 HDC hdc1, hdc2;
79 HRGN hrgn;
80
81 atomClass = RegisterClassHelper(pszClassName, 0, WndProc);
82 ok(atomClass != 0, "Failed to register class\n");
83
84 hwnd = CreateWindowHelper(pszClassName, "Test Window1");
85 ok(hwnd != NULL, "Failed to create hwnd\n");
86
87 hdc1 = GetDCEx(hwnd, 0, 0);
88 ok(hdc1 == NULL, "GetDCEx should fail\n");
89 hrgn = CreateRectRgn(0, 0, 100, 100);
90 hdc1 = GetDCEx(hwnd, hrgn, 0);
91 ok(hdc1 == NULL, "GetDCEx should fail\n");
92
94 ok(hdc1 == NULL, "GetDCEx should fail\n");
96 ok(hdc1 == NULL, "GetDCEx should fail\n");
97
99 ok(hdc1 == NULL, "GetDCEx should fail\n");
100
102 ok(hdc1 != NULL, "GetDCEx failed\n");
104
106 ok(hdc1 != NULL, "GetDCEx failed\n");
108
109 hdc1 = GetDCEx(hwnd, 0, DCX_CACHE);
110 ok(hdc1 != NULL, "GetDCEx failed\n");
112
113 hrgn = CreateRectRgn(0, 0, 100, 100);
115 ok(hdc2 != NULL, "GetDCEx failed\n");
117 ok(hdc2 == hdc1, "Expected the same DC\n");
118
119 hdc1 = GetDCEx(hwnd, 0, DCX_CACHE);
121 ok(hdc1 != NULL, "GetDCEx failed\n");
122 ok(hdc2 != hdc1, "Expected a different DC\n");
125
126 hdc1 = GetDCEx(NULL, NULL, 0);
127 ok(hdc1 != NULL, "GetDCEx failed\n");
128 hdc2 = GetDCEx(NULL, NULL, 0);
129 ok(hdc2 != NULL, "GetDCEx failed\n");
130 ok(hdc2 != hdc1, "Expected a different DC\n");
133
134 ok(CombineRgn(hrgn, hrgn, hrgn, RGN_OR) == SIMPLEREGION, "region is not valid");
135
137 ok(UnregisterClass(pszClassName, GetModuleHandleA(0)) == TRUE,
138 "UnregisterClass failed");
139}
static LRESULT CALLBACK WndProc(_In_ HWND hwnd, _In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam)
Definition: GetDCEx.c:20
static HWND CreateWindowHelper(PSZ pszClassName, PSZ pszTitle)
Definition: GetDCEx.c:54
static ATOM RegisterClassHelper(PSTR pszClassName, UINT style, WNDPROC pfnWndProc)
Definition: GetDCEx.c:31
static HRGN hrgn
HDC hdc1
Definition: SelectObject.c:10
HDC hdc2
Definition: SelectObject.c:10
#define ok(value,...)
Definition: atltest.h:57
WORD ATOM
Definition: dimm.idl:113
#define TRUE
Definition: types.h:120
static HDC
Definition: imagelist.c:92
char * PSTR
Definition: typedefs.h:51
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
HRGN WINAPI CreateRectRgn(_In_ int, _In_ int, _In_ int, _In_ int)
int WINAPI CombineRgn(_In_opt_ HRGN hrgnDest, _In_opt_ HRGN hrgnSrc1, _In_opt_ HRGN hrgnSrc2, _In_ int fnCombineMode)
#define SIMPLEREGION
Definition: wingdi.h:362
#define RGN_OR
Definition: wingdi.h:359
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define DCX_CACHE
Definition: winuser.h:2114
#define DCX_WINDOW
Definition: winuser.h:2113
#define UnregisterClass
Definition: winuser.h:5861
HDC WINAPI GetDCEx(_In_opt_ HWND, _In_opt_ HRGN, _In_ DWORD)
#define DCX_INTERSECTRGN
Definition: winuser.h:2122
#define DCX_PARENTCLIP
Definition: winuser.h:2115
BOOL WINAPI DestroyWindow(_In_ HWND)

Referenced by START_TEST().

◆ Test_GetDCEx_CS_CLASSDC()

static void Test_GetDCEx_CS_CLASSDC ( )
static

Definition at line 204 of file GetDCEx.c.

205{
206 static const PSTR pszClassName = "TestClass_CS_CLASSDC";
207 ATOM atomClass;
208 HWND hwnd1, hwnd2;
209 HDC hdc1, hdc2;
210 //HRGN hrgn;
211
212 atomClass = RegisterClassHelper(pszClassName, CS_CLASSDC, WndProc);
213 ok(atomClass != 0, "Failed to register class\n");
214
215 hwnd1 = CreateWindowHelper(pszClassName, "Test Window1");
216 ok(hwnd1 != NULL, "Failed to create hwnd1\n");
217
218 /* Looks legit, but this is not the DC you are looking for!
219 In fact this is NOT the class dc, but an own DC, doh!
220 When the first Window is created, the DC for that Window is both it's own
221 AND the class DC. But we only get the class DC, when using DCX_USESTYLE */
222 hdc1 = GetDCEx(hwnd1, NULL, 0);
223 ok(hdc1 != NULL, "GetDCEx failed\n");
224 hdc2 = GetDCEx(hwnd1, NULL, 0);
225 ok(hdc2 == hdc1, "Expected the same DC, got %p\n", hdc2);
226 ok(ReleaseDC(hwnd1, hdc1) == TRUE, "ReleaseDC failed\n");
227 ok(ReleaseDC(hwnd1, hdc2) == TRUE, "ReleaseDC failed\n");
228
229 /* Now with DCX_USESTYLE */
230 hdc2 = GetDCEx(hwnd1, NULL, DCX_USESTYLE);
231 ok(hdc2 == hdc1, "Expected the same DC, got %p\n", hdc2);
232 ok(ReleaseDC(hwnd1, hdc2) == TRUE, "ReleaseDC failed\n");
233
234 hwnd2 = CreateWindowHelper(pszClassName, "Test Window2");
235 ok(hwnd2 != NULL, "Failed to create hwnd2\n");
236
237 /* Yeah, this doesn't work anymore. Once the */
238 hdc2 = GetDCEx(hwnd2, NULL, 0);
239 ok(hdc2 == NULL, "Expected failure\n");
240
241 /* Now with DCX_USESTYLE ... */
242 hdc2 = GetDCEx(hwnd2, NULL, DCX_USESTYLE);
243 ok(hdc2 == hdc1, "Expected the same DC, got %p\n", hdc2);
244 ok(ReleaseDC(hwnd2, hdc2) == TRUE, "ReleaseDC failed\n");
245
246 SendMessage(hwnd2, WM_USER, 0, 0);
247
248 DestroyWindow(hwnd1);
249 DestroyWindow(hwnd2);
250 ok(UnregisterClass(pszClassName, GetModuleHandleA(0)) == TRUE,
251 "UnregisterClass failed");
252}
#define DCX_USESTYLE
Definition: GetDCEx.c:10
#define SendMessage
Definition: winuser.h:5843
#define WM_USER
Definition: winuser.h:1895
#define CS_CLASSDC
Definition: winuser.h:650

Referenced by START_TEST().

◆ Test_GetDCEx_CS_Mixed()

static void Test_GetDCEx_CS_Mixed ( )
static

Definition at line 256 of file GetDCEx.c.

257{
258 static const PSTR pszClassName = "TestClass_CS_Mixed";
259 ATOM atomClass;
260 HWND hwnd1,hwnd2, hwnd3;
261 HDC hdc1, hdc2, hdc3;
262
263 /* Register a class with CS_OWNDC *and* CS_CLASSDC */
264 atomClass = RegisterClassHelper(pszClassName, CS_OWNDC | CS_CLASSDC, WndProc);
265 ok(atomClass != 0, "Failed to register class\n");
266
267 /* Create the first window, this should create a single own and class DC */
268 hwnd1 = CreateWindowHelper(pszClassName, "Test Window1");
269 ok(hwnd1 != NULL, "Failed to create hwnd1\n");
270
271 /* Verify that we have the right style */
273 "class style not set\n");
274
275 /* This is now the class DC and the first windows own DC */
276 hdc1 = GetDCEx(hwnd1, NULL, 0);
277 ok(hdc1 != NULL, "GetDCEx failed\n");
278 ok(ReleaseDC(hwnd1, hdc1) == TRUE, "ReleaseDC failed\n");
279
280 /* This should get us the own/class DC again */
281 hdc2 = GetDCEx(hwnd1, NULL, 0);
282 ok(hdc2 == hdc1, "Expected the own/class DC, got %p\n", hdc2);
283 ok(ReleaseDC(hwnd1, hdc2) == TRUE, "ReleaseDC failed\n");
284
285 /* This should get us the class DC, but it's the same */
286 hdc2 = GetDCEx(hwnd1, NULL, DCX_USESTYLE);
287 ok(hdc2 == hdc1, "Expected the own/class DC, got %p\n", hdc2);
288 ok(ReleaseDC(hwnd1, hdc2) == TRUE, "ReleaseDC failed\n");
289
290 /* Create a second window */
291 hwnd2 = CreateWindowHelper(pszClassName, "Test Window1");
292 ok(hwnd1 != NULL, "Failed to create hwnd1\n");
293
294 /* This should get us the own DC of the new window */
295 hdc2 = GetDCEx(hwnd2, NULL, 0);
296 ok(hdc2 != NULL, "GetDCEx failed\n");
297 ok(hdc2 != hdc1, "Expected different DC\n");
298 ok(ReleaseDC(hwnd2, hdc2) == TRUE, "ReleaseDC failed\n");
299
300 /* This gets us the own DC again, CS_OWNDC has priority! */
301 hdc3 = GetDCEx(hwnd2, NULL, DCX_USESTYLE);
302 ok(hdc3 == hdc2, "Expected the own DC, got %p\n", hdc3);
303 ok(ReleaseDC(hwnd2, hdc3) == TRUE, "ReleaseDC failed\n");
304
305 /* Disable CS_OWNDC */
306 ok(SetClassLongPtrA(hwnd1, GCL_STYLE, CS_CLASSDC) == (CS_OWNDC | CS_CLASSDC), "unexpected style\n");
307 ok(GetClassLongPtrA(hwnd1, GCL_STYLE) == CS_CLASSDC, "class style not set\n");
308
309 /* Since the window already has an own DC, we get it again! */
310 hdc3 = GetDCEx(hwnd2, NULL, DCX_USESTYLE);
311 ok(hdc3 == hdc2, "Expected the own DC, got %p\n", hdc3);
312 ok(ReleaseDC(hwnd2, hdc3) == TRUE, "ReleaseDC failed\n");
313
314 /* Disable CS_CLASSDC, too */
315 ok(SetClassLongPtrA(hwnd1, GCL_STYLE, 0) == CS_CLASSDC, "unexpected style\n");
316 ok(GetClassLongPtrA(hwnd1, GCL_STYLE) == 0, "class style not set\n");
317
318 /* With DCX_USESTYLE we only get a cached DC */
319 hdc3 = GetDCEx(hwnd2, NULL, DCX_USESTYLE);
320 ok(hdc3 != NULL, "GetDCEx failed\n");
321 ok(hdc3 != hdc1, "Expected different DC, got class DC\n");
322 ok(hdc3 != hdc2, "Expected different DC, got own DC\n");
323 ok(ReleaseDC(hwnd2, hdc3) == TRUE, "ReleaseDC failed\n");
324
325 /* Without DCX_USESTYLE we get the own DC */
326 hdc3 = GetDCEx(hwnd2, NULL, 0);
327 ok(hdc3 != NULL, "GetDCEx failed\n");
328 ok(hdc3 != hdc1, "Expected different DC, got class DC\n");
329 ok(hdc3 == hdc2, "Expected the own DC, got %p\n", hdc3);
330 ok(ReleaseDC(hwnd2, hdc3) == TRUE, "ReleaseDC failed\n");
331
332 /* Set only CS_OWNDC */
333 ok(SetClassLongPtrA(hwnd1, GCL_STYLE, CS_OWNDC) == 0, "unexpected style\n");
334 ok(GetClassLongPtrA(hwnd1, GCL_STYLE) == CS_OWNDC, "class style not set\n");
335
336 hwnd3 = CreateWindowHelper(pszClassName, "Test Window1");
337 ok(hwnd3 != NULL, "Failed to create hwnd1\n");
338
339 /* This should get a new own DC */
340 hdc2 = GetDCEx(hwnd3, NULL, 0);
341 ok(hdc2 != hdc1, "Expected different DC\n");
342 ok(ReleaseDC(hwnd3, hdc2) == TRUE, "ReleaseDC failed\n");
343
344 /* Re-enable CS_CLASSDC */
345 ok(SetClassLongPtrA(hwnd1, GCL_STYLE, (CS_OWNDC | CS_CLASSDC)) == CS_OWNDC, "unexpected style\n");
346 ok(GetClassLongPtrA(hwnd1, GCL_STYLE) == (CS_OWNDC | CS_CLASSDC), "class style not set\n");
347
348 /* This should get us the own DC */
349 hdc3 = GetDCEx(hwnd3, NULL, 0);
350 ok(hdc3 == hdc2, "Expected the same DC, got %p\n", hdc3);
351 ok(ReleaseDC(hwnd3, hdc3) == TRUE, "ReleaseDC failed\n");
352
353 /* This should still get us the new own DC */
354 hdc3 = GetDCEx(hwnd3, NULL, DCX_USESTYLE);
355 ok(hdc3 == hdc2, "Expected the same DC, got %p\n", hdc3);
356 ok(ReleaseDC(hwnd3, hdc3) == TRUE, "ReleaseDC failed\n");
357
358 /* Disable CS_OWNDC */
359 ok(SetClassLongPtrA(hwnd1, GCL_STYLE, CS_CLASSDC) == (CS_OWNDC | CS_CLASSDC), "unexpected style\n");
360 ok(GetClassLongPtrA(hwnd1, GCL_STYLE) == CS_CLASSDC, "class style not set\n");
361
362 /* This should get us the own DC */
363 hdc3 = GetDCEx(hwnd3, NULL, 0);
364 ok(hdc3 == hdc2, "Expected the same DC, got %p\n", hdc3);
365 ok(ReleaseDC(hwnd3, hdc3) == TRUE, "ReleaseDC failed\n");
366
367 /* This should still get us the new own DC */
368 hdc3 = GetDCEx(hwnd3, NULL, DCX_USESTYLE);
369 ok(hdc3 == hdc2, "Expected the same DC, got %p\n", hdc3);
370 ok(ReleaseDC(hwnd3, hdc3) == TRUE, "ReleaseDC failed\n");
371
372 /* cleanup for a second run */
373 DestroyWindow(hwnd1);
374 DestroyWindow(hwnd2);
375 DestroyWindow(hwnd3);
376 ok(UnregisterClass(pszClassName, GetModuleHandleA(0)) == TRUE,
377 "UnregisterClass failed\n");
378
379 /* Create class again with CS_OWNDC */
380 atomClass = RegisterClassHelper(pszClassName, CS_OWNDC, WndProc);
381 ok(atomClass != 0, "Failed to register class\n");
382
383 hwnd1 = CreateWindowHelper(pszClassName, "Test Window1");
384 ok(hwnd1 != NULL, "Failed to create hwnd1\n");
385
386 /* This is the windows own DC, the class does not have a class DC yet */
387 hdc1 = GetDCEx(hwnd1, NULL, 0);
388 ok(hdc1 != NULL, "GetDCEx failed\n");
389 ok(ReleaseDC(hwnd1, hdc1) == TRUE, "ReleaseDC failed\n");
390
391 /* Enable only CS_CLASSDC */
392 ok(SetClassLongPtrA(hwnd1, GCL_STYLE, CS_CLASSDC) == CS_OWNDC, "unexpected style\n");
393 ok(GetClassLongPtrA(hwnd1, GCL_STYLE) == CS_CLASSDC, "class style not set\n");
394
395 /* Create a second window. Now we should create a class DC! */
396 hwnd2 = CreateWindowHelper(pszClassName, "Test Window2");
397 ok(hwnd2 != NULL, "Failed to create hwnd1\n");
398
399 /* We expect a new DCE (the class DCE) */
400 hdc2 = GetDCEx(hwnd2, NULL, DCX_USESTYLE);
401 ok(hdc2 != NULL, "GetDCEx failed\n");
402 ok(hdc2 != hdc1, "Expected different DCs\n");
403 ok(ReleaseDC(hwnd2, hdc2) == TRUE, "ReleaseDC failed\n");
404
405 /* cleanup */
406 DestroyWindow(hwnd1);
407 DestroyWindow(hwnd2);
408 ok(UnregisterClass(pszClassName, GetModuleHandleA(0)) == TRUE,
409 "UnregisterClass failed\n");
410}
#define SetClassLongPtrA
Definition: winuser.h:5264
#define CS_OWNDC
Definition: winuser.h:655
#define GetClassLongPtrA
Definition: winuser.h:4563
#define GCL_STYLE
Definition: winuser.h:670

Referenced by START_TEST().

◆ Test_GetDCEx_CS_OWNDC()

static void Test_GetDCEx_CS_OWNDC ( )
static

Definition at line 143 of file GetDCEx.c.

144{
145 static const PSTR pszClassName = "TestClass_CS_OWNDC";
146 ATOM atomClass;
147 HWND hwnd;
148 HDC hdc1, hdc2;
149 //HRGN hrgn;
150
151 atomClass = RegisterClassHelper(pszClassName, CS_OWNDC, WndProc);
152 ok(atomClass != 0, "Failed to register class\n");
153
154 hwnd = CreateWindowHelper(pszClassName, "Test Window1");
155 ok(hwnd != NULL, "Failed to create hwnd\n");
156
157 hdc1 = GetDCEx(hwnd, NULL, 0);
158 ok(hdc1 != NULL, "GetDCEx failed\n");
159 hdc2 = GetDCEx(hwnd, NULL, 0);
160 ok(hdc2 != NULL, "GetDCEx failed\n");
161 ok(hdc2 == hdc1, "Expected the same DC\n");
162 ok(ReleaseDC(hwnd, hdc1) == TRUE, "ReleaseDC failed\n");
163 ok(ReleaseDC(hwnd, hdc2) == TRUE, "ReleaseDC failed\n");
164
165 hdc2 = GetDCEx(hwnd, NULL, 0);
166 ok(hdc2 == hdc1, "Expected the same DC\n");
167 ok(ReleaseDC(hwnd, hdc2) == TRUE, "ReleaseDC failed\n");
168
170 ok(hdc2 != hdc1, "Expected a different DC\n");
171 ok(ReleaseDC(hwnd, hdc2) == TRUE, "ReleaseDC failed\n");
172
174 ok(hdc2 == hdc1, "Expected the same DC\n");
175 ok(ReleaseDC(hwnd, hdc2) == TRUE, "ReleaseDC failed\n");
176
177 /* Try after resetting CS_OWNDC in the class */
178 ok(SetClassLongPtrA(hwnd, GCL_STYLE, 0) == CS_OWNDC, "class style wrong\n");
179 hdc2 = GetDCEx(hwnd, NULL, 0);
180 ok(hdc2 == hdc1, "Expected the same DC, got %p\n", hdc2);
181 ok(ReleaseDC(hwnd, hdc2) == TRUE, "ReleaseDC failed\n");
182
183 /* Try after setting CS_CLASSDC in the class */
184 ok(SetClassLongPtrA(hwnd, GCL_STYLE, CS_CLASSDC) == 0, "class style not set\n");
185 hdc2 = GetDCEx(hwnd, NULL, 0);
186 ok(hdc2 == hdc1, "Expected the same DC, got %p\n", hdc2);
187 ok(ReleaseDC(hwnd, hdc2) == TRUE, "ReleaseDC failed\n");
188
189 /* CS_OWNDC and CS_CLASSDC? Is that even legal? */
190 ok(SetClassLongPtrA(hwnd, GCL_STYLE, (CS_OWNDC | CS_CLASSDC)) == CS_CLASSDC, "class style not set\n");
191 hdc2 = GetDCEx(hwnd, NULL, 0);
192 ok(hdc2 == hdc1, "Expected the same DC, got %p\n", hdc2);
193 ok(ReleaseDC(hwnd, hdc2) == TRUE, "ReleaseDC failed\n");
194
196
198 ok(UnregisterClass(pszClassName, GetModuleHandleA(0)) == TRUE,
199 "UnregisterClass failed");
200}

Referenced by START_TEST().

◆ Test_GetDCEx_CS_SwitchedStyle()

static void Test_GetDCEx_CS_SwitchedStyle ( )
static

Definition at line 414 of file GetDCEx.c.

415{
416 static const PSTR pszClassName = "TestClass_CS_SwitchedStyle";
417 ATOM atomClass;
418 HWND hwnd1, hwnd2;
419 HDC hdc1, hdc2, hdcClass;
420
421 /* Create a class with CS_CLASSDC */
422 atomClass = RegisterClassHelper(pszClassName, CS_CLASSDC, WndProc);
423 ok(atomClass != 0, "Failed to register class\n");
424
425 /* Create the 2 windows */
426 hwnd1 = CreateWindowHelper(pszClassName, "Test Window1");
427 ok(hwnd1 != NULL, "Failed to create hwnd1\n");
428 hwnd2 = CreateWindowHelper(pszClassName, "Test Window2");
429 ok(hwnd2 != NULL, "Failed to create hwnd2\n");
430
431 /* Get the class DC from the Windows */
432 hdc1 = GetDCEx(hwnd1, NULL, DCX_USESTYLE);
433 hdc2 = GetDCEx(hwnd2, NULL, DCX_USESTYLE);
434 hdcClass = hdc1;
435 ok(hdc1 == hdc2, "Expected same DC\n");
436 ok(ReleaseDC(hwnd2, hdc2) == TRUE, "ReleaseDC failed\n");
437
438 /* Switch the class to CS_OWNDC */
439 ok(SetClassLongPtrA(hwnd1, GCL_STYLE, CS_OWNDC) == CS_CLASSDC, "unexpected style\n");
440 ok(GetClassLongPtrA(hwnd1, GCL_STYLE) == CS_OWNDC, "class style not set\n");
441
442 /* Release the DC and try to get another one, this should fail now */
443 ok(ReleaseDC(hwnd1, hdc1) == TRUE, "ReleaseDC failed\n");
444 hdc1 = GetDCEx(hwnd1, NULL, DCX_USESTYLE);
445 ok(hdc1 == NULL, "GetDCEx should fail\n");
446
447 /* Destroy the 1st window, this should move it's own DC to the cache,
448 but not the class DC, but they are the same, so... */
449 DestroyWindow(hwnd1);
450
451 /* Create another window, this time it should have it's own DC */
452 hwnd1 = CreateWindowHelper(pszClassName, "Test Window1");
453 ok(hwnd1 != NULL, "Failed to create hwnd1\n");
454 hdc1 = GetDCEx(hwnd1, NULL, DCX_USESTYLE);
455 ok(hdc1 != NULL, "GetDXEx failed\n");
456 ok(hdc1 != hdc2, "Should get different DC\n");
457
458 /* Switch the class back to CS_CLASSDC */
459 ok(SetClassLongPtrA(hwnd2, GCL_STYLE, CS_CLASSDC) == CS_OWNDC, "unexpected style\n");
460 ok(GetClassLongPtrA(hwnd2, GCL_STYLE) == CS_CLASSDC, "class style not set\n");
461
462 /* Get the 2nd window's DC, this should still be the class DC */
463 hdc2 = GetDCEx(hwnd2, NULL, DCX_USESTYLE);
464 ok(hdc2 != hdc1, "Expected different DC\n");
465 ok(hdc2 == hdcClass, "Expected class DC\n");
466
467 DestroyWindow(hwnd1);
468 DestroyWindow(hwnd2);
469 ok(UnregisterClass(pszClassName, GetModuleHandleA(0)) == TRUE,
470 "UnregisterClass failed\n");
471}

Referenced by START_TEST().

◆ Test_GetDCEx_Params()

void Test_GetDCEx_Params ( )

Definition at line 12 of file GetDCEx.c.

13{
14
15}

Referenced by START_TEST().

◆ WndProc()

static LRESULT CALLBACK WndProc ( _In_ HWND  hwnd,
_In_ UINT  uMsg,
_In_ WPARAM  wParam,
_In_ LPARAM  lParam 
)
static