[USER32_WINETEST]
[reactos.git] / rostests / winetests / user32 / monitor.c
1 /*
2 * Unit tests for monitor APIs
3 *
4 * Copyright 2005 Huw Davies
5 * Copyright 2008 Dmitry Timoshkov
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22 #include "wine/test.h"
23 #include "winbase.h"
24 #include "wingdi.h"
25 #include "winuser.h"
26
27 static HMODULE hdll;
28 static LONG (WINAPI *pChangeDisplaySettingsExA)(LPCSTR, LPDEVMODEA, HWND, DWORD, LPVOID);
29 static LONG (WINAPI *pChangeDisplaySettingsExW)(LPCWSTR, LPDEVMODEW, HWND, DWORD, LPVOID);
30 static BOOL (WINAPI *pEnumDisplayDevicesA)(LPCSTR,DWORD,LPDISPLAY_DEVICEA,DWORD);
31 static BOOL (WINAPI *pEnumDisplayMonitors)(HDC,LPRECT,MONITORENUMPROC,LPARAM);
32 static BOOL (WINAPI *pGetMonitorInfoA)(HMONITOR,LPMONITORINFO);
33 static BOOL (WINAPI *pGetMonitorInfoW)(HMONITOR,LPMONITORINFO);
34 static HMONITOR (WINAPI *pMonitorFromPoint)(POINT,DWORD);
35 static HMONITOR (WINAPI *pMonitorFromRect)(LPCRECT,DWORD);
36 static HMONITOR (WINAPI *pMonitorFromWindow)(HWND,DWORD);
37
38 static void init_function_pointers(void)
39 {
40 hdll = GetModuleHandleA("user32.dll");
41
42 #define GET_PROC(func) \
43 p ## func = (void*)GetProcAddress(hdll, #func); \
44 if(!p ## func) \
45 trace("GetProcAddress(%s) failed\n", #func);
46
47 GET_PROC(ChangeDisplaySettingsExA)
48 GET_PROC(ChangeDisplaySettingsExW)
49 GET_PROC(EnumDisplayDevicesA)
50 GET_PROC(EnumDisplayMonitors)
51 GET_PROC(GetMonitorInfoA)
52 GET_PROC(GetMonitorInfoW)
53 GET_PROC(MonitorFromPoint)
54 GET_PROC(MonitorFromRect)
55 GET_PROC(MonitorFromWindow)
56
57 #undef GET_PROC
58 }
59
60 static BOOL CALLBACK monitor_enum_proc(HMONITOR hmon, HDC hdc, LPRECT lprc,
61 LPARAM lparam)
62 {
63 MONITORINFOEXA mi;
64 char *primary = (char *)lparam;
65
66 mi.cbSize = sizeof(mi);
67
68 ok(pGetMonitorInfoA(hmon, (MONITORINFO*)&mi), "GetMonitorInfo failed\n");
69 if (mi.dwFlags & MONITORINFOF_PRIMARY)
70 strcpy(primary, mi.szDevice);
71
72 return TRUE;
73 }
74
75 static void test_enumdisplaydevices(void)
76 {
77 DISPLAY_DEVICEA dd;
78 char primary_device_name[32];
79 char primary_monitor_device_name[32];
80 DWORD primary_num = -1, num = 0;
81 BOOL ret;
82
83 if (!pEnumDisplayDevicesA)
84 {
85 win_skip("EnumDisplayDevicesA is not available\n");
86 return;
87 }
88
89 dd.cb = sizeof(dd);
90 while(1)
91 {
92 BOOL ret;
93 HDC dc;
94 ret = pEnumDisplayDevicesA(NULL, num, &dd, 0);
95 if(!ret) break;
96 if(dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
97 {
98 strcpy(primary_device_name, dd.DeviceName);
99 primary_num = num;
100 }
101 if(dd.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)
102 {
103 /* test creating DC */
104 dc = CreateDCA(dd.DeviceName, NULL, NULL, NULL);
105 ok(dc != NULL, "Failed to CreateDC(\"%s\") err=%d\n", dd.DeviceName, GetLastError());
106 DeleteDC(dc);
107 }
108 num++;
109 }
110
111 if (primary_num == -1 || !pEnumDisplayMonitors || !pGetMonitorInfoA)
112 {
113 win_skip("EnumDisplayMonitors or GetMonitorInfoA are not available\n");
114 return;
115 }
116
117 primary_monitor_device_name[0] = 0;
118 ret = pEnumDisplayMonitors(NULL, NULL, monitor_enum_proc, (LPARAM)primary_monitor_device_name);
119 ok(ret, "EnumDisplayMonitors failed\n");
120 ok(!strcmp(primary_monitor_device_name, primary_device_name),
121 "monitor device name %s, device name %s\n", primary_monitor_device_name,
122 primary_device_name);
123 }
124
125 struct vid_mode
126 {
127 DWORD w, h, bpp, freq, fields;
128 BOOL must_succeed;
129 };
130
131 static const struct vid_mode vid_modes_test[] = {
132 {640, 480, 0, 0, DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY, 1},
133 {640, 480, 0, 0, DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY, 1},
134 {640, 480, 0, 0, DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL , 1},
135 {640, 480, 0, 0, DM_PELSWIDTH | DM_PELSHEIGHT , 1},
136 {640, 480, 0, 0, DM_BITSPERPEL , 0},
137 {640, 480, 0, 0, DM_DISPLAYFREQUENCY, 0},
138
139 {0, 0, 0, 0, DM_PELSWIDTH, 0},
140 {0, 0, 0, 0, DM_PELSHEIGHT, 0},
141
142 {640, 480, 0, 0, DM_PELSWIDTH, 0},
143 {640, 480, 0, 0, DM_PELSHEIGHT, 0},
144 { 0, 480, 0, 0, DM_PELSWIDTH | DM_PELSHEIGHT, 0},
145 {640, 0, 0, 0, DM_PELSWIDTH | DM_PELSHEIGHT, 0},
146
147 /* the following test succeeds under XP SP3
148 {0, 0, 0, 0, DM_DISPLAYFREQUENCY, 0}
149 */
150 };
151 #define vid_modes_cnt (sizeof(vid_modes_test) / sizeof(vid_modes_test[0]))
152
153 static void test_ChangeDisplaySettingsEx(void)
154 {
155 DEVMODEA dm;
156 DEVMODEW dmW;
157 DWORD width;
158 LONG res;
159 int i;
160
161 if (!pChangeDisplaySettingsExA)
162 {
163 win_skip("ChangeDisplaySettingsExA is not available\n");
164 return;
165 }
166
167 SetLastError(0xdeadbeef);
168 res = EnumDisplaySettingsA(NULL, ENUM_CURRENT_SETTINGS, &dm);
169 ok(res, "EnumDisplaySettings error %u\n", GetLastError());
170
171 width = dm.dmPelsWidth;
172
173 dm.dmDriverExtra = 1;
174 res = ChangeDisplaySettingsA(&dm, CDS_TEST);
175 ok(res == DISP_CHANGE_SUCCESSFUL,
176 "ChangeDisplaySettingsA returned %d, expected DISP_CHANGE_SUCCESSFUL\n", res);
177 ok(dm.dmDriverExtra == 0 || broken(dm.dmDriverExtra == 1) /* win9x */,
178 "ChangeDisplaySettingsA didn't reset dmDriverExtra to 0\n");
179
180 /* crashes under XP SP3 for large dmDriverExtra values */
181 dm.dmDriverExtra = 1;
182 res = pChangeDisplaySettingsExA(NULL, &dm, NULL, CDS_TEST, NULL);
183 ok(res == DISP_CHANGE_SUCCESSFUL,
184 "ChangeDisplaySettingsExW returned %d, expected DISP_CHANGE_SUCCESSFUL\n", res);
185 ok(dm.dmDriverExtra == 1, "ChangeDisplaySettingsExA shouldn't reset dmDriverExtra to 0\n");
186
187 memset(&dmW, 0, sizeof(dmW));
188 dmW.dmSize = sizeof(dmW);
189 dmW.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
190 dmW.dmPelsWidth = dm.dmPelsWidth;
191 dmW.dmPelsHeight = dm.dmPelsHeight;
192 dmW.dmDriverExtra = 1;
193 SetLastError(0xdeadbeef);
194 res = ChangeDisplaySettingsW(&dmW, CDS_TEST);
195 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
196 {
197 ok(res == DISP_CHANGE_SUCCESSFUL,
198 "ChangeDisplaySettingsW returned %d, expected DISP_CHANGE_SUCCESSFUL\n", res);
199 ok(dmW.dmDriverExtra == 0, "ChangeDisplaySettingsW didn't reset dmDriverExtra to 0\n");
200 }
201
202 /* Apparently XP treats dmDriverExtra being != 0 as an error */
203 dmW.dmDriverExtra = 1;
204 res = pChangeDisplaySettingsExW(NULL, &dmW, NULL, CDS_TEST, NULL);
205 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
206 {
207 ok(res == DISP_CHANGE_SUCCESSFUL,
208 "ChangeDisplaySettingsExW returned %d, expected DISP_CHANGE_SUCCESSFUL\n", res);
209 ok(dmW.dmDriverExtra == 1, "ChangeDisplaySettingsExW shouldn't reset dmDriverExtra to 0\n");
210 }
211
212 /* the following 2 tests show that dm.dmSize being 0 is invalid, but
213 * ChangeDisplaySettingsExA still reports success.
214 */
215 memset(&dm, 0, sizeof(dm));
216 dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
217 dm.dmPelsWidth = width;
218 res = pChangeDisplaySettingsExA(NULL, &dm, NULL, CDS_TEST, NULL);
219 ok(res == DISP_CHANGE_SUCCESSFUL ||
220 res == DISP_CHANGE_BADMODE || /* Win98, WinMe */
221 res == DISP_CHANGE_FAILED, /* NT4 */
222 "ChangeDisplaySettingsExA returned unexpected %d\n", res);
223
224 memset(&dmW, 0, sizeof(dmW));
225 dmW.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
226 dmW.dmPelsWidth = width;
227 SetLastError(0xdeadbeef);
228 res = pChangeDisplaySettingsExW(NULL, &dmW, NULL, CDS_TEST, NULL);
229 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
230 ok(res == DISP_CHANGE_FAILED ||
231 res == DISP_CHANGE_BADPARAM || /* NT4 */
232 res == DISP_CHANGE_BADMODE /* XP SP3 */,
233 "ChangeDisplaySettingsExW returned %d\n", res);
234
235 memset(&dm, 0, sizeof(dm));
236 dm.dmSize = sizeof(dm);
237
238 for (i = 0; i < vid_modes_cnt; i++)
239 {
240 dm.dmPelsWidth = vid_modes_test[i].w;
241 dm.dmPelsHeight = vid_modes_test[i].h;
242 dm.dmBitsPerPel = vid_modes_test[i].bpp;
243 dm.dmDisplayFrequency = vid_modes_test[i].freq;
244 dm.dmFields = vid_modes_test[i].fields;
245 res = pChangeDisplaySettingsExA(NULL, &dm, NULL, CDS_TEST, NULL);
246 ok(vid_modes_test[i].must_succeed ?
247 (res == DISP_CHANGE_SUCCESSFUL || res == DISP_CHANGE_RESTART) :
248 (res == DISP_CHANGE_SUCCESSFUL || res == DISP_CHANGE_RESTART ||
249 res == DISP_CHANGE_BADMODE || res == DISP_CHANGE_BADPARAM),
250 "Unexpected ChangeDisplaySettingsEx() return code for resolution[%d]: %d\n", i, res);
251
252 if (res == DISP_CHANGE_SUCCESSFUL)
253 {
254 RECT r, r1, virt;
255
256 SetRect(&virt, 0, 0, GetSystemMetrics(SM_CXVIRTUALSCREEN), GetSystemMetrics(SM_CYVIRTUALSCREEN));
257 if (IsRectEmpty(&virt)) /* NT4 doesn't have SM_CX/YVIRTUALSCREEN */
258 SetRect(&virt, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
259 OffsetRect(&virt, GetSystemMetrics(SM_XVIRTUALSCREEN), GetSystemMetrics(SM_YVIRTUALSCREEN));
260
261 /* Resolution change resets clip rect */
262 ok(GetClipCursor(&r), "GetClipCursor() failed\n");
263 ok(EqualRect(&r, &virt), "Invalid clip rect: (%d %d) x (%d %d)\n", r.left, r.top, r.right, r.bottom);
264
265 if (!ClipCursor(NULL)) continue;
266 ok(GetClipCursor(&r), "GetClipCursor() failed\n");
267 ok(EqualRect(&r, &virt), "Invalid clip rect: (%d %d) x (%d %d)\n", r.left, r.top, r.right, r.bottom);
268
269 /* This should always work. Primary monitor is at (0,0) */
270 SetRect(&r1, 10, 10, 20, 20);
271 ok(ClipCursor(&r1), "ClipCursor() failed\n");
272 ok(GetClipCursor(&r), "GetClipCursor() failed\n");
273 ok(EqualRect(&r, &r1), "Invalid clip rect: (%d %d) x (%d %d)\n", r.left, r.top, r.right, r.bottom);
274 SetRect(&r1, 10, 10, 10, 10);
275 ok(ClipCursor(&r1), "ClipCursor() failed\n");
276 ok(GetClipCursor(&r), "GetClipCursor() failed\n");
277 ok(EqualRect(&r, &r1), "Invalid clip rect: (%d %d) x (%d %d)\n", r.left, r.top, r.right, r.bottom);
278 SetRect(&r1, 10, 10, 10, 9);
279 ok(!ClipCursor(&r1), "ClipCursor() succeeded\n");
280 /* Windows bug: further clipping fails once an empty rect is set, so we have to reset it */
281 ClipCursor(NULL);
282
283 SetRect(&r1, virt.left - 10, virt.top - 10, virt.right + 20, virt.bottom + 20);
284 ok(ClipCursor(&r1), "ClipCursor() failed\n");
285 ok(GetClipCursor(&r), "GetClipCursor() failed\n");
286 ok(EqualRect(&r, &virt) ||
287 broken(EqualRect(&r, &r1)) /* win9x */,
288 "Invalid clip rect: (%d %d) x (%d %d)\n", r.left, r.top, r.right, r.bottom);
289 ClipCursor(&virt);
290 }
291 }
292 res = pChangeDisplaySettingsExA(NULL, NULL, NULL, CDS_RESET, NULL);
293 ok(res == DISP_CHANGE_SUCCESSFUL, "Failed to reset default resolution: %d\n", res);
294 }
295
296 static void test_monitors(void)
297 {
298 HMONITOR monitor, primary, nearest;
299 POINT pt;
300 RECT rc;
301 MONITORINFO mi;
302 MONITORINFOEXA miexa;
303 MONITORINFOEXW miexw;
304 BOOL ret;
305 DWORD i;
306
307 static const struct
308 {
309 DWORD cbSize;
310 BOOL ret;
311 } testdatami[] = {
312 {0, FALSE},
313 {sizeof(MONITORINFO)+1, FALSE},
314 {sizeof(MONITORINFO)-1, FALSE},
315 {sizeof(MONITORINFO), TRUE},
316 {-1, FALSE},
317 {0xdeadbeef, FALSE},
318 },
319 testdatamiexa[] = {
320 {0, FALSE},
321 {sizeof(MONITORINFOEXA)+1, FALSE},
322 {sizeof(MONITORINFOEXA)-1, FALSE},
323 {sizeof(MONITORINFOEXA), TRUE},
324 {-1, FALSE},
325 {0xdeadbeef, FALSE},
326 },
327 testdatamiexw[] = {
328 {0, FALSE},
329 {sizeof(MONITORINFOEXW)+1, FALSE},
330 {sizeof(MONITORINFOEXW)-1, FALSE},
331 {sizeof(MONITORINFOEXW), TRUE},
332 {-1, FALSE},
333 {0xdeadbeef, FALSE},
334 };
335
336 if (!pMonitorFromPoint || !pMonitorFromWindow || !pMonitorFromRect)
337 {
338 win_skip("MonitorFromPoint, MonitorFromWindow, or MonitorFromRect is not available\n");
339 return;
340 }
341
342 pt.x = pt.y = 0;
343 primary = pMonitorFromPoint( pt, MONITOR_DEFAULTTOPRIMARY );
344 ok( primary != 0, "couldn't get primary monitor\n" );
345
346 monitor = pMonitorFromWindow( 0, MONITOR_DEFAULTTONULL );
347 ok( !monitor, "got %p, should not get a monitor for an invalid window\n", monitor );
348 monitor = pMonitorFromWindow( 0, MONITOR_DEFAULTTOPRIMARY );
349 ok( monitor == primary, "got %p, should get primary %p for MONITOR_DEFAULTTOPRIMARY\n", monitor, primary );
350 monitor = pMonitorFromWindow( 0, MONITOR_DEFAULTTONEAREST );
351 ok( monitor == primary, "got %p, should get primary %p for MONITOR_DEFAULTTONEAREST\n", monitor, primary );
352
353 SetRect( &rc, 0, 0, 1, 1 );
354 monitor = pMonitorFromRect( &rc, MONITOR_DEFAULTTONULL );
355 ok( monitor == primary, "got %p, should get primary %p\n", monitor, primary );
356
357 monitor = pMonitorFromRect( &rc, MONITOR_DEFAULTTOPRIMARY );
358 ok( monitor == primary, "got %p, should get primary %p\n", monitor, primary );
359
360 monitor = pMonitorFromRect( &rc, MONITOR_DEFAULTTONEAREST );
361 ok( monitor == primary, "got %p, should get primary %p\n", monitor, primary );
362
363 /* Empty rect at 0,0 is considered inside the primary monitor */
364 SetRect( &rc, 0, 0, -1, -1 );
365 monitor = pMonitorFromRect( &rc, MONITOR_DEFAULTTONULL );
366 ok( monitor == primary, "got %p, should get primary %p\n", monitor, primary );
367
368 /* Even if there is a monitor left of the primary, the primary will have the most overlapping area */
369 SetRect( &rc, -1, 0, 2, 1 );
370 monitor = pMonitorFromRect( &rc, MONITOR_DEFAULTTONULL );
371 ok( monitor == primary, "got %p, should get primary %p\n", monitor, primary );
372
373 /* But the width of the rect doesn't matter if it's empty. */
374 SetRect( &rc, -1, 0, 2, -1 );
375 monitor = pMonitorFromRect( &rc, MONITOR_DEFAULTTONULL );
376 ok( monitor != primary, "got primary %p\n", monitor );
377
378 if (!pGetMonitorInfoA)
379 {
380 win_skip("GetMonitorInfoA is not available\n");
381 return;
382 }
383
384 /* Search for a monitor that has no others equally near to (left, top-1) */
385 SetRect( &rc, -1, -2, 2, 0 );
386 monitor = pMonitorFromRect( &rc, MONITOR_DEFAULTTONULL );
387 nearest = primary;
388 while (monitor != NULL)
389 {
390 ok( monitor != primary, "got primary %p\n", monitor );
391 nearest = monitor;
392 mi.cbSize = sizeof(mi);
393 ret = pGetMonitorInfoA( monitor, &mi );
394 ok( ret, "GetMonitorInfo failed\n" );
395 SetRect( &rc, mi.rcMonitor.left-1, mi.rcMonitor.top-2, mi.rcMonitor.left+2, mi.rcMonitor.top );
396 monitor = pMonitorFromRect( &rc, MONITOR_DEFAULTTONULL );
397 }
398
399 /* tests for cbSize in MONITORINFO */
400 monitor = pMonitorFromWindow( 0, MONITOR_DEFAULTTOPRIMARY );
401 for (i = 0; i < (sizeof(testdatami) / sizeof(testdatami[0])); i++)
402 {
403 memset( &mi, 0, sizeof(mi) );
404 mi.cbSize = testdatami[i].cbSize;
405 ret = pGetMonitorInfoA( monitor, &mi );
406 ok( ret == testdatami[i].ret, "GetMonitorInfo returned wrong value\n" );
407 if (ret)
408 ok( (mi.dwFlags & MONITORINFOF_PRIMARY), "MONITORINFOF_PRIMARY flag isn't set\n" );
409 else
410 ok( !(mi.dwFlags & MONITORINFOF_PRIMARY), "MONITORINFOF_PRIMARY flag is set\n" );
411
412 memset( &miexw, 0, sizeof(miexw) );
413 miexw.cbSize = testdatamiexw[i].cbSize;
414 ret = pGetMonitorInfoW( monitor, (LPMONITORINFO)&miexw );
415 ok( ret == testdatamiexw[i].ret, "GetMonitorInfo returned wrong value\n" );
416 if (ret)
417 ok( (miexw.dwFlags & MONITORINFOF_PRIMARY), "MONITORINFOF_PRIMARY flag isn't set\n" );
418 else
419 ok( !(miexw.dwFlags & MONITORINFOF_PRIMARY), "MONITORINFOF_PRIMARY flag is set\n" );
420 }
421
422 /* tests for cbSize in MONITORINFOEXA */
423 for (i = 0; i < (sizeof(testdatamiexa) / sizeof(testdatamiexa[0])); i++)
424 {
425 memset( &miexa, 0, sizeof(miexa) );
426 miexa.cbSize = testdatamiexa[i].cbSize;
427 ret = pGetMonitorInfoA( monitor, (LPMONITORINFO)&miexa );
428 ok( ret == testdatamiexa[i].ret, "GetMonitorInfo returned wrong value\n" );
429 if (ret)
430 ok( (miexa.dwFlags & MONITORINFOF_PRIMARY), "MONITORINFOF_PRIMARY flag isn't set\n" );
431 else
432 ok( !(miexa.dwFlags & MONITORINFOF_PRIMARY), "MONITORINFOF_PRIMARY flag is set\n" );
433 }
434
435 /* tests for cbSize in MONITORINFOEXW */
436 for (i = 0; i < (sizeof(testdatamiexw) / sizeof(testdatamiexw[0])); i++)
437 {
438 memset( &miexw, 0, sizeof(miexw) );
439 miexw.cbSize = testdatamiexw[i].cbSize;
440 ret = pGetMonitorInfoW( monitor, (LPMONITORINFO)&miexw );
441 ok( ret == testdatamiexw[i].ret, "GetMonitorInfo returned wrong value\n" );
442 if (ret)
443 ok( (miexw.dwFlags & MONITORINFOF_PRIMARY), "MONITORINFOF_PRIMARY flag isn't set\n" );
444 else
445 ok( !(miexw.dwFlags & MONITORINFOF_PRIMARY), "MONITORINFOF_PRIMARY flag is set\n" );
446 }
447
448 SetRect( &rc, rc.left+1, rc.top+1, rc.left+2, rc.top+2 );
449
450 monitor = pMonitorFromRect( &rc, MONITOR_DEFAULTTONULL );
451 ok( monitor == NULL, "got %p\n", monitor );
452
453 monitor = pMonitorFromRect( &rc, MONITOR_DEFAULTTOPRIMARY );
454 ok( monitor == primary, "got %p, should get primary %p\n", monitor, primary );
455
456 monitor = pMonitorFromRect( &rc, MONITOR_DEFAULTTONEAREST );
457 ok( monitor == nearest, "got %p, should get nearest %p\n", monitor, nearest );
458 }
459
460 static BOOL CALLBACK find_primary_mon(HMONITOR hmon, HDC hdc, LPRECT rc, LPARAM lp)
461 {
462 MONITORINFO mi;
463 BOOL ret;
464
465 mi.cbSize = sizeof(mi);
466 ret = pGetMonitorInfoA(hmon, &mi);
467 ok(ret, "GetMonitorInfo failed\n");
468 if (mi.dwFlags & MONITORINFOF_PRIMARY)
469 {
470 *(HMONITOR *)lp = hmon;
471 return FALSE;
472 }
473 return TRUE;
474 }
475
476 static void test_work_area(void)
477 {
478 HMONITOR hmon;
479 MONITORINFO mi;
480 RECT rc_work, rc_normal;
481 HWND hwnd;
482 WINDOWPLACEMENT wp;
483 BOOL ret;
484
485 if (!pEnumDisplayMonitors || !pGetMonitorInfoA)
486 {
487 win_skip("EnumDisplayMonitors or GetMonitorInfoA are not available\n");
488 return;
489 }
490
491 hmon = 0;
492 ret = pEnumDisplayMonitors(NULL, NULL, find_primary_mon, (LPARAM)&hmon);
493 ok(!ret && hmon != 0, "Failed to find primary monitor\n");
494
495 mi.cbSize = sizeof(mi);
496 SetLastError(0xdeadbeef);
497 ret = pGetMonitorInfoA(hmon, &mi);
498 ok(ret, "GetMonitorInfo error %u\n", GetLastError());
499 ok(mi.dwFlags & MONITORINFOF_PRIMARY, "not a primary monitor\n");
500 trace("primary monitor (%d,%d-%d,%d)\n",
501 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom);
502
503 SetLastError(0xdeadbeef);
504 ret = SystemParametersInfoA(SPI_GETWORKAREA, 0, &rc_work, 0);
505 ok(ret, "SystemParametersInfo error %u\n", GetLastError());
506 trace("work area (%d,%d-%d,%d)\n", rc_work.left, rc_work.top, rc_work.right, rc_work.bottom);
507 ok(EqualRect(&rc_work, &mi.rcWork), "work area is different\n");
508
509 hwnd = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW|WS_VISIBLE,100,100,10,10,0,0,0,NULL);
510 ok(hwnd != 0, "CreateWindowEx failed\n");
511
512 ret = GetWindowRect(hwnd, &rc_normal);
513 ok(ret, "GetWindowRect failed\n");
514 trace("normal (%d,%d-%d,%d)\n", rc_normal.left, rc_normal.top, rc_normal.right, rc_normal.bottom);
515
516 wp.length = sizeof(wp);
517 ret = GetWindowPlacement(hwnd, &wp);
518 ok(ret, "GetWindowPlacement failed\n");
519 trace("min: %d,%d max %d,%d normal %d,%d-%d,%d\n",
520 wp.ptMinPosition.x, wp.ptMinPosition.y,
521 wp.ptMaxPosition.x, wp.ptMaxPosition.y,
522 wp.rcNormalPosition.left, wp.rcNormalPosition.top,
523 wp.rcNormalPosition.right, wp.rcNormalPosition.bottom);
524 OffsetRect(&wp.rcNormalPosition, rc_work.left, rc_work.top);
525 if (mi.rcMonitor.left != mi.rcWork.left ||
526 mi.rcMonitor.top != mi.rcWork.top) /* FIXME: remove once Wine is fixed */
527 todo_wine ok(EqualRect(&rc_normal, &wp.rcNormalPosition), "normal pos is different\n");
528 else
529 ok(EqualRect(&rc_normal, &wp.rcNormalPosition), "normal pos is different\n");
530
531 SetWindowLongA(hwnd, GWL_EXSTYLE, WS_EX_TOOLWINDOW);
532
533 wp.length = sizeof(wp);
534 ret = GetWindowPlacement(hwnd, &wp);
535 ok(ret, "GetWindowPlacement failed\n");
536 trace("min: %d,%d max %d,%d normal %d,%d-%d,%d\n",
537 wp.ptMinPosition.x, wp.ptMinPosition.y,
538 wp.ptMaxPosition.x, wp.ptMaxPosition.y,
539 wp.rcNormalPosition.left, wp.rcNormalPosition.top,
540 wp.rcNormalPosition.right, wp.rcNormalPosition.bottom);
541 ok(EqualRect(&rc_normal, &wp.rcNormalPosition), "normal pos is different\n");
542
543 DestroyWindow(hwnd);
544 }
545
546 START_TEST(monitor)
547 {
548 init_function_pointers();
549 test_enumdisplaydevices();
550 test_ChangeDisplaySettingsEx();
551 test_monitors();
552 test_work_area();
553 }