2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for DrawThemeParentBackground
5 * PROGRAMMERS: Giannis Adamopoulos
12 #include <undocuser.h>
14 #include <user32testhelpers.h>
18 static int get_iwnd(HWND hWnd
)
20 if(hWnd
== hWnd1
) return 1;
21 else if(hWnd
== hWnd2
) return 2;
25 static LRESULT CALLBACK
TestProc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
27 int iwnd
= get_iwnd(hwnd
);
29 if(message
> WM_USER
|| !iwnd
|| message
== WM_GETICON
)
30 return DefWindowProc(hwnd
, message
, wParam
, lParam
);
32 RECORD_MESSAGE(iwnd
, message
, SENT
, 0,0);
33 return DefWindowProc(hwnd
, message
, wParam
, lParam
);
36 static void FlushMessages()
40 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
))
42 int iwnd
= get_iwnd(msg
.hwnd
);
43 if(iwnd
&& msg
.message
<= WM_USER
)
44 RECORD_MESSAGE(iwnd
, msg
.message
, POST
,0,0);
45 DispatchMessageW( &msg
);
49 MSG_ENTRY draw_parent_chain
[]={{1, WM_ERASEBKGND
},
58 RegisterSimpleClass(TestProc
, L
"testClass");
60 hWnd1
= CreateWindowW(L
"testClass", L
"Test parent", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
, 100, 100, 200, 200, 0, NULL
, NULL
, NULL
);
61 ok (hWnd1
!= NULL
, "Expected CreateWindowW to succeed\n");
63 hWnd2
= CreateWindowW(L
"testClass", L
"test window", WS_CHILD
| WS_VISIBLE
, 0, 0, 100, 100, hWnd1
, NULL
, NULL
, NULL
);
64 ok (hWnd2
!= NULL
, "Expected CreateWindowW to succeed\n");
71 DrawThemeParentBackground(hWnd2
, hdc
, NULL
);
73 COMPARE_CACHE(draw_parent_chain
);
75 DrawThemeParentBackground(hWnd1
, hdc
, NULL
);
77 COMPARE_CACHE(empty_chain
);
79 ShowWindow(hWnd1
, SW_SHOW
);
81 ShowWindow(hWnd2
, SW_SHOW
);
87 DrawThemeParentBackground(hWnd2
, NULL
, NULL
);
89 COMPARE_CACHE(empty_chain
);
91 DrawThemeParentBackground(hWnd1
, NULL
, NULL
);
93 COMPARE_CACHE(empty_chain
);
95 DrawThemeParentBackground(hWnd2
, hdc
, NULL
);
97 COMPARE_CACHE(draw_parent_chain
);
99 DrawThemeParentBackground(hWnd1
, hdc
, NULL
);
101 COMPARE_CACHE(empty_chain
);
103 memset(&rc
, 0, sizeof(rc
));
105 DrawThemeParentBackground(hWnd2
, hdc
, &rc
);
107 COMPARE_CACHE(draw_parent_chain
);
109 DrawThemeParentBackground(hWnd1
, hdc
, &rc
);
111 COMPARE_CACHE(empty_chain
);
116 static LONG WINAPI
VEHandler_1(PEXCEPTION_POINTERS ExceptionInfo
)
118 ok(FALSE
, "VEHandler_1 called!\n");
119 return EXCEPTION_CONTINUE_SEARCH
;
122 static LONG WINAPI
VEHandler_2(PEXCEPTION_POINTERS ExceptionInfo
)
124 bGotException
= TRUE
;
125 return EXCEPTION_CONTINUE_SEARCH
;
134 bGotException
= FALSE
;
136 pVEH
= AddVectoredExceptionHandler(1, VEHandler_1
);
138 hr
= DrawThemeParentBackground(NULL
, NULL
, NULL
);
139 ok (hr
== E_HANDLE
, "Expected E_HANDLE got 0x%lx error\n", hr
);
141 hr
= DrawThemeParentBackground((HWND
)0xdeaddead, NULL
, NULL
);
142 ok (hr
== E_HANDLE
, "Expected E_HANDLE got 0x%lx error\n", hr
);
144 hr
= DrawThemeParentBackground(NULL
, (HDC
)0xdeaddead, NULL
);
145 ok (hr
== E_HANDLE
, "Expected E_HANDLE got 0x%lx error\n", hr
);
147 hr
= DrawThemeParentBackground((HWND
)0xdeaddead, (HDC
)0xdeaddead, NULL
);
148 ok (hr
== E_HANDLE
, "Expected E_HANDLE got 0x%lx error\n", hr
);
150 RemoveVectoredExceptionHandler(pVEH
);
152 RegisterSimpleClass(DefWindowProcW
, L
"testClass2");
154 hWnd1
= CreateWindowW(L
"testClass2", L
"Test parent", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
, 100, 100, 200, 200, 0, NULL
, NULL
, NULL
);
155 ok (hWnd1
!= NULL
, "Expected CreateWindowW to succeed\n");
156 hWnd2
= CreateWindowW(L
"testClass2", L
"test window", WS_CHILD
| WS_VISIBLE
, 0, 0, 100, 100, hWnd1
, NULL
, NULL
, NULL
);
157 ok (hWnd2
!= NULL
, "Expected CreateWindowW to succeed\n");
159 ShowWindow(hWnd1
, SW_SHOW
);
161 ShowWindow(hWnd2
, SW_SHOW
);
164 hr
= DrawThemeParentBackground(hWnd1
, NULL
, NULL
);
165 ok (hr
== E_HANDLE
, "Expected E_HANDLE got 0x%lx error\n", hr
);
168 ok (hdc
!= NULL
, "Expected GetDC to succeed\n");
170 hr
= DrawThemeParentBackground(NULL
, hdc
, NULL
);
171 ok (hr
== E_HANDLE
, "Expected E_HANDLE got 0x%lx error\n", hr
);
173 hr
= DrawThemeParentBackground(hWnd1
, hdc
, NULL
);
174 ok (hr
== S_OK
, "Expected success got 0x%lx error\n", hr
);
176 hr
= DrawThemeParentBackground(hWnd1
, (HDC
)0xdeaddead, NULL
);
177 ok (hr
== S_OK
, "Expected success got 0x%lx error\n", hr
);
179 pVEH
= AddVectoredExceptionHandler(1, VEHandler_2
);
180 hr
= DrawThemeParentBackground(hWnd1
, hdc
, (RECT
*)0xdeaddead);
181 ok (hr
== E_POINTER
, "Expected success got 0x%lx error\n", hr
);
182 RemoveVectoredExceptionHandler(pVEH
);
183 ok (bGotException
== TRUE
, "Excepted a handled exception\n");
185 hr
= DrawThemeParentBackground(hWnd2
, NULL
, NULL
);
186 ok (hr
== E_HANDLE
, "Expected E_HANDLE got 0x%lx error\n", hr
);
188 hr
= DrawThemeParentBackground(hWnd2
, hdc
, NULL
);
189 ok (hr
== S_FALSE
, "Expected S_FALSE got 0x%lx error\n", hr
);
191 ReleaseDC(hWnd1
, hdc
);
193 ok (hdc
!= NULL
, "Expected GetDC to succeed\n");
195 hr
= DrawThemeParentBackground(hWnd1
, hdc
, NULL
);
196 ok (hr
== S_OK
, "Expected success got 0x%lx error\n", hr
);
198 hr
= DrawThemeParentBackground(hWnd2
, hdc
, NULL
);
199 ok (hr
== S_FALSE
, "Expected S_FALSE got 0x%lx error\n", hr
);
200 ReleaseDC(hWnd2
, hdc
);
205 START_TEST(DrawThemeParentBackground
)