2005-09-28 12:17:13 +02:00
|
|
|
/*
|
|
|
|
* Unit tests for monitor APIs
|
|
|
|
*
|
|
|
|
* Copyright 2005 Huw Davies
|
2008-08-26 13:40:58 +02:00
|
|
|
* Copyright 2008 Dmitry Timoshkov
|
2005-09-28 12:17:13 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-09-28 12:17:13 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
|
2005-10-11 22:27:27 +02:00
|
|
|
static HMODULE hdll;
|
2007-08-15 14:23:45 +02:00
|
|
|
static LONG (WINAPI *pChangeDisplaySettingsExA)(LPCSTR, LPDEVMODEA, HWND, DWORD, LPVOID);
|
2007-12-20 07:50:30 +01:00
|
|
|
static LONG (WINAPI *pChangeDisplaySettingsExW)(LPCWSTR, LPDEVMODEW, HWND, DWORD, LPVOID);
|
2005-11-17 12:04:01 +01:00
|
|
|
static BOOL (WINAPI *pEnumDisplayDevicesA)(LPCSTR,DWORD,LPDISPLAY_DEVICEA,DWORD);
|
2005-10-11 22:27:27 +02:00
|
|
|
static BOOL (WINAPI *pEnumDisplayMonitors)(HDC,LPRECT,MONITORENUMPROC,LPARAM);
|
|
|
|
static BOOL (WINAPI *pGetMonitorInfoA)(HMONITOR,LPMONITORINFO);
|
2014-04-23 17:35:43 +02:00
|
|
|
static BOOL (WINAPI *pGetMonitorInfoW)(HMONITOR,LPMONITORINFO);
|
2006-12-17 13:10:03 +01:00
|
|
|
static HMONITOR (WINAPI *pMonitorFromPoint)(POINT,DWORD);
|
2014-01-27 22:16:38 +01:00
|
|
|
static HMONITOR (WINAPI *pMonitorFromRect)(LPCRECT,DWORD);
|
2006-12-17 13:10:03 +01:00
|
|
|
static HMONITOR (WINAPI *pMonitorFromWindow)(HWND,DWORD);
|
2015-10-23 20:40:50 +02:00
|
|
|
static LONG (WINAPI *pGetDisplayConfigBufferSizes)(UINT32,UINT32*,UINT32*);
|
2005-10-11 22:27:27 +02:00
|
|
|
|
|
|
|
static void init_function_pointers(void)
|
|
|
|
{
|
|
|
|
hdll = GetModuleHandleA("user32.dll");
|
2007-08-15 14:23:45 +02:00
|
|
|
|
|
|
|
#define GET_PROC(func) \
|
|
|
|
p ## func = (void*)GetProcAddress(hdll, #func); \
|
|
|
|
if(!p ## func) \
|
|
|
|
trace("GetProcAddress(%s) failed\n", #func);
|
|
|
|
|
|
|
|
GET_PROC(ChangeDisplaySettingsExA)
|
2007-12-20 07:50:30 +01:00
|
|
|
GET_PROC(ChangeDisplaySettingsExW)
|
2007-08-15 14:23:45 +02:00
|
|
|
GET_PROC(EnumDisplayDevicesA)
|
|
|
|
GET_PROC(EnumDisplayMonitors)
|
2015-10-23 20:40:50 +02:00
|
|
|
GET_PROC(GetDisplayConfigBufferSizes)
|
2007-08-15 14:23:45 +02:00
|
|
|
GET_PROC(GetMonitorInfoA)
|
2014-04-23 17:35:43 +02:00
|
|
|
GET_PROC(GetMonitorInfoW)
|
2007-08-15 14:23:45 +02:00
|
|
|
GET_PROC(MonitorFromPoint)
|
2014-01-27 22:16:38 +01:00
|
|
|
GET_PROC(MonitorFromRect)
|
2007-08-15 14:23:45 +02:00
|
|
|
GET_PROC(MonitorFromWindow)
|
|
|
|
|
|
|
|
#undef GET_PROC
|
2005-10-11 22:27:27 +02:00
|
|
|
}
|
|
|
|
|
2005-09-28 12:17:13 +02:00
|
|
|
static BOOL CALLBACK monitor_enum_proc(HMONITOR hmon, HDC hdc, LPRECT lprc,
|
|
|
|
LPARAM lparam)
|
|
|
|
{
|
|
|
|
MONITORINFOEXA mi;
|
|
|
|
char *primary = (char *)lparam;
|
|
|
|
|
|
|
|
mi.cbSize = sizeof(mi);
|
|
|
|
|
2005-10-11 22:27:27 +02:00
|
|
|
ok(pGetMonitorInfoA(hmon, (MONITORINFO*)&mi), "GetMonitorInfo failed\n");
|
2008-08-26 13:40:58 +02:00
|
|
|
if (mi.dwFlags & MONITORINFOF_PRIMARY)
|
2005-09-28 12:17:13 +02:00
|
|
|
strcpy(primary, mi.szDevice);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_enumdisplaydevices(void)
|
|
|
|
{
|
|
|
|
DISPLAY_DEVICEA dd;
|
|
|
|
char primary_device_name[32];
|
|
|
|
char primary_monitor_device_name[32];
|
|
|
|
DWORD primary_num = -1, num = 0;
|
2008-08-26 13:40:58 +02:00
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if (!pEnumDisplayDevicesA)
|
|
|
|
{
|
2009-02-23 10:41:03 +01:00
|
|
|
win_skip("EnumDisplayDevicesA is not available\n");
|
2008-08-26 13:40:58 +02:00
|
|
|
return;
|
|
|
|
}
|
2005-09-28 12:17:13 +02:00
|
|
|
|
|
|
|
dd.cb = sizeof(dd);
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
2006-01-03 12:05:54 +01:00
|
|
|
HDC dc;
|
2005-11-17 12:04:01 +01:00
|
|
|
ret = pEnumDisplayDevicesA(NULL, num, &dd, 0);
|
2005-09-28 12:17:13 +02:00
|
|
|
if(!ret) break;
|
|
|
|
if(dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
|
|
|
|
{
|
|
|
|
strcpy(primary_device_name, dd.DeviceName);
|
|
|
|
primary_num = num;
|
|
|
|
}
|
2006-01-03 12:05:54 +01:00
|
|
|
if(dd.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)
|
|
|
|
{
|
|
|
|
/* test creating DC */
|
|
|
|
dc = CreateDCA(dd.DeviceName, NULL, NULL, NULL);
|
2006-10-07 21:45:11 +02:00
|
|
|
ok(dc != NULL, "Failed to CreateDC(\"%s\") err=%d\n", dd.DeviceName, GetLastError());
|
2006-01-03 12:05:54 +01:00
|
|
|
DeleteDC(dc);
|
|
|
|
}
|
2005-09-28 12:17:13 +02:00
|
|
|
num++;
|
|
|
|
}
|
|
|
|
|
2008-11-20 20:06:46 +01:00
|
|
|
if (primary_num == -1 || !pEnumDisplayMonitors || !pGetMonitorInfoA)
|
2008-08-26 13:40:58 +02:00
|
|
|
{
|
2008-11-20 20:06:46 +01:00
|
|
|
win_skip("EnumDisplayMonitors or GetMonitorInfoA are not available\n");
|
2008-08-26 13:40:58 +02:00
|
|
|
return;
|
2005-10-11 22:27:27 +02:00
|
|
|
}
|
2008-08-26 13:40:58 +02:00
|
|
|
|
|
|
|
primary_monitor_device_name[0] = 0;
|
|
|
|
ret = pEnumDisplayMonitors(NULL, NULL, monitor_enum_proc, (LPARAM)primary_monitor_device_name);
|
|
|
|
ok(ret, "EnumDisplayMonitors failed\n");
|
|
|
|
ok(!strcmp(primary_monitor_device_name, primary_device_name),
|
|
|
|
"monitor device name %s, device name %s\n", primary_monitor_device_name,
|
|
|
|
primary_device_name);
|
2005-09-28 12:17:13 +02:00
|
|
|
}
|
|
|
|
|
2006-07-26 07:31:22 +02:00
|
|
|
struct vid_mode
|
|
|
|
{
|
|
|
|
DWORD w, h, bpp, freq, fields;
|
2008-09-17 16:29:32 +02:00
|
|
|
BOOL must_succeed;
|
2006-07-26 07:31:22 +02:00
|
|
|
};
|
|
|
|
|
2007-12-20 07:50:30 +01:00
|
|
|
static const struct vid_mode vid_modes_test[] = {
|
2007-02-22 12:43:06 +01:00
|
|
|
{640, 480, 0, 0, DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY, 1},
|
|
|
|
{640, 480, 0, 0, DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY, 1},
|
|
|
|
{640, 480, 0, 0, DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL , 1},
|
|
|
|
{640, 480, 0, 0, DM_PELSWIDTH | DM_PELSHEIGHT , 1},
|
2008-09-17 16:29:32 +02:00
|
|
|
{640, 480, 0, 0, DM_BITSPERPEL , 0},
|
|
|
|
{640, 480, 0, 0, DM_DISPLAYFREQUENCY, 0},
|
2007-02-22 12:43:06 +01:00
|
|
|
|
2008-09-17 16:29:32 +02:00
|
|
|
{0, 0, 0, 0, DM_PELSWIDTH, 0},
|
|
|
|
{0, 0, 0, 0, DM_PELSHEIGHT, 0},
|
2007-02-22 12:43:06 +01:00
|
|
|
|
|
|
|
{640, 480, 0, 0, DM_PELSWIDTH, 0},
|
|
|
|
{640, 480, 0, 0, DM_PELSHEIGHT, 0},
|
|
|
|
{ 0, 480, 0, 0, DM_PELSWIDTH | DM_PELSHEIGHT, 0},
|
|
|
|
{640, 0, 0, 0, DM_PELSWIDTH | DM_PELSHEIGHT, 0},
|
|
|
|
|
2008-05-18 11:47:14 +02:00
|
|
|
/* the following test succeeds under XP SP3
|
|
|
|
{0, 0, 0, 0, DM_DISPLAYFREQUENCY, 0}
|
|
|
|
*/
|
2006-07-26 07:31:22 +02:00
|
|
|
};
|
|
|
|
#define vid_modes_cnt (sizeof(vid_modes_test) / sizeof(vid_modes_test[0]))
|
|
|
|
|
|
|
|
static void test_ChangeDisplaySettingsEx(void)
|
|
|
|
{
|
2007-12-20 07:50:30 +01:00
|
|
|
DEVMODEA dm;
|
|
|
|
DEVMODEW dmW;
|
|
|
|
DWORD width;
|
2006-07-26 07:31:22 +02:00
|
|
|
LONG res;
|
|
|
|
int i;
|
|
|
|
|
2007-08-15 14:23:45 +02:00
|
|
|
if (!pChangeDisplaySettingsExA)
|
|
|
|
{
|
2009-02-23 10:41:03 +01:00
|
|
|
win_skip("ChangeDisplaySettingsExA is not available\n");
|
2007-08-15 14:23:45 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-12-20 07:50:30 +01:00
|
|
|
SetLastError(0xdeadbeef);
|
2013-10-23 07:53:58 +02:00
|
|
|
res = EnumDisplaySettingsA(NULL, ENUM_CURRENT_SETTINGS, &dm);
|
2007-12-20 07:50:30 +01:00
|
|
|
ok(res, "EnumDisplaySettings error %u\n", GetLastError());
|
|
|
|
|
|
|
|
width = dm.dmPelsWidth;
|
|
|
|
|
2008-05-18 11:47:14 +02:00
|
|
|
dm.dmDriverExtra = 1;
|
|
|
|
res = ChangeDisplaySettingsA(&dm, CDS_TEST);
|
|
|
|
ok(res == DISP_CHANGE_SUCCESSFUL,
|
|
|
|
"ChangeDisplaySettingsA returned %d, expected DISP_CHANGE_SUCCESSFUL\n", res);
|
2008-11-20 20:06:46 +01:00
|
|
|
ok(dm.dmDriverExtra == 0 || broken(dm.dmDriverExtra == 1) /* win9x */,
|
|
|
|
"ChangeDisplaySettingsA didn't reset dmDriverExtra to 0\n");
|
2008-05-18 11:47:14 +02:00
|
|
|
|
|
|
|
/* crashes under XP SP3 for large dmDriverExtra values */
|
|
|
|
dm.dmDriverExtra = 1;
|
|
|
|
res = pChangeDisplaySettingsExA(NULL, &dm, NULL, CDS_TEST, NULL);
|
|
|
|
ok(res == DISP_CHANGE_SUCCESSFUL,
|
2012-06-04 17:26:24 +02:00
|
|
|
"ChangeDisplaySettingsExW returned %d, expected DISP_CHANGE_SUCCESSFUL\n", res);
|
2008-05-18 11:47:14 +02:00
|
|
|
ok(dm.dmDriverExtra == 1, "ChangeDisplaySettingsExA shouldn't reset dmDriverExtra to 0\n");
|
|
|
|
|
|
|
|
memset(&dmW, 0, sizeof(dmW));
|
|
|
|
dmW.dmSize = sizeof(dmW);
|
|
|
|
dmW.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
|
|
|
|
dmW.dmPelsWidth = dm.dmPelsWidth;
|
|
|
|
dmW.dmPelsHeight = dm.dmPelsHeight;
|
|
|
|
dmW.dmDriverExtra = 1;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
res = ChangeDisplaySettingsW(&dmW, CDS_TEST);
|
|
|
|
if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
|
|
|
|
{
|
|
|
|
ok(res == DISP_CHANGE_SUCCESSFUL,
|
|
|
|
"ChangeDisplaySettingsW returned %d, expected DISP_CHANGE_SUCCESSFUL\n", res);
|
|
|
|
ok(dmW.dmDriverExtra == 0, "ChangeDisplaySettingsW didn't reset dmDriverExtra to 0\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Apparently XP treats dmDriverExtra being != 0 as an error */
|
|
|
|
dmW.dmDriverExtra = 1;
|
|
|
|
res = pChangeDisplaySettingsExW(NULL, &dmW, NULL, CDS_TEST, NULL);
|
|
|
|
if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
|
|
|
|
{
|
|
|
|
ok(res == DISP_CHANGE_SUCCESSFUL,
|
2012-06-04 17:26:24 +02:00
|
|
|
"ChangeDisplaySettingsExW returned %d, expected DISP_CHANGE_SUCCESSFUL\n", res);
|
2008-05-18 11:47:14 +02:00
|
|
|
ok(dmW.dmDriverExtra == 1, "ChangeDisplaySettingsExW shouldn't reset dmDriverExtra to 0\n");
|
|
|
|
}
|
|
|
|
|
2007-12-20 07:50:30 +01:00
|
|
|
/* the following 2 tests show that dm.dmSize being 0 is invalid, but
|
|
|
|
* ChangeDisplaySettingsExA still reports success.
|
|
|
|
*/
|
|
|
|
memset(&dm, 0, sizeof(dm));
|
|
|
|
dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
|
|
|
|
dm.dmPelsWidth = width;
|
|
|
|
res = pChangeDisplaySettingsExA(NULL, &dm, NULL, CDS_TEST, NULL);
|
2008-11-17 14:17:05 +01:00
|
|
|
ok(res == DISP_CHANGE_SUCCESSFUL ||
|
|
|
|
res == DISP_CHANGE_BADMODE || /* Win98, WinMe */
|
|
|
|
res == DISP_CHANGE_FAILED, /* NT4 */
|
|
|
|
"ChangeDisplaySettingsExA returned unexpected %d\n", res);
|
2007-12-20 07:50:30 +01:00
|
|
|
|
|
|
|
memset(&dmW, 0, sizeof(dmW));
|
|
|
|
dmW.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
|
|
|
|
dmW.dmPelsWidth = width;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
res = pChangeDisplaySettingsExW(NULL, &dmW, NULL, CDS_TEST, NULL);
|
|
|
|
if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
|
2008-05-18 11:47:14 +02:00
|
|
|
ok(res == DISP_CHANGE_FAILED ||
|
2008-11-20 20:06:46 +01:00
|
|
|
res == DISP_CHANGE_BADPARAM || /* NT4 */
|
2008-05-18 11:47:14 +02:00
|
|
|
res == DISP_CHANGE_BADMODE /* XP SP3 */,
|
2008-11-20 20:06:46 +01:00
|
|
|
"ChangeDisplaySettingsExW returned %d\n", res);
|
2007-12-20 07:50:30 +01:00
|
|
|
|
2006-07-26 07:31:22 +02:00
|
|
|
memset(&dm, 0, sizeof(dm));
|
|
|
|
dm.dmSize = sizeof(dm);
|
|
|
|
|
|
|
|
for (i = 0; i < vid_modes_cnt; i++)
|
|
|
|
{
|
|
|
|
dm.dmPelsWidth = vid_modes_test[i].w;
|
|
|
|
dm.dmPelsHeight = vid_modes_test[i].h;
|
|
|
|
dm.dmBitsPerPel = vid_modes_test[i].bpp;
|
|
|
|
dm.dmDisplayFrequency = vid_modes_test[i].freq;
|
|
|
|
dm.dmFields = vid_modes_test[i].fields;
|
2008-05-18 11:47:14 +02:00
|
|
|
res = pChangeDisplaySettingsExA(NULL, &dm, NULL, CDS_TEST, NULL);
|
2008-09-17 16:29:32 +02:00
|
|
|
ok(vid_modes_test[i].must_succeed ?
|
2009-01-25 17:28:39 +01:00
|
|
|
(res == DISP_CHANGE_SUCCESSFUL || res == DISP_CHANGE_RESTART) :
|
2009-01-27 14:38:23 +01:00
|
|
|
(res == DISP_CHANGE_SUCCESSFUL || res == DISP_CHANGE_RESTART ||
|
|
|
|
res == DISP_CHANGE_BADMODE || res == DISP_CHANGE_BADPARAM),
|
2007-02-22 12:43:06 +01:00
|
|
|
"Unexpected ChangeDisplaySettingsEx() return code for resolution[%d]: %d\n", i, res);
|
2006-12-14 18:33:51 +01:00
|
|
|
|
|
|
|
if (res == DISP_CHANGE_SUCCESSFUL)
|
|
|
|
{
|
|
|
|
RECT r, r1, virt;
|
|
|
|
|
|
|
|
SetRect(&virt, 0, 0, GetSystemMetrics(SM_CXVIRTUALSCREEN), GetSystemMetrics(SM_CYVIRTUALSCREEN));
|
2008-11-20 20:06:46 +01:00
|
|
|
if (IsRectEmpty(&virt)) /* NT4 doesn't have SM_CX/YVIRTUALSCREEN */
|
|
|
|
SetRect(&virt, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
|
2006-12-14 18:33:51 +01:00
|
|
|
OffsetRect(&virt, GetSystemMetrics(SM_XVIRTUALSCREEN), GetSystemMetrics(SM_YVIRTUALSCREEN));
|
|
|
|
|
|
|
|
/* Resolution change resets clip rect */
|
|
|
|
ok(GetClipCursor(&r), "GetClipCursor() failed\n");
|
|
|
|
ok(EqualRect(&r, &virt), "Invalid clip rect: (%d %d) x (%d %d)\n", r.left, r.top, r.right, r.bottom);
|
|
|
|
|
2009-01-25 17:28:39 +01:00
|
|
|
if (!ClipCursor(NULL)) continue;
|
2006-12-14 18:33:51 +01:00
|
|
|
ok(GetClipCursor(&r), "GetClipCursor() failed\n");
|
|
|
|
ok(EqualRect(&r, &virt), "Invalid clip rect: (%d %d) x (%d %d)\n", r.left, r.top, r.right, r.bottom);
|
|
|
|
|
|
|
|
/* This should always work. Primary monitor is at (0,0) */
|
|
|
|
SetRect(&r1, 10, 10, 20, 20);
|
|
|
|
ok(ClipCursor(&r1), "ClipCursor() failed\n");
|
|
|
|
ok(GetClipCursor(&r), "GetClipCursor() failed\n");
|
|
|
|
ok(EqualRect(&r, &r1), "Invalid clip rect: (%d %d) x (%d %d)\n", r.left, r.top, r.right, r.bottom);
|
2011-06-21 14:50:23 +02:00
|
|
|
SetRect(&r1, 10, 10, 10, 10);
|
|
|
|
ok(ClipCursor(&r1), "ClipCursor() failed\n");
|
|
|
|
ok(GetClipCursor(&r), "GetClipCursor() failed\n");
|
|
|
|
ok(EqualRect(&r, &r1), "Invalid clip rect: (%d %d) x (%d %d)\n", r.left, r.top, r.right, r.bottom);
|
|
|
|
SetRect(&r1, 10, 10, 10, 9);
|
|
|
|
ok(!ClipCursor(&r1), "ClipCursor() succeeded\n");
|
|
|
|
/* Windows bug: further clipping fails once an empty rect is set, so we have to reset it */
|
|
|
|
ClipCursor(NULL);
|
2006-12-14 18:33:51 +01:00
|
|
|
|
|
|
|
SetRect(&r1, virt.left - 10, virt.top - 10, virt.right + 20, virt.bottom + 20);
|
|
|
|
ok(ClipCursor(&r1), "ClipCursor() failed\n");
|
|
|
|
ok(GetClipCursor(&r), "GetClipCursor() failed\n");
|
2008-09-17 16:29:32 +02:00
|
|
|
ok(EqualRect(&r, &virt) ||
|
|
|
|
broken(EqualRect(&r, &r1)) /* win9x */,
|
|
|
|
"Invalid clip rect: (%d %d) x (%d %d)\n", r.left, r.top, r.right, r.bottom);
|
|
|
|
ClipCursor(&virt);
|
2006-12-14 18:33:51 +01:00
|
|
|
}
|
2006-07-26 07:31:22 +02:00
|
|
|
}
|
2007-08-15 14:23:45 +02:00
|
|
|
res = pChangeDisplaySettingsExA(NULL, NULL, NULL, CDS_RESET, NULL);
|
2006-10-07 21:45:11 +02:00
|
|
|
ok(res == DISP_CHANGE_SUCCESSFUL, "Failed to reset default resolution: %d\n", res);
|
2006-07-26 07:31:22 +02:00
|
|
|
}
|
|
|
|
|
2006-10-23 18:03:16 +02:00
|
|
|
static void test_monitors(void)
|
|
|
|
{
|
2014-01-27 22:16:38 +01:00
|
|
|
HMONITOR monitor, primary, nearest;
|
2006-10-23 18:03:16 +02:00
|
|
|
POINT pt;
|
2014-01-27 22:16:38 +01:00
|
|
|
RECT rc;
|
2014-04-18 19:07:55 +02:00
|
|
|
MONITORINFO mi;
|
2014-04-23 17:35:43 +02:00
|
|
|
MONITORINFOEXA miexa;
|
|
|
|
MONITORINFOEXW miexw;
|
2014-04-18 19:07:55 +02:00
|
|
|
BOOL ret;
|
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
DWORD cbSize;
|
|
|
|
BOOL ret;
|
|
|
|
} testdatami[] = {
|
|
|
|
{0, FALSE},
|
|
|
|
{sizeof(MONITORINFO)+1, FALSE},
|
|
|
|
{sizeof(MONITORINFO)-1, FALSE},
|
|
|
|
{sizeof(MONITORINFO), TRUE},
|
|
|
|
{-1, FALSE},
|
|
|
|
{0xdeadbeef, FALSE},
|
|
|
|
},
|
2014-04-23 17:35:43 +02:00
|
|
|
testdatamiexa[] = {
|
2014-04-18 19:07:55 +02:00
|
|
|
{0, FALSE},
|
|
|
|
{sizeof(MONITORINFOEXA)+1, FALSE},
|
|
|
|
{sizeof(MONITORINFOEXA)-1, FALSE},
|
|
|
|
{sizeof(MONITORINFOEXA), TRUE},
|
|
|
|
{-1, FALSE},
|
|
|
|
{0xdeadbeef, FALSE},
|
2014-04-23 17:35:43 +02:00
|
|
|
},
|
|
|
|
testdatamiexw[] = {
|
|
|
|
{0, FALSE},
|
|
|
|
{sizeof(MONITORINFOEXW)+1, FALSE},
|
|
|
|
{sizeof(MONITORINFOEXW)-1, FALSE},
|
|
|
|
{sizeof(MONITORINFOEXW), TRUE},
|
|
|
|
{-1, FALSE},
|
|
|
|
{0xdeadbeef, FALSE},
|
2014-04-18 19:07:55 +02:00
|
|
|
};
|
2006-10-23 18:03:16 +02:00
|
|
|
|
2014-01-27 22:16:38 +01:00
|
|
|
if (!pMonitorFromPoint || !pMonitorFromWindow || !pMonitorFromRect)
|
2008-08-26 13:40:58 +02:00
|
|
|
{
|
2014-01-27 22:16:38 +01:00
|
|
|
win_skip("MonitorFromPoint, MonitorFromWindow, or MonitorFromRect is not available\n");
|
2008-08-26 13:40:58 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-10-23 18:03:16 +02:00
|
|
|
pt.x = pt.y = 0;
|
2006-12-17 13:10:03 +01:00
|
|
|
primary = pMonitorFromPoint( pt, MONITOR_DEFAULTTOPRIMARY );
|
2006-10-23 18:03:16 +02:00
|
|
|
ok( primary != 0, "couldn't get primary monitor\n" );
|
|
|
|
|
2006-12-17 13:10:03 +01:00
|
|
|
monitor = pMonitorFromWindow( 0, MONITOR_DEFAULTTONULL );
|
2006-10-23 18:03:16 +02:00
|
|
|
ok( !monitor, "got %p, should not get a monitor for an invalid window\n", monitor );
|
2006-12-17 13:10:03 +01:00
|
|
|
monitor = pMonitorFromWindow( 0, MONITOR_DEFAULTTOPRIMARY );
|
2006-10-23 18:03:16 +02:00
|
|
|
ok( monitor == primary, "got %p, should get primary %p for MONITOR_DEFAULTTOPRIMARY\n", monitor, primary );
|
2006-12-17 13:10:03 +01:00
|
|
|
monitor = pMonitorFromWindow( 0, MONITOR_DEFAULTTONEAREST );
|
2006-10-23 18:03:16 +02:00
|
|
|
ok( monitor == primary, "got %p, should get primary %p for MONITOR_DEFAULTTONEAREST\n", monitor, primary );
|
2014-01-27 22:16:38 +01:00
|
|
|
|
|
|
|
SetRect( &rc, 0, 0, 1, 1 );
|
|
|
|
monitor = pMonitorFromRect( &rc, MONITOR_DEFAULTTONULL );
|
|
|
|
ok( monitor == primary, "got %p, should get primary %p\n", monitor, primary );
|
|
|
|
|
|
|
|
monitor = pMonitorFromRect( &rc, MONITOR_DEFAULTTOPRIMARY );
|
|
|
|
ok( monitor == primary, "got %p, should get primary %p\n", monitor, primary );
|
|
|
|
|
|
|
|
monitor = pMonitorFromRect( &rc, MONITOR_DEFAULTTONEAREST );
|
|
|
|
ok( monitor == primary, "got %p, should get primary %p\n", monitor, primary );
|
|
|
|
|
|
|
|
/* Empty rect at 0,0 is considered inside the primary monitor */
|
|
|
|
SetRect( &rc, 0, 0, -1, -1 );
|
|
|
|
monitor = pMonitorFromRect( &rc, MONITOR_DEFAULTTONULL );
|
|
|
|
ok( monitor == primary, "got %p, should get primary %p\n", monitor, primary );
|
|
|
|
|
|
|
|
/* Even if there is a monitor left of the primary, the primary will have the most overlapping area */
|
|
|
|
SetRect( &rc, -1, 0, 2, 1 );
|
|
|
|
monitor = pMonitorFromRect( &rc, MONITOR_DEFAULTTONULL );
|
|
|
|
ok( monitor == primary, "got %p, should get primary %p\n", monitor, primary );
|
|
|
|
|
|
|
|
/* But the width of the rect doesn't matter if it's empty. */
|
|
|
|
SetRect( &rc, -1, 0, 2, -1 );
|
|
|
|
monitor = pMonitorFromRect( &rc, MONITOR_DEFAULTTONULL );
|
|
|
|
ok( monitor != primary, "got primary %p\n", monitor );
|
|
|
|
|
|
|
|
if (!pGetMonitorInfoA)
|
|
|
|
{
|
|
|
|
win_skip("GetMonitorInfoA is not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Search for a monitor that has no others equally near to (left, top-1) */
|
|
|
|
SetRect( &rc, -1, -2, 2, 0 );
|
|
|
|
monitor = pMonitorFromRect( &rc, MONITOR_DEFAULTTONULL );
|
|
|
|
nearest = primary;
|
|
|
|
while (monitor != NULL)
|
|
|
|
{
|
|
|
|
ok( monitor != primary, "got primary %p\n", monitor );
|
|
|
|
nearest = monitor;
|
|
|
|
mi.cbSize = sizeof(mi);
|
|
|
|
ret = pGetMonitorInfoA( monitor, &mi );
|
|
|
|
ok( ret, "GetMonitorInfo failed\n" );
|
|
|
|
SetRect( &rc, mi.rcMonitor.left-1, mi.rcMonitor.top-2, mi.rcMonitor.left+2, mi.rcMonitor.top );
|
|
|
|
monitor = pMonitorFromRect( &rc, MONITOR_DEFAULTTONULL );
|
|
|
|
}
|
|
|
|
|
2014-04-18 19:07:55 +02:00
|
|
|
/* tests for cbSize in MONITORINFO */
|
|
|
|
monitor = pMonitorFromWindow( 0, MONITOR_DEFAULTTOPRIMARY );
|
|
|
|
for (i = 0; i < (sizeof(testdatami) / sizeof(testdatami[0])); i++)
|
|
|
|
{
|
|
|
|
memset( &mi, 0, sizeof(mi) );
|
|
|
|
mi.cbSize = testdatami[i].cbSize;
|
|
|
|
ret = pGetMonitorInfoA( monitor, &mi );
|
|
|
|
ok( ret == testdatami[i].ret, "GetMonitorInfo returned wrong value\n" );
|
|
|
|
if (ret)
|
|
|
|
ok( (mi.dwFlags & MONITORINFOF_PRIMARY), "MONITORINFOF_PRIMARY flag isn't set\n" );
|
|
|
|
else
|
|
|
|
ok( !(mi.dwFlags & MONITORINFOF_PRIMARY), "MONITORINFOF_PRIMARY flag is set\n" );
|
2014-04-23 17:35:43 +02:00
|
|
|
|
|
|
|
memset( &miexw, 0, sizeof(miexw) );
|
|
|
|
miexw.cbSize = testdatamiexw[i].cbSize;
|
|
|
|
ret = pGetMonitorInfoW( monitor, (LPMONITORINFO)&miexw );
|
|
|
|
ok( ret == testdatamiexw[i].ret, "GetMonitorInfo returned wrong value\n" );
|
|
|
|
if (ret)
|
|
|
|
ok( (miexw.dwFlags & MONITORINFOF_PRIMARY), "MONITORINFOF_PRIMARY flag isn't set\n" );
|
|
|
|
else
|
|
|
|
ok( !(miexw.dwFlags & MONITORINFOF_PRIMARY), "MONITORINFOF_PRIMARY flag is set\n" );
|
2014-04-18 19:07:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* tests for cbSize in MONITORINFOEXA */
|
2014-04-23 17:35:43 +02:00
|
|
|
for (i = 0; i < (sizeof(testdatamiexa) / sizeof(testdatamiexa[0])); i++)
|
|
|
|
{
|
|
|
|
memset( &miexa, 0, sizeof(miexa) );
|
|
|
|
miexa.cbSize = testdatamiexa[i].cbSize;
|
|
|
|
ret = pGetMonitorInfoA( monitor, (LPMONITORINFO)&miexa );
|
|
|
|
ok( ret == testdatamiexa[i].ret, "GetMonitorInfo returned wrong value\n" );
|
|
|
|
if (ret)
|
|
|
|
ok( (miexa.dwFlags & MONITORINFOF_PRIMARY), "MONITORINFOF_PRIMARY flag isn't set\n" );
|
|
|
|
else
|
|
|
|
ok( !(miexa.dwFlags & MONITORINFOF_PRIMARY), "MONITORINFOF_PRIMARY flag is set\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* tests for cbSize in MONITORINFOEXW */
|
|
|
|
for (i = 0; i < (sizeof(testdatamiexw) / sizeof(testdatamiexw[0])); i++)
|
2014-04-18 19:07:55 +02:00
|
|
|
{
|
2014-04-23 17:35:43 +02:00
|
|
|
memset( &miexw, 0, sizeof(miexw) );
|
|
|
|
miexw.cbSize = testdatamiexw[i].cbSize;
|
|
|
|
ret = pGetMonitorInfoW( monitor, (LPMONITORINFO)&miexw );
|
|
|
|
ok( ret == testdatamiexw[i].ret, "GetMonitorInfo returned wrong value\n" );
|
2014-04-18 19:07:55 +02:00
|
|
|
if (ret)
|
2014-04-23 17:35:43 +02:00
|
|
|
ok( (miexw.dwFlags & MONITORINFOF_PRIMARY), "MONITORINFOF_PRIMARY flag isn't set\n" );
|
2014-04-18 19:07:55 +02:00
|
|
|
else
|
2014-04-23 17:35:43 +02:00
|
|
|
ok( !(miexw.dwFlags & MONITORINFOF_PRIMARY), "MONITORINFOF_PRIMARY flag is set\n" );
|
2014-04-18 19:07:55 +02:00
|
|
|
}
|
|
|
|
|
2014-01-27 22:16:38 +01:00
|
|
|
SetRect( &rc, rc.left+1, rc.top+1, rc.left+2, rc.top+2 );
|
|
|
|
|
|
|
|
monitor = pMonitorFromRect( &rc, MONITOR_DEFAULTTONULL );
|
|
|
|
ok( monitor == NULL, "got %p\n", monitor );
|
|
|
|
|
|
|
|
monitor = pMonitorFromRect( &rc, MONITOR_DEFAULTTOPRIMARY );
|
|
|
|
ok( monitor == primary, "got %p, should get primary %p\n", monitor, primary );
|
|
|
|
|
|
|
|
monitor = pMonitorFromRect( &rc, MONITOR_DEFAULTTONEAREST );
|
|
|
|
ok( monitor == nearest, "got %p, should get nearest %p\n", monitor, nearest );
|
2006-10-23 18:03:16 +02:00
|
|
|
}
|
|
|
|
|
2008-08-26 13:40:58 +02:00
|
|
|
static BOOL CALLBACK find_primary_mon(HMONITOR hmon, HDC hdc, LPRECT rc, LPARAM lp)
|
|
|
|
{
|
|
|
|
MONITORINFO mi;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
mi.cbSize = sizeof(mi);
|
|
|
|
ret = pGetMonitorInfoA(hmon, &mi);
|
|
|
|
ok(ret, "GetMonitorInfo failed\n");
|
|
|
|
if (mi.dwFlags & MONITORINFOF_PRIMARY)
|
|
|
|
{
|
|
|
|
*(HMONITOR *)lp = hmon;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_work_area(void)
|
|
|
|
{
|
|
|
|
HMONITOR hmon;
|
|
|
|
MONITORINFO mi;
|
|
|
|
RECT rc_work, rc_normal;
|
|
|
|
HWND hwnd;
|
|
|
|
WINDOWPLACEMENT wp;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if (!pEnumDisplayMonitors || !pGetMonitorInfoA)
|
|
|
|
{
|
2009-02-23 10:41:03 +01:00
|
|
|
win_skip("EnumDisplayMonitors or GetMonitorInfoA are not available\n");
|
2008-08-26 13:40:58 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hmon = 0;
|
|
|
|
ret = pEnumDisplayMonitors(NULL, NULL, find_primary_mon, (LPARAM)&hmon);
|
|
|
|
ok(!ret && hmon != 0, "Failed to find primary monitor\n");
|
|
|
|
|
|
|
|
mi.cbSize = sizeof(mi);
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pGetMonitorInfoA(hmon, &mi);
|
|
|
|
ok(ret, "GetMonitorInfo error %u\n", GetLastError());
|
|
|
|
ok(mi.dwFlags & MONITORINFOF_PRIMARY, "not a primary monitor\n");
|
|
|
|
trace("primary monitor (%d,%d-%d,%d)\n",
|
|
|
|
mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom);
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2013-10-23 07:53:58 +02:00
|
|
|
ret = SystemParametersInfoA(SPI_GETWORKAREA, 0, &rc_work, 0);
|
2008-08-26 13:40:58 +02:00
|
|
|
ok(ret, "SystemParametersInfo error %u\n", GetLastError());
|
|
|
|
trace("work area (%d,%d-%d,%d)\n", rc_work.left, rc_work.top, rc_work.right, rc_work.bottom);
|
|
|
|
ok(EqualRect(&rc_work, &mi.rcWork), "work area is different\n");
|
|
|
|
|
2013-10-23 07:53:58 +02:00
|
|
|
hwnd = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW|WS_VISIBLE,100,100,10,10,0,0,0,NULL);
|
2008-08-26 13:40:58 +02:00
|
|
|
ok(hwnd != 0, "CreateWindowEx failed\n");
|
|
|
|
|
|
|
|
ret = GetWindowRect(hwnd, &rc_normal);
|
|
|
|
ok(ret, "GetWindowRect failed\n");
|
|
|
|
trace("normal (%d,%d-%d,%d)\n", rc_normal.left, rc_normal.top, rc_normal.right, rc_normal.bottom);
|
|
|
|
|
|
|
|
wp.length = sizeof(wp);
|
|
|
|
ret = GetWindowPlacement(hwnd, &wp);
|
|
|
|
ok(ret, "GetWindowPlacement failed\n");
|
|
|
|
trace("min: %d,%d max %d,%d normal %d,%d-%d,%d\n",
|
|
|
|
wp.ptMinPosition.x, wp.ptMinPosition.y,
|
|
|
|
wp.ptMaxPosition.x, wp.ptMaxPosition.y,
|
|
|
|
wp.rcNormalPosition.left, wp.rcNormalPosition.top,
|
|
|
|
wp.rcNormalPosition.right, wp.rcNormalPosition.bottom);
|
2008-09-11 06:38:21 +02:00
|
|
|
OffsetRect(&wp.rcNormalPosition, rc_work.left, rc_work.top);
|
2016-02-11 03:26:32 +01:00
|
|
|
todo_wine_if (mi.rcMonitor.left != mi.rcWork.left ||
|
2009-01-25 17:28:39 +01:00
|
|
|
mi.rcMonitor.top != mi.rcWork.top) /* FIXME: remove once Wine is fixed */
|
2016-02-11 03:26:32 +01:00
|
|
|
{
|
2008-08-26 13:40:58 +02:00
|
|
|
ok(EqualRect(&rc_normal, &wp.rcNormalPosition), "normal pos is different\n");
|
2016-02-11 03:26:32 +01:00
|
|
|
}
|
2008-08-26 13:40:58 +02:00
|
|
|
|
2013-10-23 07:53:58 +02:00
|
|
|
SetWindowLongA(hwnd, GWL_EXSTYLE, WS_EX_TOOLWINDOW);
|
2008-08-26 13:40:58 +02:00
|
|
|
|
|
|
|
wp.length = sizeof(wp);
|
|
|
|
ret = GetWindowPlacement(hwnd, &wp);
|
|
|
|
ok(ret, "GetWindowPlacement failed\n");
|
|
|
|
trace("min: %d,%d max %d,%d normal %d,%d-%d,%d\n",
|
|
|
|
wp.ptMinPosition.x, wp.ptMinPosition.y,
|
|
|
|
wp.ptMaxPosition.x, wp.ptMaxPosition.y,
|
|
|
|
wp.rcNormalPosition.left, wp.rcNormalPosition.top,
|
|
|
|
wp.rcNormalPosition.right, wp.rcNormalPosition.bottom);
|
|
|
|
ok(EqualRect(&rc_normal, &wp.rcNormalPosition), "normal pos is different\n");
|
|
|
|
|
|
|
|
DestroyWindow(hwnd);
|
|
|
|
}
|
2005-09-28 12:17:13 +02:00
|
|
|
|
2015-10-23 20:40:50 +02:00
|
|
|
static void test_display_config(void)
|
|
|
|
{
|
|
|
|
UINT32 paths, modes;
|
|
|
|
LONG ret;
|
|
|
|
|
|
|
|
if (!pGetDisplayConfigBufferSizes)
|
|
|
|
{
|
|
|
|
win_skip("GetDisplayConfigBufferSizes is not supported\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = pGetDisplayConfigBufferSizes(QDC_ALL_PATHS, NULL, NULL);
|
|
|
|
ok(ret == ERROR_INVALID_PARAMETER, "got %d\n", ret);
|
|
|
|
|
|
|
|
paths = 100;
|
|
|
|
ret = pGetDisplayConfigBufferSizes(QDC_ALL_PATHS, &paths, NULL);
|
|
|
|
ok(ret == ERROR_INVALID_PARAMETER, "got %d\n", ret);
|
|
|
|
ok(paths == 100, "got %u\n", paths);
|
|
|
|
|
|
|
|
modes = 100;
|
|
|
|
ret = pGetDisplayConfigBufferSizes(QDC_ALL_PATHS, NULL, &modes);
|
|
|
|
ok(ret == ERROR_INVALID_PARAMETER, "got %d\n", ret);
|
|
|
|
ok(modes == 100, "got %u\n", modes);
|
|
|
|
|
|
|
|
paths = modes = 0;
|
|
|
|
ret = pGetDisplayConfigBufferSizes(QDC_ALL_PATHS, &paths, &modes);
|
|
|
|
if (!ret)
|
|
|
|
ok(paths > 0 && modes > 0, "got %u, %u\n", paths, modes);
|
|
|
|
else
|
|
|
|
ok(ret == ERROR_NOT_SUPPORTED, "got %d\n", ret);
|
|
|
|
|
|
|
|
/* Invalid flags, non-zero invalid flags validation is version (or driver?) dependent,
|
|
|
|
it's unreliable to use in tests. */
|
|
|
|
ret = pGetDisplayConfigBufferSizes(0, NULL, NULL);
|
|
|
|
ok(ret == ERROR_INVALID_PARAMETER, "got %d\n", ret);
|
|
|
|
|
|
|
|
paths = 100;
|
|
|
|
ret = pGetDisplayConfigBufferSizes(0, &paths, NULL);
|
|
|
|
ok(ret == ERROR_INVALID_PARAMETER, "got %d\n", ret);
|
|
|
|
ok(paths == 100, "got %u\n", paths);
|
|
|
|
|
|
|
|
modes = 100;
|
|
|
|
ret = pGetDisplayConfigBufferSizes(0, NULL, &modes);
|
|
|
|
ok(ret == ERROR_INVALID_PARAMETER, "got %d\n", ret);
|
|
|
|
ok(modes == 100, "got %u\n", modes);
|
|
|
|
|
|
|
|
paths = modes = 100;
|
|
|
|
ret = pGetDisplayConfigBufferSizes(0, &paths, &modes);
|
|
|
|
ok(ret == ERROR_INVALID_PARAMETER || ret == ERROR_NOT_SUPPORTED, "got %d\n", ret);
|
|
|
|
ok(modes == 0 && paths == 0, "got %u, %u\n", modes, paths);
|
|
|
|
}
|
|
|
|
|
2005-09-28 12:17:13 +02:00
|
|
|
START_TEST(monitor)
|
|
|
|
{
|
2005-10-11 22:27:27 +02:00
|
|
|
init_function_pointers();
|
2005-09-28 12:17:13 +02:00
|
|
|
test_enumdisplaydevices();
|
2008-05-18 11:47:14 +02:00
|
|
|
test_ChangeDisplaySettingsEx();
|
2008-08-26 13:40:58 +02:00
|
|
|
test_monitors();
|
|
|
|
test_work_area();
|
2015-10-23 20:40:50 +02:00
|
|
|
test_display_config();
|
2005-09-28 12:17:13 +02:00
|
|
|
}
|