Commit 1d34b3a9 authored by Huw Davies's avatar Huw Davies Committed by Alexandre Julliard

EnumDisplayDevices and GetMonitorInfo should return the same device

name for the primary device. Make both EnumDisplayDevicesA and GetMonitorInfoA call their unicode counterparts. Update prototype of EnumDisplayDevices. Add some tests.
parent 925e4674
......@@ -28,6 +28,7 @@
#include "wingdi.h"
#include "winuser.h"
#include "winnls.h"
#include "winternl.h"
#include "wine/unicode.h"
#include "wine/debug.h"
......@@ -271,41 +272,67 @@ DWORD WINAPI SetLogonNotifyWindow(HWINSTA hwinsta,HWND hwnd)
return 1;
}
static const WCHAR primary_device_name[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
static const WCHAR primary_device_string[] = {'X','1','1',' ','W','i','n','d','o','w','i','n','g',' ',
'S','y','s','t','e','m',0};
/***********************************************************************
* EnumDisplayDevicesA (USER32.@)
*/
BOOL WINAPI EnumDisplayDevicesA( LPVOID unused, DWORD i, LPDISPLAY_DEVICEA lpDisplayDevice,
BOOL WINAPI EnumDisplayDevicesA( LPCSTR lpDevice, DWORD i, LPDISPLAY_DEVICEA lpDispDev,
DWORD dwFlags )
{
if (i)
return FALSE;
FIXME("(%p,%ld,%p,0x%08lx), stub!\n",unused,i,lpDisplayDevice,dwFlags);
strcpy(lpDisplayDevice->DeviceName,"X11");
strcpy(lpDisplayDevice->DeviceString,"X 11 Windowing System");
lpDisplayDevice->StateFlags =
DISPLAY_DEVICE_ATTACHED_TO_DESKTOP |
DISPLAY_DEVICE_PRIMARY_DEVICE |
DISPLAY_DEVICE_VGA_COMPATIBLE;
UNICODE_STRING deviceW;
DISPLAY_DEVICEW ddW;
BOOL ret;
if(lpDevice)
RtlCreateUnicodeStringFromAsciiz(&deviceW, lpDevice);
else
deviceW.Buffer = NULL;
ddW.cb = sizeof(ddW);
ret = EnumDisplayDevicesW(deviceW.Buffer, i, &ddW, dwFlags);
RtlFreeUnicodeString(&deviceW);
if(!ret) return ret;
WideCharToMultiByte(CP_ACP, 0, ddW.DeviceName, -1, lpDispDev->DeviceName, sizeof(lpDispDev->DeviceName), NULL, NULL);
WideCharToMultiByte(CP_ACP, 0, ddW.DeviceString, -1, lpDispDev->DeviceString, sizeof(lpDispDev->DeviceString), NULL, NULL);
lpDispDev->StateFlags = ddW.StateFlags;
if(lpDispDev->cb >= offsetof(DISPLAY_DEVICEA, DeviceID) + sizeof(lpDispDev->DeviceID))
WideCharToMultiByte(CP_ACP, 0, ddW.DeviceID, -1, lpDispDev->DeviceID, sizeof(lpDispDev->DeviceID), NULL, NULL);
if(lpDispDev->cb >= offsetof(DISPLAY_DEVICEA, DeviceKey) + sizeof(lpDispDev->DeviceKey))
WideCharToMultiByte(CP_ACP, 0, ddW.DeviceKey, -1, lpDispDev->DeviceKey, sizeof(lpDispDev->DeviceKey), NULL, NULL);
return TRUE;
}
/***********************************************************************
* EnumDisplayDevicesW (USER32.@)
*/
BOOL WINAPI EnumDisplayDevicesW( LPVOID unused, DWORD i, LPDISPLAY_DEVICEW lpDisplayDevice,
BOOL WINAPI EnumDisplayDevicesW( LPCWSTR lpDevice, DWORD i, LPDISPLAY_DEVICEW lpDisplayDevice,
DWORD dwFlags )
{
FIXME("(%s,%ld,%p,0x%08lx), stub!\n",debugstr_w(lpDevice),i,lpDisplayDevice,dwFlags);
if (i)
return FALSE;
FIXME("(%p,%ld,%p,0x%08lx), stub!\n",unused,i,lpDisplayDevice,dwFlags);
MultiByteToWideChar( CP_ACP, 0, "X11", -1, lpDisplayDevice->DeviceName,
sizeof(lpDisplayDevice->DeviceName)/sizeof(WCHAR) );
MultiByteToWideChar( CP_ACP, 0, "X11 Windowing System", -1, lpDisplayDevice->DeviceString,
sizeof(lpDisplayDevice->DeviceString)/sizeof(WCHAR) );
memcpy(lpDisplayDevice->DeviceName, primary_device_name, sizeof(primary_device_name));
memcpy(lpDisplayDevice->DeviceString, primary_device_string, sizeof(primary_device_string));
lpDisplayDevice->StateFlags =
DISPLAY_DEVICE_ATTACHED_TO_DESKTOP |
DISPLAY_DEVICE_PRIMARY_DEVICE |
DISPLAY_DEVICE_VGA_COMPATIBLE;
if(lpDisplayDevice->cb >= offsetof(DISPLAY_DEVICEW, DeviceID) + sizeof(lpDisplayDevice->DeviceID))
lpDisplayDevice->DeviceID[0] = 0;
if(lpDisplayDevice->cb >= offsetof(DISPLAY_DEVICEW, DeviceKey) + sizeof(lpDisplayDevice->DeviceKey))
lpDisplayDevice->DeviceKey[0] = 0;
return TRUE;
}
......@@ -366,26 +393,21 @@ HMONITOR WINAPI MonitorFromWindow(HWND hWnd, DWORD dwFlags)
*/
BOOL WINAPI GetMonitorInfoA(HMONITOR hMonitor, LPMONITORINFO lpMonitorInfo)
{
RECT rcWork;
MONITORINFOEXW miW;
MONITORINFOEXA *miA = (MONITORINFOEXA*)lpMonitorInfo;
BOOL ret;
if ((hMonitor == xPRIMARY_MONITOR) &&
lpMonitorInfo &&
(lpMonitorInfo->cbSize >= sizeof(MONITORINFO)) &&
SystemParametersInfoA(SPI_GETWORKAREA, 0, &rcWork, 0))
{
SetRect( &lpMonitorInfo->rcMonitor, 0, 0,
GetSystemMetrics(SM_CXSCREEN),
GetSystemMetrics(SM_CYSCREEN) );
lpMonitorInfo->rcWork = rcWork;
lpMonitorInfo->dwFlags = MONITORINFOF_PRIMARY;
miW.cbSize = sizeof(miW);
if (lpMonitorInfo->cbSize >= sizeof(MONITORINFOEXA))
strcpy(((MONITORINFOEXA*)lpMonitorInfo)->szDevice, "DISPLAY");
ret = GetMonitorInfoW(hMonitor, (MONITORINFO*)&miW);
if(!ret) return ret;
return TRUE;
}
return FALSE;
miA->rcMonitor = miW.rcMonitor;
miA->rcWork = miW.rcWork;
miA->dwFlags = miW.dwFlags;
if(miA->cbSize >= offsetof(MONITORINFOEXA, szDevice) + sizeof(miA->szDevice))
WideCharToMultiByte(CP_ACP, 0, miW.szDevice, -1, miA->szDevice, sizeof(miA->szDevice), NULL, NULL);
return ret;
}
/***********************************************************************
......@@ -393,7 +415,6 @@ BOOL WINAPI GetMonitorInfoA(HMONITOR hMonitor, LPMONITORINFO lpMonitorInfo)
*/
BOOL WINAPI GetMonitorInfoW(HMONITOR hMonitor, LPMONITORINFO lpMonitorInfo)
{
static const WCHAR displayW[] = {'D','I','S','P','L','A','Y',0};
RECT rcWork;
if ((hMonitor == xPRIMARY_MONITOR) &&
......@@ -408,7 +429,7 @@ BOOL WINAPI GetMonitorInfoW(HMONITOR hMonitor, LPMONITORINFO lpMonitorInfo)
lpMonitorInfo->dwFlags = MONITORINFOF_PRIMARY;
if (lpMonitorInfo->cbSize >= sizeof(MONITORINFOEXW))
strcpyW(((MONITORINFOEXW*)lpMonitorInfo)->szDevice, displayW);
strcpyW(((MONITORINFOEXW*)lpMonitorInfo)->szDevice, primary_device_name);
return TRUE;
}
......
......@@ -9,6 +9,7 @@ generated.ok
input.ok
listbox.ok
menu.ok
monitor.ok
msg.ok
resource.ok
resource.res
......
......@@ -16,6 +16,7 @@ CTESTS = \
input.c \
listbox.c \
menu.c \
monitor.c \
msg.c \
resource.c \
sysparams.c \
......
/*
* Unit tests for monitor APIs
*
* Copyright 2005 Huw Davies
*
* 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
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "wine/test.h"
#include "winbase.h"
#include "wingdi.h"
#include "winuser.h"
static BOOL CALLBACK monitor_enum_proc(HMONITOR hmon, HDC hdc, LPRECT lprc,
LPARAM lparam)
{
MONITORINFOEXA mi;
char *primary = (char *)lparam;
mi.cbSize = sizeof(mi);
ok(GetMonitorInfoA(hmon, (MONITORINFO*)&mi), "GetMonitorInfo failed\n");
if(mi.dwFlags == MONITORINFOF_PRIMARY)
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;
dd.cb = sizeof(dd);
while(1)
{
BOOL ret;
ret = EnumDisplayDevicesA(NULL, num, &dd, 0), "EnumDisplayDevices fails\n";
ok(ret || num != 0, "EnumDisplayDevices fails with num == 0\n");
if(!ret) break;
if(dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
{
strcpy(primary_device_name, dd.DeviceName);
primary_num = num;
}
num++;
}
ok(primary_num != -1, "Didn't get the primary device\n");
ok(EnumDisplayMonitors(NULL, NULL, monitor_enum_proc, (LPARAM)primary_monitor_device_name),
"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);
}
START_TEST(monitor)
{
test_enumdisplaydevices();
}
......@@ -3895,8 +3895,8 @@ LONG WINAPI ChangeDisplaySettingsExW(LPCWSTR,LPDEVMODEW,HWND,DWORD,LPVOID
HDESK WINAPI CreateDesktopA(LPCSTR,LPCSTR,LPDEVMODEA,DWORD,ACCESS_MASK,LPSECURITY_ATTRIBUTES);
HDESK WINAPI CreateDesktopW(LPCWSTR,LPCWSTR,LPDEVMODEW,DWORD,ACCESS_MASK,LPSECURITY_ATTRIBUTES);
#define CreateDesktop WINELIB_NAME_AW(CreateDesktop)
BOOL WINAPI EnumDisplayDevicesA(LPVOID,DWORD,LPDISPLAY_DEVICEA,DWORD);
BOOL WINAPI EnumDisplayDevicesW(LPVOID,DWORD,LPDISPLAY_DEVICEW,DWORD);
BOOL WINAPI EnumDisplayDevicesA(LPCSTR,DWORD,LPDISPLAY_DEVICEA,DWORD);
BOOL WINAPI EnumDisplayDevicesW(LPCWSTR,DWORD,LPDISPLAY_DEVICEW,DWORD);
#define EnumDisplayDevices WINELIB_NAME_AW(EnumDisplayDevices)
BOOL WINAPI EnumDisplaySettingsA(LPCSTR,DWORD,LPDEVMODEA);
BOOL WINAPI EnumDisplaySettingsW(LPCWSTR,DWORD,LPDEVMODEW);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment