2 * Unit tests for monitor APIs
4 * Copyright 2005 Huw Davies
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "wine/test.h"
27 static BOOL (WINAPI *pEnumDisplayDevicesA)(LPCSTR,DWORD,LPDISPLAY_DEVICEA,DWORD);
28 static BOOL (WINAPI *pEnumDisplayMonitors)(HDC,LPRECT,MONITORENUMPROC,LPARAM);
29 static BOOL (WINAPI *pGetMonitorInfoA)(HMONITOR,LPMONITORINFO);
30 static HMONITOR (WINAPI *pMonitorFromPoint)(POINT,DWORD);
31 static HMONITOR (WINAPI *pMonitorFromWindow)(HWND,DWORD);
33 static void init_function_pointers(void)
35 hdll = GetModuleHandleA("user32.dll");
39 pEnumDisplayDevicesA = (void*)GetProcAddress(hdll, "EnumDisplayDevicesA");
40 pEnumDisplayMonitors = (void*)GetProcAddress(hdll, "EnumDisplayMonitors");
41 pGetMonitorInfoA = (void*)GetProcAddress(hdll, "GetMonitorInfoA");
42 pMonitorFromPoint = (void*)GetProcAddress(hdll, "MonitorFromPoint");
43 pMonitorFromWindow = (void*)GetProcAddress(hdll, "MonitorFromWindow");
47 static BOOL CALLBACK monitor_enum_proc(HMONITOR hmon, HDC hdc, LPRECT lprc,
51 char *primary = (char *)lparam;
53 mi.cbSize = sizeof(mi);
55 ok(pGetMonitorInfoA(hmon, (MONITORINFO*)&mi), "GetMonitorInfo failed\n");
56 if(mi.dwFlags == MONITORINFOF_PRIMARY)
57 strcpy(primary, mi.szDevice);
62 static void test_enumdisplaydevices(void)
65 char primary_device_name[32];
66 char primary_monitor_device_name[32];
67 DWORD primary_num = -1, num = 0;
70 if(pEnumDisplayDevicesA == NULL) return;
75 ret = pEnumDisplayDevicesA(NULL, num, &dd, 0);
76 ok(ret || num != 0, "EnumDisplayDevices fails with num == 0\n");
78 if(dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
80 strcpy(primary_device_name, dd.DeviceName);
83 if(dd.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)
85 /* test creating DC */
86 dc = CreateDCA(dd.DeviceName, NULL, NULL, NULL);
87 ok(dc != NULL, "Failed to CreateDC(\"%s\") err=%d\n", dd.DeviceName, GetLastError());
92 ok(primary_num != -1, "Didn't get the primary device\n");
94 if(pEnumDisplayMonitors && pGetMonitorInfoA) {
95 ok(pEnumDisplayMonitors(NULL, NULL, monitor_enum_proc, (LPARAM)primary_monitor_device_name),
96 "EnumDisplayMonitors failed\n");
98 ok(!strcmp(primary_monitor_device_name, primary_device_name),
99 "monitor device name %s, device name %s\n", primary_monitor_device_name,
100 primary_device_name);
106 DWORD w, h, bpp, freq, fields;
110 static struct vid_mode vid_modes_test[] = {
111 {640, 480, 0, 0, DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY, 1},
112 {640, 480, 0, 0, DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY, 1},
113 {640, 480, 0, 0, DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL , 1},
114 {640, 480, 0, 0, DM_PELSWIDTH | DM_PELSHEIGHT , 1},
115 {640, 480, 0, 0, DM_BITSPERPEL , 1},
116 {640, 480, 0, 0, DM_DISPLAYFREQUENCY, 1},
118 {0, 0, 0, 0, DM_PELSWIDTH, 1},
119 {0, 0, 0, 0, DM_PELSHEIGHT, 1},
121 {640, 480, 0, 0, DM_PELSWIDTH, 0},
122 {640, 480, 0, 0, DM_PELSHEIGHT, 0},
123 { 0, 480, 0, 0, DM_PELSWIDTH | DM_PELSHEIGHT, 0},
124 {640, 0, 0, 0, DM_PELSWIDTH | DM_PELSHEIGHT, 0},
126 {0, 0, 0, 0, DM_DISPLAYFREQUENCY, 0},
128 #define vid_modes_cnt (sizeof(vid_modes_test) / sizeof(vid_modes_test[0]))
130 static void test_ChangeDisplaySettingsEx(void)
136 memset(&dm, 0, sizeof(dm));
137 dm.dmSize = sizeof(dm);
139 for (i = 0; i < vid_modes_cnt; i++)
141 dm.dmPelsWidth = vid_modes_test[i].w;
142 dm.dmPelsHeight = vid_modes_test[i].h;
143 dm.dmBitsPerPel = vid_modes_test[i].bpp;
144 dm.dmDisplayFrequency = vid_modes_test[i].freq;
145 dm.dmFields = vid_modes_test[i].fields;
146 res = ChangeDisplaySettingsEx(NULL, &dm, NULL, CDS_FULLSCREEN, NULL);
147 ok(vid_modes_test[i].success ?
148 (res == DISP_CHANGE_SUCCESSFUL) :
149 (res == DISP_CHANGE_BADMODE || res == DISP_CHANGE_BADPARAM),
150 "Unexpected ChangeDisplaySettingsEx() return code for resolution[%d]: %d\n", i, res);
152 if (res == DISP_CHANGE_SUCCESSFUL)
156 SetRect(&virt, 0, 0, GetSystemMetrics(SM_CXVIRTUALSCREEN), GetSystemMetrics(SM_CYVIRTUALSCREEN));
157 OffsetRect(&virt, GetSystemMetrics(SM_XVIRTUALSCREEN), GetSystemMetrics(SM_YVIRTUALSCREEN));
159 /* Resolution change resets clip rect */
160 ok(GetClipCursor(&r), "GetClipCursor() failed\n");
161 ok(EqualRect(&r, &virt), "Invalid clip rect: (%d %d) x (%d %d)\n", r.left, r.top, r.right, r.bottom);
163 ok(ClipCursor(NULL), "ClipCursor() failed\n");
164 ok(GetClipCursor(&r), "GetClipCursor() failed\n");
165 ok(EqualRect(&r, &virt), "Invalid clip rect: (%d %d) x (%d %d)\n", r.left, r.top, r.right, r.bottom);
167 /* This should always work. Primary monitor is at (0,0) */
168 SetRect(&r1, 10, 10, 20, 20);
169 ok(ClipCursor(&r1), "ClipCursor() failed\n");
170 ok(GetClipCursor(&r), "GetClipCursor() failed\n");
171 ok(EqualRect(&r, &r1), "Invalid clip rect: (%d %d) x (%d %d)\n", r.left, r.top, r.right, r.bottom);
173 SetRect(&r1, virt.left - 10, virt.top - 10, virt.right + 20, virt.bottom + 20);
174 ok(ClipCursor(&r1), "ClipCursor() failed\n");
175 ok(GetClipCursor(&r), "GetClipCursor() failed\n");
176 ok(EqualRect(&r, &virt), "Invalid clip rect: (%d %d) x (%d %d)\n", r.left, r.top, r.right, r.bottom);
179 res = ChangeDisplaySettingsEx(NULL, NULL, NULL, CDS_RESET, NULL);
180 ok(res == DISP_CHANGE_SUCCESSFUL, "Failed to reset default resolution: %d\n", res);
183 static void test_monitors(void)
185 HMONITOR monitor, primary;
189 primary = pMonitorFromPoint( pt, MONITOR_DEFAULTTOPRIMARY );
190 ok( primary != 0, "couldn't get primary monitor\n" );
192 monitor = pMonitorFromWindow( 0, MONITOR_DEFAULTTONULL );
193 ok( !monitor, "got %p, should not get a monitor for an invalid window\n", monitor );
194 monitor = pMonitorFromWindow( 0, MONITOR_DEFAULTTOPRIMARY );
195 ok( monitor == primary, "got %p, should get primary %p for MONITOR_DEFAULTTOPRIMARY\n", monitor, primary );
196 monitor = pMonitorFromWindow( 0, MONITOR_DEFAULTTONEAREST );
197 ok( monitor == primary, "got %p, should get primary %p for MONITOR_DEFAULTTONEAREST\n", monitor, primary );
203 init_function_pointers();
204 test_enumdisplaydevices();
205 if (winetest_interactive)
206 test_ChangeDisplaySettingsEx();
207 if (pMonitorFromPoint && pMonitorFromWindow)