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 ******************************************************************/
33 #include <wine/debug.h>
34 WINE_DEFAULT_DEBUG_CHANNEL(user32
);
36 #define SIZEOF_DEVMODEA_300 124
37 #define SIZEOF_DEVMODEA_400 148
38 #define SIZEOF_DEVMODEA_500 156
39 #define SIZEOF_DEVMODEW_300 188
40 #define SIZEOF_DEVMODEW_400 212
41 #define SIZEOF_DEVMODEW_500 220
43 /* FUNCTIONS *****************************************************************/
52 PDISPLAY_DEVICEA lpDisplayDevice
,
56 UNICODE_STRING Device
;
57 DISPLAY_DEVICEW DisplayDeviceW
;
59 if ( !RtlCreateUnicodeStringFromAsciiz ( &Device
, (PCSZ
)lpDevice
) )
61 SetLastError ( ERROR_OUTOFMEMORY
);
65 RtlZeroMemory(&DisplayDeviceW
, sizeof(DISPLAY_DEVICEW
));
66 DisplayDeviceW
.cb
= sizeof(DISPLAY_DEVICEW
);
67 rc
= NtUserEnumDisplayDevices (
74 /* Copy result from DisplayDeviceW to lpDisplayDevice */
75 lpDisplayDevice
->StateFlags
= DisplayDeviceW
.StateFlags
;
76 WideCharToMultiByte(CP_ACP
,0,
77 DisplayDeviceW
.DeviceName
,wcslen(DisplayDeviceW
.DeviceName
),
78 lpDisplayDevice
->DeviceName
,sizeof(lpDisplayDevice
->DeviceName
) / sizeof(lpDisplayDevice
->DeviceName
[0]),
80 WideCharToMultiByte(CP_ACP
,0,
81 DisplayDeviceW
.DeviceString
,wcslen(DisplayDeviceW
.DeviceString
),
82 lpDisplayDevice
->DeviceString
,sizeof(lpDisplayDevice
->DeviceString
) / sizeof(lpDisplayDevice
->DeviceString
[0]),
84 WideCharToMultiByte(CP_ACP
,0,
85 DisplayDeviceW
.DeviceID
,wcslen(DisplayDeviceW
.DeviceID
),
86 lpDisplayDevice
->DeviceID
,sizeof(lpDisplayDevice
->DeviceID
) / sizeof(lpDisplayDevice
->DeviceID
[0]),
88 WideCharToMultiByte(CP_ACP
,0,
89 DisplayDeviceW
.DeviceKey
,wcslen(DisplayDeviceW
.DeviceKey
),
90 lpDisplayDevice
->DeviceKey
,sizeof(lpDisplayDevice
->DeviceKey
) / sizeof(lpDisplayDevice
->DeviceKey
[0]),
94 RtlFreeUnicodeString ( &Device
);
108 PDISPLAY_DEVICE lpDisplayDevice
,
111 UNICODE_STRING Device
;
114 RtlInitUnicodeString ( &Device
, lpDevice
);
116 rc
= NtUserEnumDisplayDevices (
134 MONITORENUMPROC lpfnEnum
,
138 HMONITOR
*hMonitorList
;
142 /* get list of monitors/rects */
143 iCount
= NtUserEnumDisplayMonitors(hdc
, lprcClip
, NULL
, NULL
, 0);
146 /* FIXME: SetLastError() */
154 hHeap
= GetProcessHeap();
155 hMonitorList
= HeapAlloc(hHeap
, 0, sizeof (HMONITOR
) * iCount
);
156 if (hMonitorList
== NULL
)
158 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
161 pRectList
= HeapAlloc(hHeap
, 0, sizeof (RECT
) * iCount
);
162 if (pRectList
== NULL
)
164 HeapFree(hHeap
, 0, hMonitorList
);
165 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
169 iCount
= NtUserEnumDisplayMonitors(hdc
, lprcClip
, hMonitorList
, pRectList
, iCount
);
172 /* FIXME: SetLastError() */
173 HeapFree(hHeap
, 0, hMonitorList
);
174 HeapFree(hHeap
, 0, pRectList
);
179 for (i
= 0; i
< iCount
; i
++)
181 HMONITOR hMonitor
= hMonitorList
[i
];
182 LPRECT pMonitorRect
= pRectList
+ i
;
183 HDC hMonitorDC
= NULL
;
187 /* make monitor DC */
191 if (!lpfnEnum(hMonitor
, hMonitorDC
, pMonitorRect
, dwData
))
194 HeapFree(hHeap
, 0, hMonitorList
);
195 HeapFree(hHeap
, 0, pRectList
);
205 EnumDisplaySettingsExA(
206 LPCSTR lpszDeviceName
,
208 LPDEVMODEA lpDevMode
,
212 UNICODE_STRING usDeviceName
, *pusDeviceName
= NULL
;
217 if (!RtlCreateUnicodeStringFromAsciiz(&usDeviceName
, (PCSZ
)lpszDeviceName
))
219 SetLastError(ERROR_OUTOFMEMORY
);
222 pusDeviceName
= &usDeviceName
;
225 memset(&DevModeW
,0, sizeof(DEVMODEW
));
226 DevModeW
.dmSize
= sizeof(DEVMODEW
);
228 Status
= NtUserEnumDisplaySettings(pusDeviceName
, iModeNum
, &DevModeW
, dwFlags
);
232 RtlFreeUnicodeString (&usDeviceName
);
235 if (!NT_SUCCESS(Status
))
240 #define COPYS(f,len) WideCharToMultiByte( CP_THREAD_ACP, 0, DevModeW.f, len, (LPSTR)lpDevMode->f, len, NULL, NULL )
241 #define COPYN(f) lpDevMode->f = DevModeW.f
242 COPYS(dmDeviceName
, CCHDEVICENAME
);
243 COPYN(dmSpecVersion
);
244 COPYN(dmDriverVersion
);
245 switch (lpDevMode
->dmSize
)
247 case SIZEOF_DEVMODEA_300
:
248 case SIZEOF_DEVMODEA_400
:
249 case SIZEOF_DEVMODEA_500
:
252 lpDevMode
->dmSize
= SIZEOF_DEVMODEA_300
;
255 COPYN(dmDriverExtra
);
261 COPYN(dmDefaultSource
);
262 COPYN(dmPrintQuality
);
265 COPYN(dmYResolution
);
268 COPYS(dmFormName
,CCHFORMNAME
);
273 COPYN(dmDisplayFlags
); // aka dmNup
274 COPYN(dmDisplayFrequency
);
276 if (lpDevMode
->dmSize
<= SIZEOF_DEVMODEW_300
)
277 return TRUE
; // we're done with 0x300 fields
286 if (lpDevMode
->dmSize
<= SIZEOF_DEVMODEW_400
)
287 return TRUE
; // we're done with 0x400 fields
289 COPYN(dmPanningWidth
);
290 COPYN(dmPanningHeight
);
301 EnumDisplaySettingsA(
302 LPCSTR lpszDeviceName
,
304 LPDEVMODEA lpDevMode
)
306 return EnumDisplaySettingsExA ( lpszDeviceName
, iModeNum
, lpDevMode
, 0 );
315 EnumDisplaySettingsExW(
316 LPCWSTR lpszDeviceName
,
318 LPDEVMODEW lpDevMode
,
322 UNICODE_STRING usDeviceName
, *pusDeviceName
= NULL
;
326 RtlInitUnicodeString(&usDeviceName
, lpszDeviceName
);
327 pusDeviceName
= &usDeviceName
;
330 Status
= NtUserEnumDisplaySettings(pusDeviceName
, iModeNum
, lpDevMode
, dwFlags
);
332 return NT_SUCCESS(Status
);
341 EnumDisplaySettingsW(
342 LPCWSTR lpszDeviceName
,
344 LPDEVMODEW lpDevMode
)
346 return EnumDisplaySettingsExW ( lpszDeviceName
, iModeNum
, lpDevMode
, 0 );
359 if (lpmi
->cbSize
== sizeof (MONITORINFO
))
361 return NtUserGetMonitorInfo(hMonitor
, lpmi
);
363 else if (lpmi
->cbSize
!= sizeof (MONITORINFOEXA
))
365 SetLastError(ERROR_INVALID_PARAMETER
);
370 MONITORINFOEXW miExW
;
373 miExW
.cbSize
= sizeof (MONITORINFOEXW
);
374 if (!NtUserGetMonitorInfo(hMonitor
, (LPMONITORINFO
)&miExW
))
378 memcpy(lpmi
, &miExW
, sizeof (MONITORINFO
));
379 res
= WideCharToMultiByte(CP_THREAD_ACP
, 0, miExW
.szDevice
, -1,
380 ((LPMONITORINFOEXA
)lpmi
)->szDevice
, CCHDEVICENAME
,
384 WARN("WideCharToMultiByte() failed!\n");
402 return NtUserGetMonitorInfo(hMonitor
, lpmi
);
415 return NtUserMonitorFromPoint(ptPoint
, dwFlags
);
428 return NtUserMonitorFromRect(lpcRect
, dwFlags
);
441 return NtUserMonitorFromWindow(hWnd
, dwFlags
);
450 ChangeDisplaySettingsExA(
451 LPCSTR lpszDeviceName
,
452 LPDEVMODEA lpDevMode
,
458 UNICODE_STRING DeviceName
;
459 PUNICODE_STRING pDeviceName
= &DeviceName
;
460 LPDEVMODEW pDevModeW
;
462 if (lpszDeviceName
!= NULL
)
464 if ( !RtlCreateUnicodeStringFromAsciiz ( pDeviceName
, (PCSZ
)lpszDeviceName
) )
466 SetLastError ( ERROR_OUTOFMEMORY
);
467 return DISP_CHANGE_BADPARAM
; /* FIXME what to return? */
473 if (lpDevMode
!= NULL
)
474 pDevModeW
= GdiConvertToDevmodeW(lpDevMode
);
478 rc
= NtUserChangeDisplaySettings ( pDeviceName
, pDevModeW
, hwnd
, dwflags
, lParam
);
480 if (lpszDeviceName
!= NULL
)
481 RtlFreeUnicodeString ( &DeviceName
);
492 ChangeDisplaySettingsA(
493 LPDEVMODEA lpDevMode
,
496 return ChangeDisplaySettingsExA ( NULL
, lpDevMode
, NULL
, dwflags
, 0 );
505 ChangeDisplaySettingsExW(
506 LPCWSTR lpszDeviceName
,
507 LPDEVMODEW lpDevMode
,
513 UNICODE_STRING DeviceName
;
514 PUNICODE_STRING pDeviceName
= &DeviceName
;
516 if (lpszDeviceName
!= NULL
)
517 RtlInitUnicodeString ( pDeviceName
, lpszDeviceName
);
521 rc
= NtUserChangeDisplaySettings ( pDeviceName
, lpDevMode
, hwnd
, dwflags
, lParam
);
532 ChangeDisplaySettingsW(
533 LPDEVMODEW lpDevMode
,
536 return ChangeDisplaySettingsExW ( NULL
, lpDevMode
, NULL
, dwflags
, 0 );