ReactOS  0.4.13-dev-100-gc8611ae
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 CreateWindowA(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4184
#define CW_USEDEFAULT
Definition: winuser.h:225
smooth NULL
Definition: ftsmooth.c:416
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637

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;
42  cls.hInstance = GetModuleHandleA(0);
43  cls.hIcon = 0;
44  cls.hCursor = LoadCursorA(0, IDC_ARROW);
46  cls.lpszMenuName = NULL;
47  cls.lpszClassName = pszClassName;
48 
49  return RegisterClassA(&cls);
50 }
HGDIOBJ WINAPI GetStockObject(_In_ int)
int cbClsExtra
Definition: winuser.h:3118
LPCSTR lpszMenuName
Definition: winuser.h:3124
#define WHITE_BRUSH
Definition: wingdi.h:901
HBRUSH hbrBackground
Definition: winuser.h:3123
int cbWndExtra
Definition: winuser.h:3119
HCURSOR hCursor
Definition: winuser.h:3122
smooth NULL
Definition: ftsmooth.c:416
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:819
LPCSTR lpszClassName
Definition: winuser.h:3125
HCURSOR WINAPI LoadCursorA(_In_opt_ HINSTANCE, _In_ LPCSTR)
Definition: cursoricon.c:2059
UINT style
Definition: winuser.h:3116
HINSTANCE hInstance
Definition: winuser.h:3120
WNDPROC lpfnWndProc
Definition: winuser.h:3117
#define IDC_ARROW
Definition: winuser.h:682
Arabic default style
Definition: afstyles.h:93
ATOM WINAPI RegisterClassA(_In_ CONST WNDCLASSA *)
HICON hIcon
Definition: winuser.h:3121

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 438 of file GetDCEx.c.

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

◆ 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 
93  hdc1 = GetDCEx(hwnd, 0, DCX_WINDOW);
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");
103  ReleaseDC(hwnd, hdc1);
104 
106  ok(hdc1 != NULL, "GetDCEx failed\n");
107  ReleaseDC(hwnd, hdc1);
108 
109  hdc1 = GetDCEx(hwnd, 0, DCX_CACHE);
110  ok(hdc1 != NULL, "GetDCEx failed\n");
111  ReleaseDC(hwnd, hdc1);
112 
113  hrgn = CreateRectRgn(0, 0, 100, 100);
115  ok(hdc2 != NULL, "GetDCEx failed\n");
116  ReleaseDC(hwnd, hdc2);
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");
123  ReleaseDC(hwnd, hdc1);
124  ReleaseDC(hwnd, hdc2);
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");
131  ReleaseDC(hwnd, hdc1);
132  ReleaseDC(hwnd, hdc2);
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 }
int WINAPI CombineRgn(_In_opt_ HRGN hrgnDest, _In_opt_ HRGN hrgnSrc1, _In_opt_ HRGN hrgnSrc2, _In_ int fnCombineMode)
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
HDC WINAPI GetDCEx(_In_opt_ HWND, _In_opt_ HRGN, _In_ DWORD)
#define TRUE
Definition: types.h:120
WORD ATOM
Definition: dimm.idl:113
static HDC
Definition: imagelist.c:92
static HWND CreateWindowHelper(PSZ pszClassName, PSZ pszTitle)
Definition: GetDCEx.c:54
BOOL WINAPI DestroyWindow(_In_ HWND)
#define DCX_INTERSECTRGN
Definition: winuser.h:2083
#define DCX_WINDOW
Definition: winuser.h:2074
static LRESULT CALLBACK WndProc(_In_ HWND hwnd, _In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam)
Definition: GetDCEx.c:20
HDC hdc2
Definition: SelectObject.c:10
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define ok(value,...)
smooth NULL
Definition: ftsmooth.c:416
#define RGN_OR
Definition: wingdi.h:358
HDC hdc1
Definition: SelectObject.c:10
HRGN WINAPI CreateRectRgn(_In_ int, _In_ int, _In_ int, _In_ int)
static ATOM RegisterClassHelper(PSTR pszClassName, UINT style, WNDPROC pfnWndProc)
Definition: GetDCEx.c:31
static HRGN hrgn
Definition: win.c:55
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:819
#define SIMPLEREGION
Definition: wingdi.h:361
#define DCX_CACHE
Definition: winuser.h:2075
#define DCX_PARENTCLIP
Definition: winuser.h:2076
signed char * PSTR
Definition: retypes.h:7
#define UnregisterClass
Definition: winuser.h:5727

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 }
HDC WINAPI GetDCEx(_In_opt_ HWND, _In_opt_ HRGN, _In_ DWORD)
#define TRUE
Definition: types.h:120
WORD ATOM
Definition: dimm.idl:113
static HDC
Definition: imagelist.c:92
static HWND CreateWindowHelper(PSZ pszClassName, PSZ pszTitle)
Definition: GetDCEx.c:54
#define DCX_USESTYLE
Definition: GetDCEx.c:10
BOOL WINAPI DestroyWindow(_In_ HWND)
static LRESULT CALLBACK WndProc(_In_ HWND hwnd, _In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam)
Definition: GetDCEx.c:20
HDC hdc2
Definition: SelectObject.c:10
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define ok(value,...)
smooth NULL
Definition: ftsmooth.c:416
HDC hdc1
Definition: SelectObject.c:10
static ATOM RegisterClassHelper(PSTR pszClassName, UINT style, WNDPROC pfnWndProc)
Definition: GetDCEx.c:31
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:819
#define WM_USER
Definition: winuser.h:1856
#define CS_CLASSDC
Definition: winuser.h:645
signed char * PSTR
Definition: retypes.h:7
#define SendMessage
Definition: winuser.h:5709
#define UnregisterClass
Definition: winuser.h:5727

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 }
HDC WINAPI GetDCEx(_In_opt_ HWND, _In_opt_ HRGN, _In_ DWORD)
#define TRUE
Definition: types.h:120
WORD ATOM
Definition: dimm.idl:113
static HDC
Definition: imagelist.c:92
static HWND CreateWindowHelper(PSZ pszClassName, PSZ pszTitle)
Definition: GetDCEx.c:54
#define DCX_USESTYLE
Definition: GetDCEx.c:10
#define CS_OWNDC
Definition: winuser.h:650
BOOL WINAPI DestroyWindow(_In_ HWND)
static LRESULT CALLBACK WndProc(_In_ HWND hwnd, _In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam)
Definition: GetDCEx.c:20
HDC hdc2
Definition: SelectObject.c:10
#define GCL_STYLE
Definition: winuser.h:665
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define ok(value,...)
smooth NULL
Definition: ftsmooth.c:416
HDC hdc1
Definition: SelectObject.c:10
static ATOM RegisterClassHelper(PSTR pszClassName, UINT style, WNDPROC pfnWndProc)
Definition: GetDCEx.c:31
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:819
#define SetClassLongPtrA
Definition: winuser.h:5133
#define CS_CLASSDC
Definition: winuser.h:645
signed char * PSTR
Definition: retypes.h:7
#define GetClassLongPtrA
Definition: winuser.h:4432
#define UnregisterClass
Definition: winuser.h:5727

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 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
HDC WINAPI GetDCEx(_In_opt_ HWND, _In_opt_ HRGN, _In_ DWORD)
#define TRUE
Definition: types.h:120
WORD ATOM
Definition: dimm.idl:113
static HDC
Definition: imagelist.c:92
static HWND CreateWindowHelper(PSZ pszClassName, PSZ pszTitle)
Definition: GetDCEx.c:54
#define CS_OWNDC
Definition: winuser.h:650
BOOL WINAPI DestroyWindow(_In_ HWND)
#define DCX_WINDOW
Definition: winuser.h:2074
static LRESULT CALLBACK WndProc(_In_ HWND hwnd, _In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam)
Definition: GetDCEx.c:20
HDC hdc2
Definition: SelectObject.c:10
#define GCL_STYLE
Definition: winuser.h:665
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define ok(value,...)
smooth NULL
Definition: ftsmooth.c:416
HDC hdc1
Definition: SelectObject.c:10
static ATOM RegisterClassHelper(PSTR pszClassName, UINT style, WNDPROC pfnWndProc)
Definition: GetDCEx.c:31
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:819
#define SetClassLongPtrA
Definition: winuser.h:5133
#define CS_CLASSDC
Definition: winuser.h:645
#define DCX_CACHE
Definition: winuser.h:2075
signed char * PSTR
Definition: retypes.h:7
#define UnregisterClass
Definition: winuser.h:5727

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 
420  atomClass = RegisterClassHelper(pszClassName, CS_OWNDC, WndProc);
421  ok(atomClass != 0, "Failed to register class\n");
422 
423  hwnd1 = CreateWindowHelper(pszClassName, "Test Window1");
424  ok(hwnd1 != NULL, "Failed to create hwnd1\n");
425 
426  ok(SetClassLongPtrA(hwnd1, GCL_STYLE, CS_CLASSDC) == CS_OWNDC, "unexpected style\n");
427  ok(GetClassLongPtrA(hwnd1, GCL_STYLE) == CS_CLASSDC, "class style not set\n");
428 
429  hwnd2 = CreateWindowHelper(pszClassName, "Test Window2");
430  ok(hwnd2 != NULL, "Failed to create hwnd2\n");
431 
432  DestroyWindow(hwnd1);
433  DestroyWindow(hwnd2);
434  ok(UnregisterClass(pszClassName, GetModuleHandleA(0)) == TRUE,
435  "UnregisterClass failed\n");
436 }
#define TRUE
Definition: types.h:120
WORD ATOM
Definition: dimm.idl:113
static HWND CreateWindowHelper(PSZ pszClassName, PSZ pszTitle)
Definition: GetDCEx.c:54
#define CS_OWNDC
Definition: winuser.h:650
BOOL WINAPI DestroyWindow(_In_ HWND)
static LRESULT CALLBACK WndProc(_In_ HWND hwnd, _In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam)
Definition: GetDCEx.c:20
#define GCL_STYLE
Definition: winuser.h:665
#define ok(value,...)
smooth NULL
Definition: ftsmooth.c:416
static ATOM RegisterClassHelper(PSTR pszClassName, UINT style, WNDPROC pfnWndProc)
Definition: GetDCEx.c:31
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:819
#define SetClassLongPtrA
Definition: winuser.h:5133
#define CS_CLASSDC
Definition: winuser.h:645
signed char * PSTR
Definition: retypes.h:7
#define GetClassLongPtrA
Definition: winuser.h:4432
#define UnregisterClass
Definition: winuser.h:5727

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

Definition at line 20 of file GetDCEx.c.

25 {
26  return TRUE;
27 }
#define TRUE
Definition: types.h:120

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