3 * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * PROJECT: ReactOS user32.dll
22 * FILE: lib/user32/misc/dde.c
24 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
26 * 09-05-2001 CSH Created
29 /* INCLUDES ******************************************************************/
35 #define SIZEOF_DEVMODEA_300 124
36 #define SIZEOF_DEVMODEA_400 148
37 #define SIZEOF_DEVMODEA_500 156
38 #define SIZEOF_DEVMODEW_300 188
39 #define SIZEOF_DEVMODEW_400 212
40 #define SIZEOF_DEVMODEW_500 220
42 /* FUNCTIONS *****************************************************************/
51 PDISPLAY_DEVICEA lpDisplayDevice
,
55 UNICODE_STRING Device
;
56 DISPLAY_DEVICEW DisplayDeviceW
;
58 if ( !RtlCreateUnicodeStringFromAsciiz ( &Device
, (PCSZ
)lpDevice
) )
60 SetLastError ( ERROR_OUTOFMEMORY
);
64 DisplayDeviceW
.cb
= sizeof(DISPLAY_DEVICEW
);
65 rc
= NtUserEnumDisplayDevices (
72 /* Copy result from DisplayDeviceW to lpDisplayDevice */
73 lpDisplayDevice
->StateFlags
= DisplayDeviceW
.StateFlags
;
74 WideCharToMultiByte(CP_ACP
,0,
75 DisplayDeviceW
.DeviceName
,wcslen(DisplayDeviceW
.DeviceName
),
76 lpDisplayDevice
->DeviceName
,sizeof(lpDisplayDevice
->DeviceName
) / sizeof(lpDisplayDevice
->DeviceName
[0]),
78 WideCharToMultiByte(CP_ACP
,0,
79 DisplayDeviceW
.DeviceString
,wcslen(DisplayDeviceW
.DeviceString
),
80 lpDisplayDevice
->DeviceString
,sizeof(lpDisplayDevice
->DeviceString
) / sizeof(lpDisplayDevice
->DeviceString
[0]),
82 WideCharToMultiByte(CP_ACP
,0,
83 DisplayDeviceW
.DeviceID
,wcslen(DisplayDeviceW
.DeviceID
),
84 lpDisplayDevice
->DeviceID
,sizeof(lpDisplayDevice
->DeviceID
) / sizeof(lpDisplayDevice
->DeviceID
[0]),
86 WideCharToMultiByte(CP_ACP
,0,
87 DisplayDeviceW
.DeviceKey
,wcslen(DisplayDeviceW
.DeviceKey
),
88 lpDisplayDevice
->DeviceKey
,sizeof(lpDisplayDevice
->DeviceKey
) / sizeof(lpDisplayDevice
->DeviceKey
[0]),
92 RtlFreeUnicodeString ( &Device
);
106 PDISPLAY_DEVICE lpDisplayDevice
,
109 UNICODE_STRING Device
;
112 RtlInitUnicodeString ( &Device
, lpDevice
);
114 rc
= NtUserEnumDisplayDevices (
132 MONITORENUMPROC lpfnEnum
,
136 HMONITOR
*hMonitorList
;
140 /* get list of monitors/rects */
141 iCount
= NtUserEnumDisplayMonitors(hdc
, lprcClip
, NULL
, NULL
, 0);
144 /* FIXME: SetLastError() */
152 hHeap
= GetProcessHeap();
153 hMonitorList
= HeapAlloc(hHeap
, 0, sizeof (HMONITOR
) * iCount
);
154 if (hMonitorList
== NULL
)
156 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
159 pRectList
= HeapAlloc(hHeap
, 0, sizeof (RECT
) * iCount
);
160 if (pRectList
== NULL
)
162 HeapFree(hHeap
, 0, hMonitorList
);
163 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
167 iCount
= NtUserEnumDisplayMonitors(hdc
, lprcClip
, hMonitorList
, pRectList
, iCount
);
170 /* FIXME: SetLastError() */
175 for (i
= 0; i
< iCount
; i
++)
177 HMONITOR hMonitor
= hMonitorList
[i
];
178 LPRECT pMonitorRect
= pRectList
+ i
;
179 HDC hMonitorDC
= NULL
;
183 /* make monitor DC */
187 if (!lpfnEnum(hMonitor
, hMonitorDC
, pMonitorRect
, dwData
))
200 EnumDisplaySettingsExA(
201 LPCSTR lpszDeviceName
,
203 LPDEVMODEA lpDevMode
,
207 UNICODE_STRING DeviceName
;
210 if ( !RtlCreateUnicodeStringFromAsciiz ( &DeviceName
, (PCSZ
)lpszDeviceName
) )
212 SetLastError ( ERROR_OUTOFMEMORY
);
216 memset(&lpDevModeW
,0,sizeof(DEVMODEW
));
217 lpDevModeW
.dmSize
= sizeof(DEVMODEW
);
219 rc
= NtUserEnumDisplaySettings ( &DeviceName
, iModeNum
, &lpDevModeW
,
222 #define COPYS(f,len) WideCharToMultiByte( CP_THREAD_ACP, 0, lpDevModeW.f, len, (LPSTR)lpDevMode->f, len, NULL, NULL )
223 #define COPYN(f) lpDevMode->f = lpDevModeW.f
224 COPYS(dmDeviceName
, CCHDEVICENAME
);
225 COPYN(dmSpecVersion
);
226 COPYN(dmDriverVersion
);
227 switch ( lpDevModeW
.dmSize
)
229 case SIZEOF_DEVMODEW_300
:
230 lpDevMode
->dmSize
= SIZEOF_DEVMODEA_300
;
232 case SIZEOF_DEVMODEW_400
:
233 lpDevMode
->dmSize
= SIZEOF_DEVMODEA_400
;
235 case SIZEOF_DEVMODEW_500
:
236 default: /* FIXME what to do??? */
237 lpDevMode
->dmSize
= SIZEOF_DEVMODEA_500
;
240 COPYN(dmDriverExtra
);
246 COPYN(dmDefaultSource
);
247 COPYN(dmPrintQuality
);
250 COPYN(dmYResolution
);
253 COPYS(dmFormName
,CCHFORMNAME
);
258 COPYN(dmDisplayFlags
); // aka dmNup
259 COPYN(dmDisplayFrequency
);
261 if ( lpDevModeW
.dmSize
<= SIZEOF_DEVMODEW_300
)
262 goto done
; // we're done with 0x300 fields
271 if ( lpDevModeW
.dmSize
<= SIZEOF_DEVMODEW_400
)
272 goto done
; // we're done with 0x400 fields
274 COPYN(dmPanningWidth
);
275 COPYN(dmPanningHeight
);
278 RtlFreeUnicodeString ( &DeviceName
);
290 EnumDisplaySettingsA(
291 LPCSTR lpszDeviceName
,
293 LPDEVMODEA lpDevMode
)
295 return EnumDisplaySettingsExA ( lpszDeviceName
, iModeNum
, lpDevMode
, 0 );
304 EnumDisplaySettingsExW(
305 LPCWSTR lpszDeviceName
,
307 LPDEVMODEW lpDevMode
,
311 UNICODE_STRING DeviceName
;
313 RtlInitUnicodeString ( &DeviceName
, lpszDeviceName
);
315 rc
= NtUserEnumDisplaySettings ( &DeviceName
, iModeNum
, lpDevMode
, dwFlags
);
326 EnumDisplaySettingsW(
327 LPCWSTR lpszDeviceName
,
329 LPDEVMODEW lpDevMode
)
331 return EnumDisplaySettingsExW ( lpszDeviceName
, iModeNum
, lpDevMode
, 0 );
344 if (lpmi
->cbSize
== sizeof (MONITORINFO
))
346 return NtUserGetMonitorInfo(hMonitor
, lpmi
);
348 else if (lpmi
->cbSize
!= sizeof (MONITORINFOEXA
))
350 SetLastError(ERROR_INVALID_PARAMETER
);
355 MONITORINFOEXW miExW
;
358 miExW
.cbSize
= sizeof (MONITORINFOEXW
);
359 if (!NtUserGetMonitorInfo(hMonitor
, (LPMONITORINFO
)&miExW
))
363 memcpy(lpmi
, &miExW
, sizeof (MONITORINFO
));
364 res
= WideCharToMultiByte(CP_THREAD_ACP
, 0, miExW
.szDevice
, -1,
365 ((LPMONITORINFOEXA
)lpmi
)->szDevice
, CCHDEVICENAME
,
369 DPRINT("WideCharToMultiByte() failed!\n");
387 return NtUserGetMonitorInfo(hMonitor
, lpmi
);
400 return NtUserMonitorFromPoint(ptPoint
, dwFlags
);
413 return NtUserMonitorFromRect(lpcRect
, dwFlags
);
426 return NtUserMonitorFromWindow(hWnd
, dwFlags
);
435 ChangeDisplaySettingsExA(
436 LPCSTR lpszDeviceName
,
437 LPDEVMODEA lpDevMode
,
443 UNICODE_STRING DeviceName
;
444 PUNICODE_STRING pDeviceName
= &DeviceName
;
445 LPDEVMODEW pDevModeW
;
447 if (lpszDeviceName
!= NULL
)
449 if ( !RtlCreateUnicodeStringFromAsciiz ( pDeviceName
, (PCSZ
)lpszDeviceName
) )
451 SetLastError ( ERROR_OUTOFMEMORY
);
452 return DISP_CHANGE_BADPARAM
; /* FIXME what to return? */
458 if (lpDevMode
!= NULL
)
459 pDevModeW
= GdiConvertToDevmodeW(lpDevMode
);
463 rc
= NtUserChangeDisplaySettings ( pDeviceName
, pDevModeW
, hwnd
, dwflags
, lParam
);
465 if (lpszDeviceName
!= NULL
)
466 RtlFreeUnicodeString ( &DeviceName
);
477 ChangeDisplaySettingsA(
478 LPDEVMODEA lpDevMode
,
481 return ChangeDisplaySettingsExA ( NULL
, lpDevMode
, NULL
, dwflags
, 0 );
490 ChangeDisplaySettingsExW(
491 LPCWSTR lpszDeviceName
,
492 LPDEVMODEW lpDevMode
,
498 UNICODE_STRING DeviceName
;
499 PUNICODE_STRING pDeviceName
= &DeviceName
;
501 if (lpszDeviceName
!= NULL
)
502 RtlInitUnicodeString ( pDeviceName
, lpszDeviceName
);
506 rc
= NtUserChangeDisplaySettings ( pDeviceName
, lpDevMode
, hwnd
, dwflags
, lParam
);
517 ChangeDisplaySettingsW(
518 LPDEVMODEW lpDevMode
,
521 return ChangeDisplaySettingsExW ( NULL
, lpDevMode
, NULL
, dwflags
, 0 );