- Obtain border size of windows from registry if available.
[wine] / dlls / user / sysparams.c
1 /*
2  * System parameters functions
3  *
4  * Copyright 1994 Alexandre Julliard
5  *
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.
10  *
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.
15  *
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "config.h"
22
23 #include <assert.h>
24 #include <stdarg.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winnls.h"
31 #include "wingdi.h"
32 #include "winreg.h"
33 #include "wine/winuser16.h"
34 #include "winerror.h"
35
36 #include "controls.h"
37 #include "user_private.h"
38 #include "wine/unicode.h"
39 #include "wine/debug.h"
40
41 WINE_DEFAULT_DEBUG_CHANNEL(system);
42
43 /* System parameter indexes */
44 #define SPI_SETBEEP_IDX                         0
45 #define SPI_SETMOUSE_IDX                        1
46 #define SPI_SETBORDER_IDX                       2
47 #define SPI_SETKEYBOARDSPEED_IDX                3
48 #define SPI_ICONHORIZONTALSPACING_IDX           4
49 #define SPI_SETSCREENSAVETIMEOUT_IDX            5
50 #define SPI_SETGRIDGRANULARITY_IDX              6
51 #define SPI_SETKEYBOARDDELAY_IDX                7
52 #define SPI_ICONVERTICALSPACING_IDX             8
53 #define SPI_SETICONTITLEWRAP_IDX                9
54 #define SPI_SETMENUDROPALIGNMENT_IDX            10
55 #define SPI_SETDOUBLECLKWIDTH_IDX               11
56 #define SPI_SETDOUBLECLKHEIGHT_IDX              12
57 #define SPI_SETDOUBLECLICKTIME_IDX              13
58 #define SPI_SETMOUSEBUTTONSWAP_IDX              14
59 #define SPI_SETDRAGFULLWINDOWS_IDX              15
60 #define SPI_SETWORKAREA_IDX                     16
61 #define SPI_SETSHOWSOUNDS_IDX                   17
62 #define SPI_SETKEYBOARDPREF_IDX                 18
63 #define SPI_SETSCREENREADER_IDX                 19
64 #define SPI_SETSCREENSAVERRUNNING_IDX           20
65 #define SPI_SETFONTSMOOTHING_IDX                21
66 #define SPI_SETKEYBOARDCUES_IDX                 22
67 #define SPI_SETGRADIENTCAPTIONS_IDX             23
68 #define SPI_SETHOTTRACKING_IDX                  24
69 #define SPI_SETLISTBOXSMOOTHSCROLLING_IDX       25
70 #define SPI_SETMOUSEHOVERWIDTH_IDX              26
71 #define SPI_SETMOUSEHOVERHEIGHT_IDX             27
72 #define SPI_SETMOUSEHOVERTIME_IDX               28
73 #define SPI_SETMOUSESCROLLLINES_IDX             29
74 #define SPI_SETMENUSHOWDELAY_IDX                30
75
76 #define SPI_WINE_IDX                            SPI_SETMENUSHOWDELAY_IDX
77
78 /**
79  * Names of the registry subkeys of HKEY_CURRENT_USER key and value names
80  * for the system parameters.
81  * Names of the keys are created by adding string "_REGKEY" to
82  * "SET" action names, value names are created by adding "_REG_NAME"
83  * to the "SET" action name.
84  */
85 static const WCHAR SPI_SETBEEP_REGKEY[]=                      {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','S','o','u','n','d',0};
86 static const WCHAR SPI_SETBEEP_VALNAME[]=                     {'B','e','e','p',0};
87 static const WCHAR SPI_SETMOUSE_REGKEY[]=                     {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','M','o','u','s','e',0};
88 static const WCHAR SPI_SETMOUSE_VALNAME1[]=                   {'M','o','u','s','e','T','h','r','e','s','h','o','l','d','1',0};
89 static const WCHAR SPI_SETMOUSE_VALNAME2[]=                   {'M','o','u','s','e','T','h','r','e','s','h','o','l','d','2',0};
90 static const WCHAR SPI_SETMOUSE_VALNAME3[]=                   {'M','o','u','s','e','S','p','e','e','d',0};
91 static const WCHAR SPI_SETBORDER_REGKEY[]=                    {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
92 static const WCHAR SPI_SETBORDER_VALNAME[]=                   {'B','o','r','d','e','r','W','i','d','t','h',0};
93 static const WCHAR SPI_SETKEYBOARDSPEED_REGKEY[]=             {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','K','e','y','b','o','a','r','d',0};
94 static const WCHAR SPI_SETKEYBOARDSPEED_VALNAME[]=            {'K','e','y','b','o','a','r','d','S','p','e','e','d',0};
95 static const WCHAR SPI_ICONHORIZONTALSPACING_REGKEY[]=        {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p','\\',
96                                                                'W','i','n','d','o','w','M','e','t','r','i','c','s',0};
97 static const WCHAR SPI_ICONHORIZONTALSPACING_VALNAME[]=       {'I','c','o','n','S','p','a','c','i','n','g',0};
98 static const WCHAR SPI_SETSCREENSAVETIMEOUT_REGKEY[]=         {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
99 static const WCHAR SPI_SETSCREENSAVETIMEOUT_VALNAME[]=        {'S','c','r','e','e','n','S','a','v','e','T','i','m','e','O','u','t',0};
100 static const WCHAR SPI_SETSCREENSAVEACTIVE_REGKEY[]=          {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
101 static const WCHAR SPI_SETSCREENSAVEACTIVE_VALNAME[]=         {'S','c','r','e','e','n','S','a','v','e','A','c','t','i','v','e',0};
102 static const WCHAR SPI_SETGRIDGRANULARITY_REGKEY[]=           {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
103 static const WCHAR SPI_SETGRIDGRANULARITY_VALNAME[]=          {'G','r','i','d','G','r','a','n','u','l','a','r','i','t','y',0};
104 static const WCHAR SPI_SETKEYBOARDDELAY_REGKEY[]=             {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','K','e','y','b','o','a','r','d',0};
105 static const WCHAR SPI_SETKEYBOARDDELAY_VALNAME[]=            {'K','e','y','b','o','a','r','d','D','e','l','a','y',0};
106 static const WCHAR SPI_ICONVERTICALSPACING_REGKEY[]=          {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p','\\',
107                                                                'W','i','n','d','o','w','M','e','t','r','i','c','s',0};
108 static const WCHAR SPI_ICONVERTICALSPACING_VALNAME[]=         {'I','c','o','n','V','e','r','t','i','c','a','l','S','p','a','c','i','n','g',0};
109 static const WCHAR SPI_SETICONTITLEWRAP_REGKEY1[]=            {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p','\\',
110                                                                'W','i','n','d','o','w','M','e','t','r','i','c','s',0};
111 static const WCHAR SPI_SETICONTITLEWRAP_REGKEY2[]=            {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
112 static const WCHAR SPI_SETICONTITLEWRAP_VALNAME[]=            {'I','c','o','n','T','i','t','l','e','W','r','a','p',0};
113 static const WCHAR SPI_SETMENUDROPALIGNMENT_REGKEY1[]=        {'S','o','f','t','w','a','r','e','\\',
114                                                                'M','i','c','r','o','s','o','f','t','\\',
115                                                                'W','i','n','d','o','w','s',' ','N','T','\\',
116                                                                'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
117                                                                'W','i','n','d','o','w','s',0};
118 static const WCHAR SPI_SETMENUDROPALIGNMENT_REGKEY2[]=        {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
119 static const WCHAR SPI_SETMENUDROPALIGNMENT_VALNAME[]=        {'M','e','n','u','D','r','o','p','A','l','i','g','n','m','e','n','t',0};
120 static const WCHAR SPI_SETDOUBLECLKWIDTH_REGKEY1[]=           {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','M','o','u','s','e',0};
121 static const WCHAR SPI_SETDOUBLECLKWIDTH_REGKEY2[]=           {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
122 static const WCHAR SPI_SETDOUBLECLKWIDTH_VALNAME[]=           {'D','o','u','b','l','e','C','l','i','c','k','W','i','d','t','h',0};
123 static const WCHAR SPI_SETDOUBLECLKHEIGHT_REGKEY1[]=          {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','M','o','u','s','e',0};
124 static const WCHAR SPI_SETDOUBLECLKHEIGHT_REGKEY2[]=          {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
125 static const WCHAR SPI_SETDOUBLECLKHEIGHT_VALNAME[]=          {'D','o','u','b','l','e','C','l','i','c','k','H','e','i','g','h','t',0};
126 static const WCHAR SPI_SETDOUBLECLICKTIME_REGKEY[]=           {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','M','o','u','s','e',0};
127 static const WCHAR SPI_SETDOUBLECLICKTIME_VALNAME[]=          {'D','o','u','b','l','e','C','l','i','c','k','S','p','e','e','d',0};
128 static const WCHAR SPI_SETMOUSEBUTTONSWAP_REGKEY[]=           {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','M','o','u','s','e',0};
129 static const WCHAR SPI_SETMOUSEBUTTONSWAP_VALNAME[]=          {'S','w','a','p','M','o','u','s','e','B','u','t','t','o','n','s',0};
130 static const WCHAR SPI_SETDRAGFULLWINDOWS_REGKEY[]=           {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
131 static const WCHAR SPI_SETDRAGFULLWINDOWS_VALNAME[]=          {'D','r','a','g','F','u','l','l','W','i','n','d','o','w','s',0};
132 static const WCHAR SPI_SETWORKAREA_REGKEY[]=                  {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
133 static const WCHAR SPI_SETWORKAREA_VALNAME[]=                 {'W','I','N','E','_','W','o','r','k','A','r','e','a',0};
134 static const WCHAR SPI_SETSHOWSOUNDS_REGKEY[]=                {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\',
135                                                                'A','c','c','e','s','s','i','b','i','l','i','t','y','\\',
136                                                                'S','h','o','w','S','o','u','n','d','s',0};
137 static const WCHAR SPI_SETSHOWSOUNDS_VALNAME[]=               {'O','n',0};
138 static const WCHAR SPI_SETDESKWALLPAPER_REGKEY[]=             {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
139 static const WCHAR SPI_SETDESKWALLPAPER_VALNAME[]=            {'W','a','l','l','p','a','p','e','r',0};
140 static const WCHAR SPI_SETFONTSMOOTHING_REGKEY[]=             {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
141 static const WCHAR SPI_SETFONTSMOOTHING_VALNAME[]=            {'F','o','n','t','S','m','o','o','t','h','i','n','g',0};
142 static const WCHAR SPI_GETLOPOWERACTIVE_REGKEY[]=             {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
143 static const WCHAR SPI_GETLOPOWERACTIVE_VALNAME[]=            {'L','o','w','P','o','w','e','r','A','c','t','i','v','e',0};
144 static const WCHAR SPI_USERPREFERENCEMASK_REGKEY[]=           {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
145 static const WCHAR SPI_USERPREFERENCEMASK_VALNAME[]=          {'U','s','e','r','P','r','e','f','e','r','e','n','c','e','m','a','s','k',0};
146 static const WCHAR SPI_SETLISTBOXSMOOTHSCROLLING_REGKEY[]=    {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
147 static const WCHAR SPI_SETLISTBOXSMOOTHSCROLLING_VALNAME[]=   {'S','m','o','o','t','h','S','c','r','o','l','l',0};
148 static const WCHAR SPI_SETMOUSEHOVERWIDTH_REGKEY[]=           {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','M','o','u','s','e',0};
149 static const WCHAR SPI_SETMOUSEHOVERWIDTH_VALNAME[]=          {'M','o','u','s','e','H','o','v','e','r','W','i','d','t','h',0};
150 static const WCHAR SPI_SETMOUSEHOVERHEIGHT_REGKEY[]=          {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','M','o','u','s','e',0};
151 static const WCHAR SPI_SETMOUSEHOVERHEIGHT_VALNAME[]=         {'M','o','u','s','e','H','o','v','e','r','H','e','i','g','h','t',0};
152 static const WCHAR SPI_SETMOUSEHOVERTIME_REGKEY[]=            {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','M','o','u','s','e',0};
153 static const WCHAR SPI_SETMOUSEHOVERTIME_VALNAME[]=           {'M','o','u','s','e','H','o','v','e','r','T','i','m','e',0};
154 static const WCHAR SPI_SETMOUSESCROLLLINES_REGKEY[]=          {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
155 static const WCHAR SPI_SETMOUSESCROLLLINES_VALNAME[]=         {'W','h','e','e','l','S','c','r','o','l','l','L','i','n','e','s',0};
156 static const WCHAR SPI_SETMENUSHOWDELAY_REGKEY[]=             {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
157 static const WCHAR SPI_SETMENUSHOWDELAY_VALNAME[]=            {'M','e','n','u','S','h','o','w','D','e','l','a','y',0};
158
159 /* FIXME - real values */
160 static const WCHAR SPI_SETKEYBOARDPREF_REGKEY[]=         {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
161 static const WCHAR SPI_SETKEYBOARDPREF_VALNAME[]=        {'W','I','N','E','_','K','e','y','b','o','a','r','d','P','r','e','f',0};
162 static const WCHAR SPI_SETSCREENREADER_REGKEY[]=         {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
163 static const WCHAR SPI_SETSCREENREADER_VALNAME[]=        {'W','I','N','E','_','S','c','r','e','e','n','R','e','a','d','e','r',0};
164 static const WCHAR SPI_SETSCREENSAVERRUNNING_REGKEY[]=   {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
165 static const WCHAR SPI_SETSCREENSAVERRUNNING_VALNAME[]=  {'W','I','N','E','_','S','c','r','e','e','n','S','a','v','e','r','R','u','n','n','i','n','g',0};
166
167 static const WCHAR METRICS_REGKEY[]=                  {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p','\\',
168                                                        'W','i','n','d','o','w','M','e','t','r','i','c','s',0};
169 static const WCHAR METRICS_SCROLLWIDTH_VALNAME[]=     {'S','c','r','o','l','l','W','i','d','t','h',0};
170 static const WCHAR METRICS_SCROLLHEIGHT_VALNAME[]=    {'S','c','r','o','l','l','H','e','i','g','h','t',0};
171 static const WCHAR METRICS_CAPTIONWIDTH_VALNAME[]=    {'C','a','p','t','i','o','n','W','i','d','t','h',0};
172 static const WCHAR METRICS_CAPTIONHEIGHT_VALNAME[]=   {'C','a','p','t','i','o','n','H','e','i','g','h','t',0};
173 static const WCHAR METRICS_SMCAPTIONWIDTH_VALNAME[]=  {'S','m','C','a','p','t','i','o','n','W','i','d','t','h',0};
174 static const WCHAR METRICS_SMCAPTIONHEIGHT_VALNAME[]= {'S','m','C','a','p','t','i','o','n','H','e','i','g','h','t',0};
175 static const WCHAR METRICS_MENUWIDTH_VALNAME[]=       {'M','e','n','u','W','i','d','t','h',0};
176 static const WCHAR METRICS_MENUHEIGHT_VALNAME[]=      {'M','e','n','u','H','e','i','g','h','t',0};
177 static const WCHAR METRICS_ICONSIZE_VALNAME[]=        {'S','h','e','l','l',' ','I','c','o','n',' ','S','i','z','e',0};
178 static const WCHAR METRICS_BORDERWIDTH_VALNAME[]=     {'B','o','r','d','e','r','W','i','d','t','h',0};
179
180 /* volatile registry branch under CURRENT_USER_REGKEY for temporary values storage */
181 static const WCHAR WINE_CURRENT_USER_REGKEY[] = {'W','i','n','e',0};
182
183
184 static const WCHAR Yes[]=                                    {'Y','e','s',0};
185 static const WCHAR No[]=                                     {'N','o',0};
186 static const WCHAR Desktop[]=                                {'D','e','s','k','t','o','p',0};
187 static const WCHAR Pattern[]=                                {'P','a','t','t','e','r','n',0};
188 static const WCHAR MenuFont[]=                               {'M','e','n','u','F','o','n','t',0};
189 static const WCHAR MenuFontSize[]=                           {'M','e','n','u','F','o','n','t','S','i','z','e',0};
190 static const WCHAR StatusFont[]=                             {'S','t','a','t','u','s','F','o','n','t',0};
191 static const WCHAR StatusFontSize[]=                         {'S','t','a','t','u','s','F','o','n','t','S','i','z','e',0};
192 static const WCHAR MessageFont[]=                            {'M','e','s','s','a','g','e','F','o','n','t',0};
193 static const WCHAR MessageFontSize[]=                        {'M','e','s','s','a','g','e','F','o','n','t','S','i','z','e',0};
194 static const WCHAR System[]=                                 {'S','y','s','t','e','m',0};
195 static const WCHAR IconTitleSize[]=                          {'I','c','o','n','T','i','t','l','e','S','i','z','e',0};
196 static const WCHAR IconTitleFaceName[]=                      {'I','c','o','n','T','i','t','l','e','F','a','c','e','N','a','m','e',0};
197 static const WCHAR defPattern[]=                             {'1','7','0',' ','8','5',' ','1','7','0',' ','8','5',' ','1','7','0',' ','8','5',
198                                                               ' ','1','7','0',' ','8','5',0};
199 static const WCHAR CSu[]=                                    {'%','u',0};
200 static const WCHAR CSd[]=                                    {'%','d',0};
201 static const WCHAR DISPLAY[]=                                {'D','I','S','P','L','A','Y',0};
202
203 /* Indicators whether system parameter value is loaded */
204 static char spi_loaded[SPI_WINE_IDX + 1];
205
206 static BOOL notify_change = TRUE;
207
208 /* System parameters storage */
209 static int sysMetrics[SM_CMETRICS+1];
210 static HDC display_dc;
211 static BOOL beep_active = TRUE;
212 static int mouse_threshold1 = 6;
213 static int mouse_threshold2 = 10;
214 static int mouse_speed = 1;
215 static int border = 1;
216 static int keyboard_speed = 31;
217 static int screensave_timeout = 300;
218 static int grid_granularity = 0;
219 static int keyboard_delay = 1;
220 static BOOL icon_title_wrap = TRUE;
221 static int double_click_time = 500;
222 static BOOL drag_full_windows = FALSE;
223 static RECT work_area;
224 static BOOL keyboard_pref = TRUE;
225 static BOOL screen_reader = FALSE;
226 static int mouse_hover_width = 4;
227 static int mouse_hover_height = 4;
228 static int mouse_hover_time = 400;
229 static int mouse_scroll_lines = 3;
230 static int menu_show_delay = 400;
231 static BOOL screensaver_running = FALSE;
232 static BOOL font_smoothing = FALSE;
233 static BOOL lowpoweractive = FALSE;
234 static BOOL keyboard_cues = FALSE;
235 static BOOL gradient_captions = FALSE;
236 static BOOL listbox_smoothscrolling = FALSE;
237 static BOOL hot_tracking = FALSE;
238
239 /***********************************************************************
240  *              GetTimerResolution (USER.14)
241  */
242 LONG WINAPI GetTimerResolution16(void)
243 {
244         return (1000);
245 }
246
247 /***********************************************************************
248  *              ControlPanelInfo (USER.273)
249  */
250 void WINAPI ControlPanelInfo16( INT16 nInfoType, WORD wData, LPSTR lpBuffer )
251 {
252         FIXME("(%d, %04x, %p): stub.\n", nInfoType, wData, lpBuffer);
253 }
254
255 /* This function is a copy of the one in objects/font.c */
256 static void SYSPARAMS_LogFont32ATo16( const LOGFONTA* font32, LPLOGFONT16 font16 )
257 {
258     font16->lfHeight = font32->lfHeight;
259     font16->lfWidth = font32->lfWidth;
260     font16->lfEscapement = font32->lfEscapement;
261     font16->lfOrientation = font32->lfOrientation;
262     font16->lfWeight = font32->lfWeight;
263     font16->lfItalic = font32->lfItalic;
264     font16->lfUnderline = font32->lfUnderline;
265     font16->lfStrikeOut = font32->lfStrikeOut;
266     font16->lfCharSet = font32->lfCharSet;
267     font16->lfOutPrecision = font32->lfOutPrecision;
268     font16->lfClipPrecision = font32->lfClipPrecision;
269     font16->lfQuality = font32->lfQuality;
270     font16->lfPitchAndFamily = font32->lfPitchAndFamily;
271     lstrcpynA( font16->lfFaceName, font32->lfFaceName, LF_FACESIZE );
272 }
273
274 static void SYSPARAMS_LogFont32WTo32A( const LOGFONTW* font32W, LPLOGFONTA font32A )
275 {
276     font32A->lfHeight = font32W->lfHeight;
277     font32A->lfWidth = font32W->lfWidth;
278     font32A->lfEscapement = font32W->lfEscapement;
279     font32A->lfOrientation = font32W->lfOrientation;
280     font32A->lfWeight = font32W->lfWeight;
281     font32A->lfItalic = font32W->lfItalic;
282     font32A->lfUnderline = font32W->lfUnderline;
283     font32A->lfStrikeOut = font32W->lfStrikeOut;
284     font32A->lfCharSet = font32W->lfCharSet;
285     font32A->lfOutPrecision = font32W->lfOutPrecision;
286     font32A->lfClipPrecision = font32W->lfClipPrecision;
287     font32A->lfQuality = font32W->lfQuality;
288     font32A->lfPitchAndFamily = font32W->lfPitchAndFamily;
289     WideCharToMultiByte( CP_ACP, 0, font32W->lfFaceName, -1, font32A->lfFaceName, LF_FACESIZE, NULL, NULL );
290     font32A->lfFaceName[LF_FACESIZE-1] = 0;
291 }
292
293 static void SYSPARAMS_NonClientMetrics32ATo16( const NONCLIENTMETRICSA* lpnm32, LPNONCLIENTMETRICS16 lpnm16 )
294 {
295     lpnm16->iBorderWidth        = lpnm32->iBorderWidth;
296     lpnm16->iScrollWidth        = lpnm32->iScrollWidth;
297     lpnm16->iScrollHeight       = lpnm32->iScrollHeight;
298     lpnm16->iCaptionWidth       = lpnm32->iCaptionWidth;
299     lpnm16->iCaptionHeight      = lpnm32->iCaptionHeight;
300     SYSPARAMS_LogFont32ATo16( &lpnm32->lfCaptionFont,   &lpnm16->lfCaptionFont );
301     lpnm16->iSmCaptionWidth     = lpnm32->iSmCaptionWidth;
302     lpnm16->iSmCaptionHeight    = lpnm32->iSmCaptionHeight;
303     SYSPARAMS_LogFont32ATo16( &lpnm32->lfSmCaptionFont, &lpnm16->lfSmCaptionFont );
304     lpnm16->iMenuWidth          = lpnm32->iMenuWidth;
305     lpnm16->iMenuHeight         = lpnm32->iMenuHeight;
306     SYSPARAMS_LogFont32ATo16( &lpnm32->lfMenuFont,      &lpnm16->lfMenuFont );
307     SYSPARAMS_LogFont32ATo16( &lpnm32->lfStatusFont,    &lpnm16->lfStatusFont );
308     SYSPARAMS_LogFont32ATo16( &lpnm32->lfMessageFont,   &lpnm16->lfMessageFont );
309 }
310
311 static void SYSPARAMS_NonClientMetrics32WTo32A( const NONCLIENTMETRICSW* lpnm32W, LPNONCLIENTMETRICSA lpnm32A )
312 {
313     lpnm32A->iBorderWidth       = lpnm32W->iBorderWidth;
314     lpnm32A->iScrollWidth       = lpnm32W->iScrollWidth;
315     lpnm32A->iScrollHeight      = lpnm32W->iScrollHeight;
316     lpnm32A->iCaptionWidth      = lpnm32W->iCaptionWidth;
317     lpnm32A->iCaptionHeight     = lpnm32W->iCaptionHeight;
318     SYSPARAMS_LogFont32WTo32A(  &lpnm32W->lfCaptionFont,        &lpnm32A->lfCaptionFont );
319     lpnm32A->iSmCaptionWidth    = lpnm32W->iSmCaptionWidth;
320     lpnm32A->iSmCaptionHeight   = lpnm32W->iSmCaptionHeight;
321     SYSPARAMS_LogFont32WTo32A( &lpnm32W->lfSmCaptionFont,       &lpnm32A->lfSmCaptionFont );
322     lpnm32A->iMenuWidth         = lpnm32W->iMenuWidth;
323     lpnm32A->iMenuHeight        = lpnm32W->iMenuHeight;
324     SYSPARAMS_LogFont32WTo32A( &lpnm32W->lfMenuFont,            &lpnm32A->lfMenuFont );
325     SYSPARAMS_LogFont32WTo32A( &lpnm32W->lfStatusFont,          &lpnm32A->lfStatusFont );
326     SYSPARAMS_LogFont32WTo32A( &lpnm32W->lfMessageFont,         &lpnm32A->lfMessageFont );
327 }
328
329 /***********************************************************************
330  *           SYSPARAMS_Reset
331  *
332  * Sets the system parameter which should be always loaded to
333  * current value stored in registry.
334  * Invalidates lazy loaded parameter, so it will be loaded the next time
335  * it is requested.
336  *
337  * Parameters:
338  * uiAction - system parameter to reload value for.
339  *      Note, only "SET" values can be used for this parameter.
340  *      If uiAction is 0 all system parameters are reset.
341  */
342 void SYSPARAMS_Reset( UINT uiAction )
343 {
344 #define WINE_RELOAD_SPI(x) \
345     case x: \
346         spi_loaded[x##_IDX] = FALSE; \
347         SystemParametersInfoA( x, 0, dummy_buf, 0 );\
348         if (uiAction) \
349             break
350
351 #define WINE_IGNORE_SPI(x) \
352     case x: \
353         if (uiAction) \
354             break
355
356 #define WINE_INVALIDATE_SPI(x) \
357     case x: \
358         spi_loaded[x##_IDX] = FALSE; \
359         break
360
361     BOOL not_all_processed = TRUE;
362     char dummy_buf[10];
363
364     /* Execution falls through all the branches for uiAction == 0 */
365     switch (uiAction)
366     {
367     case 0:
368         memset( spi_loaded, 0, sizeof(spi_loaded) );
369
370     WINE_RELOAD_SPI(SPI_SETBORDER);
371     WINE_RELOAD_SPI(SPI_ICONHORIZONTALSPACING);
372     WINE_RELOAD_SPI(SPI_ICONVERTICALSPACING);
373     WINE_IGNORE_SPI(SPI_SETSCREENSAVEACTIVE);
374     WINE_RELOAD_SPI(SPI_SETDOUBLECLKWIDTH);
375     WINE_RELOAD_SPI(SPI_SETDOUBLECLKHEIGHT);
376     WINE_RELOAD_SPI(SPI_SETMOUSEBUTTONSWAP);
377     WINE_RELOAD_SPI(SPI_SETSHOWSOUNDS);
378     WINE_RELOAD_SPI(SPI_SETMENUDROPALIGNMENT);
379
380     default:
381         if (uiAction)
382         {
383             /* lazy loaded parameters */
384             switch (uiAction)
385             {
386             WINE_INVALIDATE_SPI(SPI_SETBEEP);
387             WINE_INVALIDATE_SPI(SPI_SETMOUSE);
388             WINE_INVALIDATE_SPI(SPI_SETKEYBOARDSPEED);
389             WINE_INVALIDATE_SPI(SPI_SETSCREENSAVETIMEOUT);
390             WINE_INVALIDATE_SPI(SPI_SETGRIDGRANULARITY);
391             WINE_INVALIDATE_SPI(SPI_SETKEYBOARDDELAY);
392             WINE_INVALIDATE_SPI(SPI_SETICONTITLEWRAP);
393             WINE_INVALIDATE_SPI(SPI_SETDOUBLECLICKTIME);
394             WINE_INVALIDATE_SPI(SPI_SETDRAGFULLWINDOWS);
395             WINE_INVALIDATE_SPI(SPI_SETWORKAREA);
396             WINE_INVALIDATE_SPI(SPI_SETKEYBOARDPREF);
397             WINE_INVALIDATE_SPI(SPI_SETSCREENREADER);
398             WINE_INVALIDATE_SPI(SPI_SETSCREENSAVERRUNNING);
399             default:
400                 FIXME( "Unknown action reset: %u\n", uiAction );
401                 break;
402             }
403         }
404         else
405             not_all_processed = FALSE;
406         break;
407     }
408
409     if (!uiAction && not_all_processed)
410         ERR( "Incorrect implementation of SYSPARAMS_Reset. "
411              "Not all params are reloaded.\n" );
412 #undef WINE_INVALIDATE_SPI
413 #undef WINE_IGNORE_SPI
414 #undef WINE_RELOAD_SPI
415 }
416
417 /***********************************************************************
418  *           get_volatile_regkey
419  *
420  * Return a handle to the volatile registry key used to store
421  * non-permanently modified parameters.
422  */
423 static HKEY get_volatile_regkey(void)
424 {
425     static HKEY volatile_key;
426
427     if (!volatile_key)
428     {
429         if (RegCreateKeyExW( HKEY_CURRENT_USER, WINE_CURRENT_USER_REGKEY,
430                              0, 0, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, 0,
431                              &volatile_key, 0 ) != ERROR_SUCCESS)
432             ERR("Can't create wine configuration registry branch\n");
433     }
434     return volatile_key;
435 }
436
437 /***********************************************************************
438  *           SYSPARAMS_NotifyChange
439  *
440  * Sends notification about system parameter update.
441  */
442 void SYSPARAMS_NotifyChange( UINT uiAction, UINT fWinIni )
443 {
444     static const WCHAR emptyW[1];
445
446     if (notify_change)
447     {
448         if (fWinIni & SPIF_UPDATEINIFILE)
449         {
450             if (fWinIni & (SPIF_SENDWININICHANGE | SPIF_SENDCHANGE))
451                 SendMessageTimeoutW(HWND_BROADCAST, WM_SETTINGCHANGE,
452                                     uiAction, (LPARAM) emptyW,
453                                     SMTO_ABORTIFHUNG, 2000, NULL );
454         }
455         else
456         {
457             /* FIXME notify other wine processes with internal message */
458         }
459     }
460 }
461
462
463 /***********************************************************************
464  * Loads system parameter from user profile.
465  */
466 static BOOL SYSPARAMS_Load( LPCWSTR lpRegKey, LPCWSTR lpValName, LPWSTR lpBuf, DWORD count )
467 {
468     BOOL ret = FALSE;
469     DWORD type;
470     HKEY hKey;
471
472     if ((RegOpenKeyW( get_volatile_regkey(), lpRegKey, &hKey ) == ERROR_SUCCESS) ||
473         (RegOpenKeyW( HKEY_CURRENT_USER, lpRegKey, &hKey ) == ERROR_SUCCESS))
474     {
475         ret = !RegQueryValueExW( hKey, lpValName, NULL, &type, (LPBYTE)lpBuf, &count);
476         RegCloseKey( hKey );
477     }
478     return ret;
479 }
480
481 /***********************************************************************
482  * Saves system parameter to user profile.
483  */
484 static BOOL SYSPARAMS_Save( LPCWSTR lpRegKey, LPCWSTR lpValName, LPCWSTR lpValue,
485                             UINT fWinIni )
486 {
487     HKEY hKey;
488     HKEY hBaseKey;
489     DWORD dwOptions;
490     BOOL ret = FALSE;
491
492     if (fWinIni & SPIF_UPDATEINIFILE)
493     {
494         hBaseKey = HKEY_CURRENT_USER;
495         dwOptions = 0;
496     }
497     else
498     {
499         hBaseKey = get_volatile_regkey();
500         dwOptions = REG_OPTION_VOLATILE;
501     }
502
503     if (RegCreateKeyExW( hBaseKey, lpRegKey,
504                          0, 0, dwOptions, KEY_ALL_ACCESS,
505                          0, &hKey, 0 ) == ERROR_SUCCESS)
506     {
507         if (RegSetValueExW( hKey, lpValName, 0, REG_SZ,
508                             (const BYTE*)lpValue,
509                             (strlenW(lpValue) + 1)*sizeof(WCHAR)) == ERROR_SUCCESS)
510         {
511             ret = TRUE;
512             if (hBaseKey == HKEY_CURRENT_USER)
513                 RegDeleteKeyW( get_volatile_regkey(), lpRegKey );
514         }
515         RegCloseKey( hKey );
516     }
517     return ret;
518 }
519
520
521 /***********************************************************************
522  * SYSPARAMS_Twips2Pixels
523  *
524  * Convert a dimension value that was obtained from the registry.  These are
525  * quoted as being "twips" values if negative and pixels if positive.
526  * See for example
527  *   MSDN Library - April 2001 -> Resource Kits ->
528  *       Windows 2000 Resource Kit Reference ->
529  *       Technical Reference to the Windows 2000 Registry ->
530  *       HKEY_CURRENT_USER -> Control Panel -> Desktop -> WindowMetrics
531  */
532 inline static int SYSPARAMS_Twips2Pixels(int x)
533 {
534     if (x < 0)
535         x = (-x+7)/15;
536     return x;
537 }
538
539 /***********************************************************************
540  * SYSPARAMS_GetRegistryMetric
541  *
542  * Get a registry entry from the already open key.  This allows us to open the
543  * section once and read several values.
544  *
545  * Of course this function belongs somewhere more usable but here will do
546  * for now.
547  */
548 static int SYSPARAMS_GetRegistryMetric( HKEY hkey, LPCWSTR lpValName, int default_value )
549 {
550     int value = default_value;
551     if (hkey)
552     {
553         WCHAR buffer[128];
554         DWORD type, count = sizeof(buffer);
555         if(!RegQueryValueExW( hkey, lpValName, NULL, &type, (LPBYTE)buffer, &count) )
556         {
557             if (type != REG_SZ)
558             {
559                 /* Are there any utilities for converting registry entries
560                  * between formats?
561                  */
562                 /* FIXME_(reg)("We need reg format converter\n"); */
563             }
564             else
565                 value = atoiW(buffer);
566         }
567     }
568     return SYSPARAMS_Twips2Pixels(value);
569 }
570
571
572 /***********************************************************************
573  *           SYSPARAMS_Init
574  *
575  * Initialisation of the system metrics array.
576  *
577  * Differences in return values between 3.1 and 95 apps under Win95 (FIXME ?):
578  * SM_CXVSCROLL        x+1      x       Fixed May 24, 1999 - Ronald B. Cemer
579  * SM_CYHSCROLL        x+1      x       Fixed May 24, 1999 - Ronald B. Cemer
580  * SM_CXDLGFRAME       x-1      x       Already fixed
581  * SM_CYDLGFRAME       x-1      x       Already fixed
582  * SM_CYCAPTION        x+1      x       Fixed May 24, 1999 - Ronald B. Cemer
583  * SM_CYMENU           x-1      x       Already fixed
584  * SM_CYFULLSCREEN     x-1      x
585  * SM_CXFRAME                           Fixed July 6, 2001 - Bill Medland
586  *
587  * Starting at Win95 there are now a large number or Registry entries in the
588  * [WindowMetrics] section that are probably relevant here.
589  */
590 void SYSPARAMS_Init(void)
591 {
592     HKEY hkey; /* key to the window metrics area of the registry */
593     WCHAR buf[10];
594     INT border;
595
596     display_dc = CreateICW( DISPLAY, NULL, NULL, NULL );
597     assert( display_dc );
598
599     if (RegOpenKeyExW (HKEY_CURRENT_USER, METRICS_REGKEY,
600                        0, KEY_QUERY_VALUE, &hkey) != ERROR_SUCCESS) hkey = 0;
601
602     sysMetrics[SM_CXVSCROLL] = SYSPARAMS_GetRegistryMetric( hkey, METRICS_SCROLLWIDTH_VALNAME, 16 );
603     sysMetrics[SM_CYHSCROLL] = sysMetrics[SM_CXVSCROLL];
604
605     /* The Win 2000 resource kit SAYS that this is governed by the ScrollHeight
606      * but on my computer that controls the CYV/CXH values. */
607     sysMetrics[SM_CYCAPTION] = SYSPARAMS_GetRegistryMetric(hkey, METRICS_CAPTIONHEIGHT_VALNAME, 18)
608                                  + 1; /* for the separator? */
609
610     sysMetrics[SM_CYMENU] = SYSPARAMS_GetRegistryMetric (hkey, METRICS_MENUHEIGHT_VALNAME, 18) + 1;
611
612
613     sysMetrics[SM_CXDLGFRAME] = 3;
614     sysMetrics[SM_CYDLGFRAME] = sysMetrics[SM_CXDLGFRAME];
615
616     SystemParametersInfoW( SPI_GETBORDER, 0, &border, 0 );
617     sysMetrics[SM_CXFRAME] = sysMetrics[SM_CXDLGFRAME] + border;
618     sysMetrics[SM_CYFRAME] = sysMetrics[SM_CYDLGFRAME] + border;
619
620     sysMetrics[SM_CXCURSOR] = 32;
621     sysMetrics[SM_CYCURSOR] = 32;
622     sysMetrics[SM_CXBORDER] = SYSPARAMS_GetRegistryMetric( hkey, METRICS_BORDERWIDTH_VALNAME, 1 );
623     sysMetrics[SM_CYBORDER] = sysMetrics[SM_CXBORDER];
624     sysMetrics[SM_CYVTHUMB] = sysMetrics[SM_CXVSCROLL];
625     sysMetrics[SM_CXHTHUMB] = sysMetrics[SM_CYVTHUMB];
626     sysMetrics[SM_CXICON] = SYSPARAMS_GetRegistryMetric( hkey, METRICS_ICONSIZE_VALNAME, 32 );
627     sysMetrics[SM_CYICON] = sysMetrics[SM_CXICON];
628     sysMetrics[SM_CYKANJIWINDOW] = 0;
629     sysMetrics[SM_MOUSEPRESENT] = 1;
630     sysMetrics[SM_CYVSCROLL] = SYSPARAMS_GetRegistryMetric (hkey, METRICS_SCROLLHEIGHT_VALNAME, sysMetrics[SM_CXVSCROLL]);
631     sysMetrics[SM_CXHSCROLL] = SYSPARAMS_GetRegistryMetric (hkey, METRICS_SCROLLHEIGHT_VALNAME, sysMetrics[SM_CYHSCROLL]);
632     sysMetrics[SM_DEBUG] = 0;
633
634     sysMetrics[SM_SWAPBUTTON] = 0;
635     if (SYSPARAMS_Load( SPI_SETMOUSEBUTTONSWAP_REGKEY, SPI_SETMOUSEBUTTONSWAP_VALNAME, buf, sizeof(buf) ))
636         sysMetrics[SM_SWAPBUTTON] = atoiW( buf );
637     spi_loaded[SPI_SETMOUSEBUTTONSWAP_IDX] = TRUE;
638
639     sysMetrics[SM_RESERVED1] = 0;
640     sysMetrics[SM_RESERVED2] = 0;
641     sysMetrics[SM_RESERVED3] = 0;
642     sysMetrics[SM_RESERVED4] = 0;
643
644     /* FIXME: The following two are calculated, but how? */
645     sysMetrics[SM_CXMIN] = 112;
646     sysMetrics[SM_CYMIN] = 27;
647
648     sysMetrics[SM_CXSIZE] = SYSPARAMS_GetRegistryMetric (hkey, METRICS_CAPTIONWIDTH_VALNAME, sysMetrics[SM_CYCAPTION] - 1);
649     sysMetrics[SM_CYSIZE] = sysMetrics[SM_CYCAPTION] - 1;
650     sysMetrics[SM_CXMINTRACK] = sysMetrics[SM_CXMIN];
651     sysMetrics[SM_CYMINTRACK] = sysMetrics[SM_CYMIN];
652
653     sysMetrics[SM_CXDOUBLECLK] = 4;
654     sysMetrics[SM_CYDOUBLECLK] = 4;
655
656     if (SYSPARAMS_Load( SPI_SETDOUBLECLKWIDTH_REGKEY1, SPI_SETDOUBLECLKWIDTH_VALNAME, buf, sizeof(buf) ))
657         sysMetrics[SM_CXDOUBLECLK] = atoiW( buf );
658     spi_loaded[SPI_SETDOUBLECLKWIDTH_IDX] = TRUE;
659
660     if (SYSPARAMS_Load( SPI_SETDOUBLECLKHEIGHT_REGKEY1, SPI_SETDOUBLECLKHEIGHT_VALNAME, buf, sizeof(buf) ))
661         sysMetrics[SM_CYDOUBLECLK] = atoiW( buf );
662     spi_loaded[SPI_SETDOUBLECLKHEIGHT_IDX] = TRUE;
663
664     sysMetrics[SM_CXICONSPACING] = 75;
665     SystemParametersInfoW( SPI_ICONHORIZONTALSPACING, 0, &sysMetrics[SM_CXICONSPACING], 0 );
666     sysMetrics[SM_CYICONSPACING] = 75;
667     SystemParametersInfoW( SPI_ICONVERTICALSPACING, 0, &sysMetrics[SM_CYICONSPACING], 0 );
668
669     SystemParametersInfoW( SPI_GETMENUDROPALIGNMENT, 0, &sysMetrics[SM_MENUDROPALIGNMENT], 0 );
670     sysMetrics[SM_PENWINDOWS] = 0;
671     sysMetrics[SM_DBCSENABLED] = 0;
672
673     /* FIXME: Need to query X for the following */
674     sysMetrics[SM_CMOUSEBUTTONS] = 3;
675
676     sysMetrics[SM_SECURE] = 0;
677     sysMetrics[SM_CXEDGE] = sysMetrics[SM_CXBORDER] + 1;
678     sysMetrics[SM_CYEDGE] = sysMetrics[SM_CXEDGE];
679     sysMetrics[SM_CXMINSPACING] = 160;
680     sysMetrics[SM_CYMINSPACING] = 24;
681     sysMetrics[SM_CXSMICON] = 16;
682     sysMetrics[SM_CYSMICON] = 16;
683     sysMetrics[SM_CYSMCAPTION] = SYSPARAMS_GetRegistryMetric(hkey, METRICS_SMCAPTIONHEIGHT_VALNAME, 15) + 1;
684     sysMetrics[SM_CXSMSIZE] = SYSPARAMS_GetRegistryMetric(hkey, METRICS_SMCAPTIONWIDTH_VALNAME, 13);
685     sysMetrics[SM_CYSMSIZE] = sysMetrics[SM_CYSMCAPTION] - 1;
686     sysMetrics[SM_CXMENUSIZE] = SYSPARAMS_GetRegistryMetric(hkey, METRICS_MENUWIDTH_VALNAME, sysMetrics[SM_CYMENU] - 1);
687     sysMetrics[SM_CYMENUSIZE] = sysMetrics[SM_CYMENU] - 1;
688
689     /* FIXME: What do these mean? */
690     sysMetrics[SM_ARRANGE] = ARW_HIDE;
691     sysMetrics[SM_CXMINIMIZED] = 160;
692     sysMetrics[SM_CYMINIMIZED] = 24;
693
694     /* FIXME: How do I calculate these? */
695     sysMetrics[SM_NETWORK] = 3;
696
697     /* For the following: 0 = ok, 1 = failsafe, 2 = failsafe + network */
698     sysMetrics[SM_CLEANBOOT] = 0;
699
700     sysMetrics[SM_CXDRAG] = 4;
701     sysMetrics[SM_CYDRAG] = 4;
702     sysMetrics[SM_CXMENUCHECK] = 13;
703     sysMetrics[SM_CYMENUCHECK] = 13;
704
705     /* FIXME: Should check the type of processor for the following */
706     sysMetrics[SM_SLOWMACHINE] = 0;
707
708     /* FIXME: Should perform a check */
709     sysMetrics[SM_MIDEASTENABLED] = 0;
710
711     sysMetrics[SM_MOUSEWHEELPRESENT] = 1;
712
713     sysMetrics[SM_XVIRTUALSCREEN] = 0;
714     sysMetrics[SM_YVIRTUALSCREEN] = 0;
715     sysMetrics[SM_CMONITORS] = 1;
716     sysMetrics[SM_SAMEDISPLAYFORMAT] = 1;
717     sysMetrics[SM_CMETRICS] = SM_CMETRICS;
718
719     SystemParametersInfoW( SPI_GETSHOWSOUNDS, 0, &sysMetrics[SM_SHOWSOUNDS], 0 );
720
721     if (hkey) RegCloseKey (hkey);
722
723     SYSCOLOR_Init();
724 }
725
726
727 /***********************************************************************
728  *              SystemParametersInfoW (USER32.@)
729  *
730  *     Each system parameter has flag which shows whether the parameter
731  * is loaded or not. Parameters, stored directly in SysParametersInfo are
732  * loaded from registry only when they are requested and the flag is
733  * "false", after the loading the flag is set to "true". On interprocess
734  * notification of the parameter change the corresponding parameter flag is
735  * set to "false". The parameter value will be reloaded when it is requested
736  * the next time.
737  *     Parameters, backed by or depend on GetSystemMetrics are processed
738  * differently. These parameters are always loaded. They are reloaded right
739  * away on interprocess change notification. We can't do lazy loading because
740  * we don't want to complicate GetSystemMetrics.
741  *     Parameters, backed by X settings are read from corresponding setting.
742  * On the parameter change request the setting is changed. Interprocess change
743  * notifications are ignored.
744  *     When parameter value is updated the changed value is stored in permanent
745  * registry branch if saving is requested. Otherwise it is stored
746  * in temporary branch
747  *
748  * Some SPI values can also be stored as Twips values in the registry,
749  * don't forget the conversion!
750  */
751 BOOL WINAPI SystemParametersInfoW( UINT uiAction, UINT uiParam,
752                                    PVOID pvParam, UINT fWinIni )
753 {
754 #define WINE_SPI_FIXME(x) \
755     case x: \
756         FIXME( "Unimplemented action: %u (%s)\n", x, #x ); \
757         SetLastError( ERROR_INVALID_SPI_VALUE ); \
758         ret = FALSE; \
759         break
760 #define WINE_SPI_WARN(x) \
761     case x: \
762         WARN( "Ignored action: %u (%s)\n", x, #x ); \
763         break
764
765     BOOL ret = TRUE;
766     unsigned spi_idx = 0;
767
768     TRACE("(%u, %u, %p, %u)\n", uiAction, uiParam, pvParam, fWinIni);
769
770     switch (uiAction)
771     {
772     case SPI_GETBEEP:                           /*      1 */
773         if (!pvParam) return FALSE;
774
775         spi_idx = SPI_SETBEEP_IDX;
776         if (!spi_loaded[spi_idx])
777         {
778             WCHAR buf[5];
779
780             if (SYSPARAMS_Load( SPI_SETBEEP_REGKEY, SPI_SETBEEP_VALNAME, buf, sizeof(buf) ))
781                 beep_active  = !lstrcmpiW( Yes, buf );
782             spi_loaded[spi_idx] = TRUE;
783         }
784
785         *(BOOL *)pvParam = beep_active;
786         break;
787
788     case SPI_SETBEEP:                           /*      2 */
789         spi_idx = SPI_SETBEEP_IDX;
790         if (SYSPARAMS_Save( SPI_SETBEEP_REGKEY, SPI_SETBEEP_VALNAME,
791                             (uiParam ? Yes : No), fWinIni ))
792         {
793             beep_active = uiParam;
794             spi_loaded[spi_idx] = TRUE;
795         }
796         else
797             ret = FALSE;
798         break;
799
800     case SPI_GETMOUSE:                          /*      3 */
801         if (!pvParam) return FALSE;
802
803         spi_idx = SPI_SETMOUSE_IDX;
804         if (!spi_loaded[spi_idx])
805         {
806             WCHAR buf[10];
807
808             if (SYSPARAMS_Load( SPI_SETMOUSE_REGKEY, SPI_SETMOUSE_VALNAME1,
809                                 buf, sizeof(buf) ))
810                 mouse_threshold1 = atoiW( buf );
811             if (SYSPARAMS_Load( SPI_SETMOUSE_REGKEY, SPI_SETMOUSE_VALNAME2,
812                                 buf, sizeof(buf) ))
813                 mouse_threshold2 = atoiW( buf );
814             if (SYSPARAMS_Load( SPI_SETMOUSE_REGKEY, SPI_SETMOUSE_VALNAME3,
815                                 buf, sizeof(buf) ))
816                 mouse_speed = atoiW( buf );
817             spi_loaded[spi_idx] = TRUE;
818         }
819         ((INT *)pvParam)[0] = mouse_threshold1;
820         ((INT *)pvParam)[1] = mouse_threshold2;
821         ((INT *)pvParam)[2] = mouse_speed;
822         break;
823
824     case SPI_SETMOUSE:                          /*      4 */
825     {
826         WCHAR buf[10];
827
828         if (!pvParam) return FALSE;
829
830         spi_idx = SPI_SETMOUSE_IDX;
831         wsprintfW(buf, CSd, ((INT *)pvParam)[0]);
832
833         if (SYSPARAMS_Save( SPI_SETMOUSE_REGKEY, SPI_SETMOUSE_VALNAME1,
834                             buf, fWinIni ))
835         {
836             mouse_threshold1 = ((INT *)pvParam)[0];
837             spi_loaded[spi_idx] = TRUE;
838
839             wsprintfW(buf, CSd, ((INT *)pvParam)[1]);
840             SYSPARAMS_Save( SPI_SETMOUSE_REGKEY, SPI_SETMOUSE_VALNAME2,
841                             buf, fWinIni );
842             mouse_threshold2 = ((INT *)pvParam)[1];
843
844             wsprintfW(buf, CSd, ((INT *)pvParam)[2]);
845             SYSPARAMS_Save( SPI_SETMOUSE_REGKEY, SPI_SETMOUSE_VALNAME3,
846                             buf, fWinIni );
847             mouse_speed = ((INT *)pvParam)[2];
848         }
849         else
850             ret = FALSE;
851         break;
852     }
853
854     case SPI_GETBORDER:                         /*      5 */
855         if (!pvParam) return FALSE;
856
857         spi_idx = SPI_SETBORDER_IDX;
858         if (!spi_loaded[spi_idx])
859         {
860             WCHAR buf[10];
861
862             if (SYSPARAMS_Load( SPI_SETBORDER_REGKEY, SPI_SETBORDER_VALNAME, buf, sizeof(buf) ))
863                 border = SYSPARAMS_Twips2Pixels( atoiW(buf) );
864
865             spi_loaded[spi_idx] = TRUE;
866             sysMetrics[SM_CXFRAME] = border + sysMetrics[SM_CXDLGFRAME];
867             sysMetrics[SM_CYFRAME] = border + sysMetrics[SM_CYDLGFRAME];
868         }
869         *(INT *)pvParam = border;
870         break;
871
872     case SPI_SETBORDER:                         /*      6 */
873     {
874         WCHAR buf[10];
875
876         spi_idx = SPI_SETBORDER_IDX;
877         wsprintfW(buf, CSu, uiParam);
878
879         if (SYSPARAMS_Save( SPI_SETBORDER_REGKEY, SPI_SETBORDER_VALNAME,
880                             buf, fWinIni ))
881         {
882             if (uiParam > 0)
883             {
884                 border = uiParam;
885                 spi_loaded[spi_idx] = TRUE;
886                 sysMetrics[SM_CXFRAME] = border + sysMetrics[SM_CXDLGFRAME];
887                 sysMetrics[SM_CYFRAME] = border + sysMetrics[SM_CYDLGFRAME];
888             }
889         }
890         else
891             ret = FALSE;
892         break;
893     }
894
895     case SPI_GETKEYBOARDSPEED:                  /*     10 */
896         if (!pvParam) return FALSE;
897
898         spi_idx = SPI_SETKEYBOARDSPEED_IDX;
899         if (!spi_loaded[spi_idx])
900         {
901             WCHAR buf[10];
902
903             if (SYSPARAMS_Load( SPI_SETKEYBOARDSPEED_REGKEY,
904                                 SPI_SETKEYBOARDSPEED_VALNAME,
905                                 buf, sizeof(buf) ))
906                 keyboard_speed = atoiW( buf );
907             spi_loaded[spi_idx] = TRUE;
908         }
909         *(INT *)pvParam = keyboard_speed;
910         break;
911
912     case SPI_SETKEYBOARDSPEED:                  /*     11 */
913     {
914         WCHAR buf[10];
915
916         spi_idx = SPI_SETKEYBOARDSPEED_IDX;
917         if (uiParam > 31)
918             uiParam = 31;
919         wsprintfW(buf, CSu, uiParam);
920
921         if (SYSPARAMS_Save( SPI_SETKEYBOARDSPEED_REGKEY,
922                             SPI_SETKEYBOARDSPEED_VALNAME,
923                             buf, fWinIni ))
924         {
925             keyboard_speed = uiParam;
926             spi_loaded[spi_idx] = TRUE;
927         }
928         else
929             ret = FALSE;
930         break;
931     }
932
933     /* not implemented in Windows */
934     WINE_SPI_WARN(SPI_LANGDRIVER);              /*     12 */
935
936     case SPI_ICONHORIZONTALSPACING:             /*     13 */
937         spi_idx = SPI_ICONHORIZONTALSPACING_IDX;
938         if (pvParam != NULL)
939         {
940             if (!spi_loaded[spi_idx])
941             {
942                 WCHAR buf[10];
943                 int val;
944
945                 if (SYSPARAMS_Load( SPI_ICONHORIZONTALSPACING_REGKEY,
946                                     SPI_ICONHORIZONTALSPACING_VALNAME, buf, sizeof(buf) ))
947                 {
948                     val = SYSPARAMS_Twips2Pixels( atoiW(buf) );
949                     sysMetrics[SM_CXICONSPACING] = val;
950                 }
951                 spi_loaded[spi_idx] = TRUE;
952             }
953
954             *(INT *)pvParam = sysMetrics[SM_CXICONSPACING];
955         }
956         else
957         {
958             WCHAR buf[10];
959
960             if (uiParam < 32) uiParam = 32;
961
962             wsprintfW(buf, CSu, uiParam);
963             if (SYSPARAMS_Save( SPI_ICONHORIZONTALSPACING_REGKEY,
964                                 SPI_ICONHORIZONTALSPACING_VALNAME,
965                                 buf, fWinIni ))
966             {
967                 sysMetrics[SM_CXICONSPACING] = uiParam;
968                 spi_loaded[spi_idx] = TRUE;
969             }
970             else
971                 ret = FALSE;
972         }
973         break;
974
975     case SPI_GETSCREENSAVETIMEOUT:              /*     14 */
976         if (!pvParam) return FALSE;
977
978         spi_idx = SPI_SETSCREENSAVETIMEOUT_IDX;
979         if (!spi_loaded[spi_idx])
980         {
981             WCHAR buf[10];
982
983             if (SYSPARAMS_Load( SPI_SETSCREENSAVETIMEOUT_REGKEY,
984                                 SPI_SETSCREENSAVETIMEOUT_VALNAME,
985                                 buf, sizeof(buf) ))
986                 screensave_timeout = atoiW( buf );
987
988             spi_loaded[spi_idx] = TRUE;
989         }
990         *(INT *)pvParam = screensave_timeout;
991         break;
992
993     case SPI_SETSCREENSAVETIMEOUT:              /*     15 */
994     {
995         WCHAR buf[10];
996
997         spi_idx = SPI_SETSCREENSAVETIMEOUT_IDX;
998         wsprintfW(buf, CSu, uiParam);
999
1000         if (SYSPARAMS_Save( SPI_SETSCREENSAVETIMEOUT_REGKEY,
1001                             SPI_SETSCREENSAVETIMEOUT_VALNAME,
1002                             buf, fWinIni ))
1003         {
1004             screensave_timeout = uiParam;
1005             spi_loaded[spi_idx] = TRUE;
1006         }
1007         else
1008             ret = FALSE;
1009         break;
1010     }
1011
1012     case SPI_GETSCREENSAVEACTIVE:               /*     16 */
1013         if (!pvParam) return FALSE;
1014         if (USER_Driver.pGetScreenSaveActive)
1015             *(BOOL *)pvParam = USER_Driver.pGetScreenSaveActive();
1016         else
1017             *(BOOL *)pvParam = FALSE;
1018         break;
1019
1020     case SPI_SETSCREENSAVEACTIVE:               /*     17 */
1021     {
1022         WCHAR buf[5];
1023
1024         wsprintfW(buf, CSu, uiParam);
1025         if (USER_Driver.pSetScreenSaveActive)
1026             USER_Driver.pSetScreenSaveActive( uiParam );
1027         /* saved value does not affect Wine */
1028         SYSPARAMS_Save( SPI_SETSCREENSAVEACTIVE_REGKEY,
1029                         SPI_SETSCREENSAVEACTIVE_VALNAME,
1030                         buf, fWinIni );
1031         break;
1032     }
1033
1034     case SPI_GETGRIDGRANULARITY:                /*     18 */
1035         if (!pvParam) return FALSE;
1036
1037         spi_idx = SPI_SETGRIDGRANULARITY_IDX;
1038         if (!spi_loaded[spi_idx])
1039         {
1040             WCHAR buf[10];
1041
1042             if (SYSPARAMS_Load( SPI_SETGRIDGRANULARITY_REGKEY,
1043                                 SPI_SETGRIDGRANULARITY_VALNAME,
1044                                 buf, sizeof(buf) ))
1045                 grid_granularity = atoiW( buf );
1046
1047             spi_loaded[spi_idx] = TRUE;
1048         }
1049         *(INT *)pvParam = grid_granularity;
1050         break;
1051
1052     case SPI_SETGRIDGRANULARITY:                /*     19 */
1053     {
1054         WCHAR buf[10];
1055
1056         spi_idx = SPI_SETGRIDGRANULARITY_IDX;
1057         wsprintfW(buf, CSu, uiParam);
1058
1059         if (SYSPARAMS_Save( SPI_SETGRIDGRANULARITY_REGKEY,
1060                             SPI_SETGRIDGRANULARITY_VALNAME,
1061                             buf, fWinIni ))
1062         {
1063             grid_granularity = uiParam;
1064             spi_loaded[spi_idx] = TRUE;
1065         }
1066         else
1067             ret = FALSE;
1068         break;
1069     }
1070
1071     case SPI_SETDESKWALLPAPER:                  /*     20 */
1072         if (!pvParam || !SetDeskWallPaper( (LPSTR)pvParam )) return FALSE;
1073         SYSPARAMS_Save(SPI_SETDESKWALLPAPER_REGKEY, SPI_SETDESKWALLPAPER_VALNAME, pvParam, fWinIni);
1074         break;
1075         
1076     case SPI_SETDESKPATTERN:                    /*     21 */
1077         /* FIXME: the ability to specify a pattern in pvParam
1078            doesn't seem to be documented for Win32 */
1079         if ((INT16)uiParam == -1)
1080         {
1081             WCHAR buf[256];
1082             GetProfileStringW( Desktop, Pattern,
1083                                defPattern,
1084                                buf, sizeof(buf)/sizeof(WCHAR) );
1085             ret = DESKTOP_SetPattern( buf );
1086         } else
1087             ret = DESKTOP_SetPattern( (LPWSTR)pvParam );
1088         break;
1089
1090     case SPI_GETKEYBOARDDELAY:                  /*     22 */
1091         if (!pvParam) return FALSE;
1092
1093         spi_idx = SPI_SETKEYBOARDDELAY_IDX;
1094         if (!spi_loaded[spi_idx])
1095         {
1096             WCHAR buf[10];
1097
1098             if (SYSPARAMS_Load( SPI_SETKEYBOARDDELAY_REGKEY,
1099                                 SPI_SETKEYBOARDDELAY_VALNAME,
1100                                 buf, sizeof(buf) ))
1101             {
1102                 int i = atoiW( buf );
1103                 if ( (i >= 0) && (i <= 3)) keyboard_delay = i;
1104             }
1105
1106             spi_loaded[spi_idx] = TRUE;
1107         }
1108         *(INT *)pvParam = keyboard_delay;
1109         break;
1110
1111     case SPI_SETKEYBOARDDELAY:                  /*     23 */
1112     {
1113         WCHAR buf[10];
1114
1115         spi_idx = SPI_SETKEYBOARDDELAY_IDX;
1116         wsprintfW(buf, CSu, uiParam);
1117
1118         if (SYSPARAMS_Save( SPI_SETKEYBOARDDELAY_REGKEY,
1119                             SPI_SETKEYBOARDDELAY_VALNAME,
1120                             buf, fWinIni ))
1121         {
1122             if (uiParam <= 3)
1123                 keyboard_delay = uiParam;
1124             spi_loaded[spi_idx] = TRUE;
1125         }
1126         else
1127             ret = FALSE;
1128         break;
1129     }
1130
1131     case SPI_ICONVERTICALSPACING:               /*     24 */
1132         spi_idx = SPI_ICONVERTICALSPACING_IDX;
1133         if (pvParam != NULL)
1134         {
1135             if (!spi_loaded[spi_idx])
1136             {
1137                 WCHAR buf[10];
1138                 int val;
1139
1140                 if (SYSPARAMS_Load( SPI_ICONVERTICALSPACING_REGKEY,
1141                                     SPI_ICONVERTICALSPACING_VALNAME, buf, sizeof(buf) ))
1142                 {
1143                     val = SYSPARAMS_Twips2Pixels( atoiW(buf) );
1144                     sysMetrics[SM_CYICONSPACING] = val;
1145                 }
1146                 spi_loaded[spi_idx] = TRUE;
1147             }
1148
1149             *(INT *)pvParam = sysMetrics[SM_CYICONSPACING];
1150         }
1151         else
1152         {
1153             WCHAR buf[10];
1154
1155             if (uiParam < 32) uiParam = 32;
1156
1157             wsprintfW(buf, CSu, uiParam);
1158             if (SYSPARAMS_Save( SPI_ICONVERTICALSPACING_REGKEY,
1159                                 SPI_ICONVERTICALSPACING_VALNAME,
1160                                 buf, fWinIni ))
1161             {
1162                 sysMetrics[SM_CYICONSPACING] = uiParam;
1163                 spi_loaded[spi_idx] = TRUE;
1164             }
1165             else
1166                 ret = FALSE;
1167         }
1168
1169         break;
1170
1171     case SPI_GETICONTITLEWRAP:                  /*     25 */
1172         if (!pvParam) return FALSE;
1173
1174         spi_idx = SPI_SETICONTITLEWRAP_IDX;
1175         if (!spi_loaded[spi_idx])
1176         {
1177             WCHAR buf[5];
1178
1179             if (SYSPARAMS_Load( SPI_SETICONTITLEWRAP_REGKEY1,
1180                                 SPI_SETICONTITLEWRAP_VALNAME, buf, sizeof(buf) ))
1181                 icon_title_wrap  = atoiW(buf);
1182             spi_loaded[spi_idx] = TRUE;
1183         }
1184
1185         *(BOOL *)pvParam = icon_title_wrap;
1186         break;
1187
1188     case SPI_SETICONTITLEWRAP:                  /*     26 */
1189     {
1190         WCHAR buf[5];
1191
1192         spi_idx = SPI_SETICONTITLEWRAP_IDX;
1193         wsprintfW(buf, CSu, uiParam);
1194         if (SYSPARAMS_Save( SPI_SETICONTITLEWRAP_REGKEY1,
1195                             SPI_SETICONTITLEWRAP_VALNAME,
1196                             buf, fWinIni ))
1197         {
1198             SYSPARAMS_Save( SPI_SETICONTITLEWRAP_REGKEY2,
1199                             SPI_SETICONTITLEWRAP_VALNAME,
1200                             buf, fWinIni );
1201             icon_title_wrap = uiParam;
1202             spi_loaded[spi_idx] = TRUE;
1203         }
1204         else
1205             ret = FALSE;
1206         break;
1207     }
1208
1209     case SPI_GETMENUDROPALIGNMENT:              /*     27 */
1210         if (!pvParam) return FALSE;
1211
1212         spi_idx = SPI_SETMENUDROPALIGNMENT_IDX;
1213
1214         if (!spi_loaded[spi_idx])
1215         {
1216             WCHAR buf[5];
1217
1218             if (SYSPARAMS_Load( SPI_SETMENUDROPALIGNMENT_REGKEY1,
1219                                 SPI_SETMENUDROPALIGNMENT_VALNAME, buf, sizeof(buf) ))
1220             {
1221                 sysMetrics[SM_MENUDROPALIGNMENT] = atoiW( buf );
1222             }
1223             spi_loaded[spi_idx] = TRUE;
1224         }
1225
1226         *(BOOL *)pvParam = sysMetrics[SM_MENUDROPALIGNMENT];
1227         break;
1228
1229     case SPI_SETMENUDROPALIGNMENT:              /*     28 */
1230     {
1231         WCHAR buf[5];
1232         spi_idx = SPI_SETMENUDROPALIGNMENT_IDX;
1233
1234         wsprintfW(buf, CSu, uiParam);
1235         if (SYSPARAMS_Save( SPI_SETMENUDROPALIGNMENT_REGKEY1,
1236                             SPI_SETMENUDROPALIGNMENT_VALNAME,
1237                             buf, fWinIni ))
1238         {
1239             SYSPARAMS_Save( SPI_SETMENUDROPALIGNMENT_REGKEY2,
1240                             SPI_SETMENUDROPALIGNMENT_VALNAME,
1241                             buf, fWinIni );
1242             sysMetrics[SM_MENUDROPALIGNMENT] = uiParam;
1243             spi_loaded[spi_idx] = TRUE;
1244         }
1245         else
1246             ret = FALSE;
1247         break;
1248     }
1249
1250     case SPI_SETDOUBLECLKWIDTH:                 /*     29 */
1251     {
1252         WCHAR buf[10];
1253         spi_idx = SPI_SETDOUBLECLKWIDTH_IDX;
1254
1255         wsprintfW(buf, CSu, uiParam);
1256         if (SYSPARAMS_Save( SPI_SETDOUBLECLKWIDTH_REGKEY1,
1257                             SPI_SETDOUBLECLKWIDTH_VALNAME,
1258                             buf, fWinIni ))
1259         {
1260             SYSPARAMS_Save( SPI_SETDOUBLECLKWIDTH_REGKEY2,
1261                             SPI_SETDOUBLECLKWIDTH_VALNAME,
1262                             buf, fWinIni );
1263             sysMetrics[SM_CXDOUBLECLK] = uiParam;
1264             spi_loaded[spi_idx] = TRUE;
1265         }
1266         else
1267             ret = FALSE;
1268         break;
1269     }
1270
1271     case SPI_SETDOUBLECLKHEIGHT:                /*     30 */
1272     {
1273         WCHAR buf[10];
1274         spi_idx = SPI_SETDOUBLECLKHEIGHT_IDX;
1275
1276         wsprintfW(buf, CSu, uiParam);
1277         if (SYSPARAMS_Save( SPI_SETDOUBLECLKHEIGHT_REGKEY1,
1278                             SPI_SETDOUBLECLKHEIGHT_VALNAME,
1279                             buf, fWinIni ))
1280         {
1281             SYSPARAMS_Save( SPI_SETDOUBLECLKHEIGHT_REGKEY2,
1282                             SPI_SETDOUBLECLKHEIGHT_VALNAME,
1283                             buf, fWinIni );
1284             sysMetrics[SM_CYDOUBLECLK] = uiParam;
1285             spi_loaded[spi_idx] = TRUE;
1286         }
1287         else
1288             ret = FALSE;
1289         break;
1290     }
1291
1292     case SPI_GETICONTITLELOGFONT:               /*     31 */
1293     {
1294         LPLOGFONTW lpLogFont = (LPLOGFONTW)pvParam;
1295         LOGFONTW        lfDefault;
1296
1297         if (!pvParam) return FALSE;
1298
1299         /*
1300          * The 'default GDI fonts' seems to be returned.
1301          * If a returned font is not a correct font in your environment,
1302          * please try to fix objects/gdiobj.c at first.
1303          */
1304         GetObjectW( GetStockObject( DEFAULT_GUI_FONT ), sizeof(LOGFONTW), &lfDefault );
1305
1306         GetProfileStringW( Desktop, IconTitleFaceName,
1307                            lfDefault.lfFaceName,
1308                            lpLogFont->lfFaceName, LF_FACESIZE );
1309         lpLogFont->lfHeight = -GetProfileIntW( Desktop, IconTitleSize, 11 );
1310         lpLogFont->lfWidth = 0;
1311         lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
1312         lpLogFont->lfWeight = FW_NORMAL;
1313         lpLogFont->lfItalic = FALSE;
1314         lpLogFont->lfStrikeOut = FALSE;
1315         lpLogFont->lfUnderline = FALSE;
1316         lpLogFont->lfCharSet = lfDefault.lfCharSet; /* at least 'charset' should not be hard-coded */
1317         lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
1318         lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
1319         lpLogFont->lfPitchAndFamily = DEFAULT_PITCH;
1320         lpLogFont->lfQuality = DEFAULT_QUALITY;
1321         break;
1322     }
1323
1324     case SPI_SETDOUBLECLICKTIME:                /*     32 */
1325     {
1326         WCHAR buf[10];
1327
1328         spi_idx = SPI_SETDOUBLECLICKTIME_IDX;
1329         wsprintfW(buf, CSu, uiParam);
1330
1331         if (SYSPARAMS_Save( SPI_SETDOUBLECLICKTIME_REGKEY,
1332                             SPI_SETDOUBLECLICKTIME_VALNAME,
1333                             buf, fWinIni ))
1334         {
1335             if (!uiParam)
1336                 uiParam = 500;
1337             double_click_time = uiParam;
1338             spi_loaded[spi_idx] = TRUE;
1339         }
1340         else
1341             ret = FALSE;
1342         break;
1343     }
1344
1345     case SPI_SETMOUSEBUTTONSWAP:                /*     33 */
1346     {
1347         WCHAR buf[5];
1348         spi_idx = SPI_SETMOUSEBUTTONSWAP_IDX;
1349
1350         wsprintfW(buf, CSu, uiParam);
1351         if (SYSPARAMS_Save( SPI_SETMOUSEBUTTONSWAP_REGKEY,
1352                             SPI_SETMOUSEBUTTONSWAP_VALNAME,
1353                             buf, fWinIni ))
1354         {
1355             sysMetrics[SM_SWAPBUTTON] = uiParam;
1356             spi_loaded[spi_idx] = TRUE;
1357         }
1358         else
1359             ret = FALSE;
1360         break;
1361     }
1362
1363     WINE_SPI_FIXME(SPI_SETICONTITLELOGFONT);    /*     34 */
1364
1365     case SPI_GETFASTTASKSWITCH:                 /*     35 */
1366         if (!pvParam) return FALSE;
1367         *(BOOL *)pvParam = 1;
1368         break;
1369
1370     case SPI_SETFASTTASKSWITCH:                 /*     36 */
1371         /* the action is disabled */
1372         ret = FALSE;
1373         break;
1374
1375     case SPI_SETDRAGFULLWINDOWS:                /*     37  WINVER >= 0x0400 */
1376     {
1377         WCHAR buf[5];
1378
1379         spi_idx = SPI_SETDRAGFULLWINDOWS_IDX;
1380         wsprintfW(buf, CSu, uiParam);
1381         if (SYSPARAMS_Save( SPI_SETDRAGFULLWINDOWS_REGKEY,
1382                             SPI_SETDRAGFULLWINDOWS_VALNAME,
1383                             buf, fWinIni ))
1384         {
1385             drag_full_windows = uiParam;
1386             spi_loaded[spi_idx] = TRUE;
1387         }
1388         else
1389             ret = FALSE;
1390         break;
1391     }
1392
1393     case SPI_GETDRAGFULLWINDOWS:                /*     38  WINVER >= 0x0400 */
1394         if (!pvParam) return FALSE;
1395
1396         spi_idx = SPI_SETDRAGFULLWINDOWS_IDX;
1397         if (!spi_loaded[spi_idx])
1398         {
1399             WCHAR buf[5];
1400
1401             if (SYSPARAMS_Load( SPI_SETDRAGFULLWINDOWS_REGKEY,
1402                                 SPI_SETDRAGFULLWINDOWS_VALNAME, buf, sizeof(buf) ))
1403                 drag_full_windows  = atoiW(buf);
1404             spi_loaded[spi_idx] = TRUE;
1405         }
1406
1407         *(BOOL *)pvParam = drag_full_windows;
1408         break;
1409
1410     case SPI_GETNONCLIENTMETRICS:               /*     41  WINVER >= 0x400 */
1411     {
1412         LPNONCLIENTMETRICSW lpnm = (LPNONCLIENTMETRICSW)pvParam;
1413
1414         if (!pvParam) return FALSE;
1415
1416         if (lpnm->cbSize == sizeof(NONCLIENTMETRICSW))
1417         {
1418             /* clear the struct, so we have 'sane' members */
1419             memset(
1420                 (char *)pvParam + sizeof(lpnm->cbSize),
1421                 0,
1422                 lpnm->cbSize - sizeof(lpnm->cbSize)
1423                 );
1424
1425             /* initialize geometry entries */
1426             lpnm->iBorderWidth = 1;
1427             lpnm->iScrollWidth = sysMetrics[SM_CXVSCROLL];
1428             lpnm->iScrollHeight = sysMetrics[SM_CYHSCROLL];
1429
1430             /* size of the normal caption buttons */
1431             lpnm->iCaptionWidth = sysMetrics[SM_CXSIZE];
1432             lpnm->iCaptionHeight = sysMetrics[SM_CYSIZE];
1433
1434             /* caption font metrics */
1435             SystemParametersInfoW( SPI_GETICONTITLELOGFONT, 0, (LPVOID)&(lpnm->lfCaptionFont), 0 );
1436             lpnm->lfCaptionFont.lfWeight = FW_BOLD;
1437
1438             /* size of the small caption buttons */
1439             lpnm->iSmCaptionWidth = sysMetrics[SM_CXSMSIZE];
1440             lpnm->iSmCaptionHeight = sysMetrics[SM_CYSMSIZE];
1441
1442             /* small caption font metrics */
1443             SystemParametersInfoW( SPI_GETICONTITLELOGFONT, 0, (LPVOID)&(lpnm->lfSmCaptionFont), 0 );
1444
1445             /* menus, FIXME: names of wine.conf entries are bogus */
1446
1447             /* size of the menu (MDI) buttons */
1448             lpnm->iMenuWidth = sysMetrics[SM_CXMENUSIZE];
1449             lpnm->iMenuHeight = sysMetrics[SM_CYMENUSIZE];
1450
1451             /* menu font metrics */
1452             SystemParametersInfoW( SPI_GETICONTITLELOGFONT, 0, (LPVOID)&(lpnm->lfMenuFont), 0 );
1453             GetProfileStringW( Desktop, MenuFont, lpnm->lfCaptionFont.lfFaceName,
1454                                lpnm->lfMenuFont.lfFaceName, LF_FACESIZE );
1455             lpnm->lfMenuFont.lfHeight = -GetProfileIntW( Desktop, MenuFontSize, 11 );
1456             lpnm->lfMenuFont.lfWeight = FW_NORMAL;
1457
1458             /* status bar font metrics */
1459             SystemParametersInfoW( SPI_GETICONTITLELOGFONT, 0,
1460                                    (LPVOID)&(lpnm->lfStatusFont), 0 );
1461             GetProfileStringW( Desktop, StatusFont, lpnm->lfCaptionFont.lfFaceName,
1462                                lpnm->lfStatusFont.lfFaceName, LF_FACESIZE );
1463             lpnm->lfStatusFont.lfHeight = -GetProfileIntW( Desktop, StatusFontSize, 11 );
1464             lpnm->lfStatusFont.lfWeight = FW_NORMAL;
1465
1466             /* message font metrics */
1467             SystemParametersInfoW( SPI_GETICONTITLELOGFONT, 0,
1468                                    (LPVOID)&(lpnm->lfMessageFont), 0 );
1469             GetProfileStringW( Desktop, MessageFont, lpnm->lfCaptionFont.lfFaceName,
1470                                lpnm->lfMessageFont.lfFaceName, LF_FACESIZE );
1471             lpnm->lfMessageFont.lfHeight = -GetProfileIntW( Desktop, MessageFontSize, 11 );
1472             lpnm->lfMessageFont.lfWeight = FW_NORMAL;
1473
1474         }
1475         else
1476         {
1477             WARN("size mismatch !! (is %d; should be %d)\n", lpnm->cbSize, sizeof(NONCLIENTMETRICSW));
1478             /* FIXME: SetLastError? */
1479             ret = FALSE;
1480         }
1481         break;
1482     }
1483     WINE_SPI_FIXME(SPI_SETNONCLIENTMETRICS);    /*     42  WINVER >= 0x400 */
1484
1485     case SPI_GETMINIMIZEDMETRICS:               /*     43  WINVER >= 0x400 */
1486     {
1487         MINIMIZEDMETRICS * lpMm = pvParam;
1488         if (lpMm && lpMm->cbSize == sizeof(*lpMm))
1489         {
1490             /* these taken from Win2k SP3 */
1491             lpMm->iWidth = 154;
1492             lpMm->iHorzGap = 0;
1493             lpMm->iVertGap = 0;
1494             lpMm->iArrange = 8;
1495         }
1496         else
1497             ret = FALSE;
1498         break;
1499     }
1500     WINE_SPI_FIXME(SPI_SETMINIMIZEDMETRICS);    /*     44  WINVER >= 0x400 */
1501
1502     case SPI_GETICONMETRICS:                    /*     45  WINVER >= 0x400 */
1503     {
1504         LPICONMETRICSW lpIcon = pvParam;
1505         if(lpIcon && lpIcon->cbSize == sizeof(*lpIcon))
1506         {
1507             SystemParametersInfoW( SPI_ICONHORIZONTALSPACING, 0,
1508                                    &lpIcon->iHorzSpacing, FALSE );
1509             SystemParametersInfoW( SPI_ICONVERTICALSPACING, 0,
1510                                    &lpIcon->iVertSpacing, FALSE );
1511             SystemParametersInfoW( SPI_GETICONTITLEWRAP, 0,
1512                                    &lpIcon->iTitleWrap, FALSE );
1513             SystemParametersInfoW( SPI_GETICONTITLELOGFONT, 0,
1514                                    &lpIcon->lfFont, FALSE );
1515         }
1516         else
1517         {
1518             ret = FALSE;
1519         }
1520         break;
1521     }
1522     WINE_SPI_FIXME(SPI_SETICONMETRICS);         /*     46  WINVER >= 0x400 */
1523
1524     case SPI_SETWORKAREA:                       /*     47  WINVER >= 0x400 */
1525     {
1526         static const WCHAR CSld[]={'%','l','d',' ','%','l','d',' ','%','l','d',' ','%','l','d',0};
1527         WCHAR buf[20];
1528         RECT *pr = (RECT *) pvParam;
1529
1530         if (!pvParam) return FALSE;
1531
1532         spi_idx = SPI_SETWORKAREA_IDX;
1533         wsprintfW(buf, CSld, pr->left, pr->top,
1534                 pr->right, pr->bottom );
1535
1536         if (SYSPARAMS_Save( SPI_SETWORKAREA_REGKEY,
1537                             SPI_SETWORKAREA_VALNAME,
1538                             buf, fWinIni ))
1539         {
1540             CopyRect( &work_area, (RECT *)pvParam );
1541             spi_loaded[spi_idx] = TRUE;
1542         }
1543         else
1544             ret = FALSE;
1545         break;
1546     }
1547
1548     case SPI_GETWORKAREA:                       /*     48  WINVER >= 0x400 */
1549         if (!pvParam) return FALSE;
1550
1551       spi_idx = SPI_SETWORKAREA_IDX;
1552       if (!spi_loaded[spi_idx])
1553       {
1554           WCHAR buf[20];
1555
1556           SetRect( &work_area, 0, 0,
1557                    GetSystemMetrics( SM_CXSCREEN ),
1558                    GetSystemMetrics( SM_CYSCREEN ) );
1559
1560           if (SYSPARAMS_Load( SPI_SETWORKAREA_REGKEY,
1561                               SPI_SETWORKAREA_VALNAME,
1562                               buf, sizeof(buf) ))
1563           {
1564               char tmpbuf[20];
1565               WideCharToMultiByte( CP_ACP, 0, buf, -1,
1566                                    tmpbuf, sizeof(tmpbuf), NULL, NULL );
1567               sscanf( tmpbuf, "%ld %ld %ld %ld",
1568                       &work_area.left, &work_area.top,
1569                       &work_area.right, &work_area.bottom );
1570           }
1571           spi_loaded[spi_idx] = TRUE;
1572       }
1573       CopyRect( (RECT *)pvParam, &work_area );
1574
1575       break;
1576
1577     WINE_SPI_FIXME(SPI_SETPENWINDOWS);          /*     49  WINVER >= 0x400 */
1578
1579     case SPI_GETFILTERKEYS:                     /*     50 */
1580     {
1581         LPFILTERKEYS lpFilterKeys = (LPFILTERKEYS)pvParam;
1582         WARN("SPI_GETFILTERKEYS not fully implemented\n");
1583         if (lpFilterKeys && lpFilterKeys->cbSize == sizeof(FILTERKEYS))
1584         {
1585             /* Indicate that no FilterKeys feature available */
1586             lpFilterKeys->dwFlags = 0;
1587             lpFilterKeys->iWaitMSec = 0;
1588             lpFilterKeys->iDelayMSec = 0;
1589             lpFilterKeys->iRepeatMSec = 0;
1590             lpFilterKeys->iBounceMSec = 0;
1591          }
1592         else
1593         {
1594             ret = FALSE;
1595         }
1596         break;
1597     }
1598     WINE_SPI_FIXME(SPI_SETFILTERKEYS);          /*     51 */
1599
1600     case SPI_GETTOGGLEKEYS:                     /*     52 */
1601     {
1602         LPTOGGLEKEYS lpToggleKeys = (LPTOGGLEKEYS)pvParam;
1603         WARN("SPI_GETTOGGLEKEYS not fully implemented\n");
1604         if (lpToggleKeys && lpToggleKeys->cbSize == sizeof(TOGGLEKEYS))
1605         {
1606             /* Indicate that no ToggleKeys feature available */
1607             lpToggleKeys->dwFlags = 0;
1608         }
1609         else
1610         {
1611             ret = FALSE;
1612         }
1613         break;
1614     }
1615     WINE_SPI_FIXME(SPI_SETTOGGLEKEYS);          /*     53 */
1616
1617     case SPI_GETMOUSEKEYS:                      /*     54 */
1618     {
1619         LPMOUSEKEYS lpMouseKeys = (LPMOUSEKEYS)pvParam;
1620         WARN("SPI_GETMOUSEKEYS not fully implemented\n");
1621         if (lpMouseKeys && lpMouseKeys->cbSize == sizeof(MOUSEKEYS))
1622         {
1623             /* Indicate that no MouseKeys feature available */
1624             lpMouseKeys->dwFlags = 0;
1625             lpMouseKeys->iMaxSpeed = 360;
1626             lpMouseKeys->iTimeToMaxSpeed = 1000;
1627             lpMouseKeys->iCtrlSpeed = 0;
1628             lpMouseKeys->dwReserved1 = 0;
1629             lpMouseKeys->dwReserved2 = 0;
1630         }
1631         else
1632         {
1633             ret = FALSE;
1634         }
1635         break;
1636     }
1637     WINE_SPI_FIXME(SPI_SETMOUSEKEYS);           /*     55 */
1638
1639     case SPI_GETSHOWSOUNDS:                     /*     56 */
1640         if (!pvParam) return FALSE;
1641
1642         spi_idx = SPI_SETSHOWSOUNDS_IDX;
1643
1644         if (!spi_loaded[spi_idx])
1645         {
1646             WCHAR buf[10];
1647
1648             if (SYSPARAMS_Load( SPI_SETSHOWSOUNDS_REGKEY,
1649                                 SPI_SETSHOWSOUNDS_VALNAME, buf, sizeof(buf) ))
1650             {
1651                 sysMetrics[SM_SHOWSOUNDS] = atoiW( buf );
1652             }
1653             spi_loaded[spi_idx] = TRUE;
1654         }
1655
1656         *(INT *)pvParam = sysMetrics[SM_SHOWSOUNDS];
1657         break;
1658
1659     case SPI_SETSHOWSOUNDS:                     /*     57 */
1660     {
1661         WCHAR buf[10];
1662         spi_idx = SPI_SETSHOWSOUNDS_IDX;
1663
1664         wsprintfW(buf, CSu, uiParam);
1665         if (SYSPARAMS_Save( SPI_SETSHOWSOUNDS_REGKEY,
1666                             SPI_SETSHOWSOUNDS_VALNAME,
1667                             buf, fWinIni ))
1668         {
1669             sysMetrics[SM_SHOWSOUNDS] = uiParam;
1670             spi_loaded[spi_idx] = TRUE;
1671         }
1672         else
1673             ret = FALSE;
1674         break;
1675     }
1676
1677     case SPI_GETSTICKYKEYS:                     /*     58 */
1678     {
1679         LPSTICKYKEYS lpStickyKeys = (LPSTICKYKEYS)pvParam;
1680         WARN("SPI_GETSTICKYKEYS not fully implemented\n");
1681         if (lpStickyKeys && lpStickyKeys->cbSize == sizeof(STICKYKEYS))
1682         {
1683             /* Indicate that no StickyKeys feature available */
1684             lpStickyKeys->dwFlags = 0;
1685         }
1686         else
1687         {
1688             ret = FALSE;
1689         }
1690         break;
1691     }
1692     WINE_SPI_FIXME(SPI_SETSTICKYKEYS);          /*     59 */
1693
1694     case SPI_GETACCESSTIMEOUT:                  /*     60 */
1695     {
1696         LPACCESSTIMEOUT lpAccessTimeout = (LPACCESSTIMEOUT)pvParam;
1697         WARN("SPI_GETACCESSTIMEOUT not fully implemented\n");
1698         if (lpAccessTimeout && lpAccessTimeout->cbSize == sizeof(ACCESSTIMEOUT))
1699         {
1700             /* Indicate that no accessibility features timeout is available */
1701             lpAccessTimeout->dwFlags = 0;
1702             lpAccessTimeout->iTimeOutMSec = 0;
1703         }
1704         else
1705         {
1706             ret = FALSE;
1707         }
1708         break;
1709     }
1710     WINE_SPI_FIXME(SPI_SETACCESSTIMEOUT);       /*     61 */
1711
1712     case SPI_GETSERIALKEYS:                     /*     62  WINVER >= 0x400 */
1713     {
1714         LPSERIALKEYSW lpSerialKeysW = (LPSERIALKEYSW)pvParam;
1715         WARN("SPI_GETSERIALKEYS not fully implemented\n");
1716         if (lpSerialKeysW && lpSerialKeysW->cbSize == sizeof(SERIALKEYSW))
1717         {
1718             /* Indicate that no SerialKeys feature available */
1719             lpSerialKeysW->dwFlags = 0;
1720             lpSerialKeysW->lpszActivePort = NULL;
1721             lpSerialKeysW->lpszPort = NULL;
1722             lpSerialKeysW->iBaudRate = 0;
1723             lpSerialKeysW->iPortState = 0;
1724         }
1725         else
1726         {
1727             ret = FALSE;
1728         }
1729         break;
1730     }
1731     WINE_SPI_FIXME(SPI_SETSERIALKEYS);          /*     63  WINVER >= 0x400 */
1732
1733     case SPI_GETSOUNDSENTRY:                    /*     64 */
1734     {
1735         LPSOUNDSENTRYW lpSoundSentryW = (LPSOUNDSENTRYW)pvParam;
1736         WARN("SPI_GETSOUNDSENTRY not fully implemented\n");
1737         if (lpSoundSentryW && lpSoundSentryW->cbSize == sizeof(SOUNDSENTRYW))
1738         {
1739             /* Indicate that no SoundSentry feature available */
1740             lpSoundSentryW->dwFlags = 0;
1741             lpSoundSentryW->iFSTextEffect = 0;
1742             lpSoundSentryW->iFSTextEffectMSec = 0;
1743             lpSoundSentryW->iFSTextEffectColorBits = 0;
1744             lpSoundSentryW->iFSGrafEffect = 0;
1745             lpSoundSentryW->iFSGrafEffectMSec = 0;
1746             lpSoundSentryW->iFSGrafEffectColor = 0;
1747             lpSoundSentryW->iWindowsEffect = 0;
1748             lpSoundSentryW->iWindowsEffectMSec = 0;
1749             lpSoundSentryW->lpszWindowsEffectDLL = 0;
1750             lpSoundSentryW->iWindowsEffectOrdinal = 0;
1751         }
1752         else
1753         {
1754             ret = FALSE;
1755         }
1756         break;
1757     }
1758     WINE_SPI_FIXME(SPI_SETSOUNDSENTRY);         /*     65 */
1759
1760     case SPI_GETHIGHCONTRAST:                   /*     66  WINVER >= 0x400 */
1761     {
1762         LPHIGHCONTRASTW lpHighContrastW = (LPHIGHCONTRASTW)pvParam;
1763         WARN("SPI_GETHIGHCONTRAST not fully implemented\n");
1764         if (lpHighContrastW && lpHighContrastW->cbSize == sizeof(HIGHCONTRASTW))
1765         {
1766             /* Indicate that no high contrast feature available */
1767             lpHighContrastW->dwFlags = 0;
1768             lpHighContrastW->lpszDefaultScheme = NULL;
1769         }
1770         else
1771         {
1772             ret = FALSE;
1773         }
1774         break;
1775     }
1776     WINE_SPI_FIXME(SPI_SETHIGHCONTRAST);        /*     67  WINVER >= 0x400 */
1777
1778     case SPI_GETKEYBOARDPREF:                   /*     68  WINVER >= 0x400 */
1779         if (!pvParam) return FALSE;
1780
1781         spi_idx = SPI_SETKEYBOARDPREF_IDX;
1782         if (!spi_loaded[spi_idx])
1783         {
1784             WCHAR buf[5];
1785
1786             if (SYSPARAMS_Load( SPI_SETKEYBOARDPREF_REGKEY,
1787                                 SPI_SETKEYBOARDPREF_VALNAME, buf, sizeof(buf) ))
1788                 keyboard_pref  = atoiW(buf);
1789             spi_loaded[spi_idx] = TRUE;
1790         }
1791
1792         *(BOOL *)pvParam = keyboard_pref;
1793         break;
1794
1795     case SPI_SETKEYBOARDPREF:                   /*     69  WINVER >= 0x400 */
1796     {
1797         WCHAR buf[5];
1798
1799         spi_idx = SPI_SETKEYBOARDPREF_IDX;
1800         wsprintfW(buf, CSu, uiParam);
1801         if (SYSPARAMS_Save( SPI_SETKEYBOARDPREF_REGKEY,
1802                             SPI_SETKEYBOARDPREF_VALNAME,
1803                             buf, fWinIni ))
1804         {
1805             keyboard_pref = uiParam;
1806             spi_loaded[spi_idx] = TRUE;
1807         }
1808         else
1809             ret = FALSE;
1810         break;
1811     }
1812
1813     case SPI_GETSCREENREADER:                   /*     70  WINVER >= 0x400 */
1814         if (!pvParam) return FALSE;
1815
1816         spi_idx = SPI_SETSCREENREADER_IDX;
1817         if (!spi_loaded[spi_idx])
1818         {
1819             WCHAR buf[5];
1820
1821             if (SYSPARAMS_Load( SPI_SETSCREENREADER_REGKEY,
1822                                 SPI_SETSCREENREADER_VALNAME, buf, sizeof(buf) ))
1823                 screen_reader  = atoiW(buf);
1824             spi_loaded[spi_idx] = TRUE;
1825         }
1826
1827         *(BOOL *)pvParam = screen_reader;
1828         break;
1829
1830     case SPI_SETSCREENREADER:                   /*     71  WINVER >= 0x400 */
1831     {
1832         WCHAR buf[5];
1833
1834         spi_idx = SPI_SETSCREENREADER_IDX;
1835         wsprintfW(buf, CSu, uiParam);
1836         if (SYSPARAMS_Save( SPI_SETSCREENREADER_REGKEY,
1837                             SPI_SETSCREENREADER_VALNAME,
1838                             buf, fWinIni ))
1839         {
1840             screen_reader = uiParam;
1841             spi_loaded[spi_idx] = TRUE;
1842         }
1843         else
1844             ret = FALSE;
1845         break;
1846     }
1847
1848     case SPI_GETANIMATION:                      /*     72  WINVER >= 0x400 */
1849     {
1850         LPANIMATIONINFO lpAnimInfo = (LPANIMATIONINFO)pvParam;
1851
1852         /* Tell it "disabled" */
1853         if (lpAnimInfo && lpAnimInfo->cbSize == sizeof(ANIMATIONINFO))
1854             lpAnimInfo->iMinAnimate = 0; /* Minimise and restore animation is disabled (nonzero == enabled) */
1855         else
1856             ret = FALSE;
1857         break;
1858     }
1859     WINE_SPI_WARN(SPI_SETANIMATION);            /*     73  WINVER >= 0x400 */
1860
1861     case SPI_GETFONTSMOOTHING:    /*     74  WINVER >= 0x400 */
1862         if (!pvParam) return FALSE;
1863
1864         spi_idx = SPI_SETFONTSMOOTHING_IDX;
1865         if (!spi_loaded[spi_idx])
1866         {
1867             WCHAR buf[5];
1868
1869             if (SYSPARAMS_Load( SPI_SETFONTSMOOTHING_REGKEY,
1870                                 SPI_SETFONTSMOOTHING_VALNAME, buf, sizeof(buf) ))
1871             {
1872                 spi_loaded[spi_idx] = TRUE;
1873                 if (buf[0] == 0x01 || buf[0] == 0x02) /* 0x01 for 95/98/NT, 0x02 for 98/ME/2k/XP */
1874                 {
1875                     font_smoothing = TRUE;
1876                 }
1877             }
1878         }
1879
1880         *(BOOL *)pvParam = font_smoothing;
1881
1882         break;
1883
1884     WINE_SPI_FIXME(SPI_SETFONTSMOOTHING);       /*     75  WINVER >= 0x400 */
1885
1886     WINE_SPI_FIXME(SPI_SETDRAGWIDTH);           /*     76  WINVER >= 0x400 */
1887     WINE_SPI_FIXME(SPI_SETDRAGHEIGHT);          /*     77  WINVER >= 0x400 */
1888
1889     WINE_SPI_FIXME(SPI_SETHANDHELD);            /*     78  WINVER >= 0x400 */
1890
1891     WINE_SPI_FIXME(SPI_GETLOWPOWERTIMEOUT);     /*     79  WINVER >= 0x400 */
1892     WINE_SPI_FIXME(SPI_GETPOWEROFFTIMEOUT);     /*     80  WINVER >= 0x400 */
1893     WINE_SPI_FIXME(SPI_SETLOWPOWERTIMEOUT);     /*     81  WINVER >= 0x400 */
1894     WINE_SPI_FIXME(SPI_SETPOWEROFFTIMEOUT);     /*     82  WINVER >= 0x400 */
1895
1896     case SPI_GETLOWPOWERACTIVE:                 /*     83  WINVER >= 0x400 */
1897         if (!pvParam)
1898         {
1899             SetLastError(ERROR_INVALID_PARAMETER);
1900             return FALSE;
1901         }
1902         if (!spi_loaded[SPI_GETLOWPOWERACTIVE])
1903         {
1904             WCHAR buf[5];
1905             if(SYSPARAMS_Load(SPI_GETLOPOWERACTIVE_REGKEY, SPI_GETLOPOWERACTIVE_VALNAME, buf, sizeof(buf)))
1906             {
1907                 spi_loaded[SPI_GETLOWPOWERACTIVE] = TRUE;
1908                 lowpoweractive = atoiW(buf);
1909             }
1910             else ret=FALSE;
1911         }
1912         *(BOOL *)pvParam = lowpoweractive;
1913         break;
1914
1915     WINE_SPI_FIXME(SPI_GETPOWEROFFACTIVE);      /*     84  WINVER >= 0x400 */
1916     WINE_SPI_FIXME(SPI_SETLOWPOWERACTIVE);      /*     85  WINVER >= 0x400 */
1917     WINE_SPI_FIXME(SPI_SETPOWEROFFACTIVE);      /*     86  WINVER >= 0x400 */
1918
1919     WINE_SPI_FIXME(SPI_SETCURSORS);             /*     87  WINVER >= 0x400 */
1920     WINE_SPI_FIXME(SPI_SETICONS);               /*     88  WINVER >= 0x400 */
1921
1922     case SPI_GETDEFAULTINPUTLANG:       /*     89  WINVER >= 0x400 */
1923         ret = GetKeyboardLayout(0) ? TRUE : FALSE;
1924         break;
1925
1926     WINE_SPI_FIXME(SPI_SETDEFAULTINPUTLANG);    /*     90  WINVER >= 0x400 */
1927
1928     WINE_SPI_FIXME(SPI_SETLANGTOGGLE);          /*     91  WINVER >= 0x400 */
1929
1930     case SPI_GETWINDOWSEXTENSION:               /*     92  WINVER >= 0x400 */
1931         WARN("pretend no support for Win9x Plus! for now.\n");
1932         ret = FALSE; /* yes, this is the result value */
1933         break;
1934
1935     WINE_SPI_FIXME(SPI_SETMOUSETRAILS);         /*     93  WINVER >= 0x400 */
1936     WINE_SPI_FIXME(SPI_GETMOUSETRAILS);         /*     94  WINVER >= 0x400 */
1937
1938     case SPI_SETSCREENSAVERRUNNING:             /*     97  WINVER >= 0x400 */
1939         {
1940         /* SPI_SCREENSAVERRUNNING is an alias for SPI_SETSCREENSAVERRUNNING */
1941         WCHAR buf[5];
1942
1943         spi_idx = SPI_SETSCREENSAVERRUNNING_IDX;
1944         wsprintfW(buf, CSu, uiParam);
1945
1946         /* save only temporarily */
1947         if (SYSPARAMS_Save( SPI_SETSCREENSAVERRUNNING_REGKEY,
1948                             SPI_SETSCREENSAVERRUNNING_VALNAME,
1949                             buf, 0  ))
1950         {
1951             screensaver_running = uiParam;
1952             spi_loaded[spi_idx] = TRUE;
1953         }
1954         else
1955             ret = FALSE;
1956         break;
1957     }
1958
1959     case SPI_GETMOUSEHOVERWIDTH:                /*     98  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
1960         if (!pvParam) return FALSE;
1961
1962         spi_idx = SPI_SETMOUSEHOVERWIDTH_IDX;
1963         if (!spi_loaded[spi_idx])
1964         {
1965             WCHAR buf[10];
1966
1967             if (SYSPARAMS_Load( SPI_SETMOUSEHOVERWIDTH_REGKEY,
1968                                 SPI_SETMOUSEHOVERWIDTH_VALNAME,
1969                                 buf, sizeof(buf) ))
1970                 mouse_hover_width = atoiW( buf );
1971             spi_loaded[spi_idx] = TRUE;
1972         }
1973         *(INT *)pvParam = mouse_hover_width;
1974         break;
1975         
1976     case SPI_SETMOUSEHOVERWIDTH:                /*     99  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
1977     {
1978         WCHAR buf[10];
1979
1980         spi_idx = SPI_SETMOUSEHOVERWIDTH_IDX;
1981         wsprintfW(buf, CSu, uiParam);
1982
1983         if (SYSPARAMS_Save( SPI_SETMOUSEHOVERWIDTH_REGKEY,
1984                             SPI_SETMOUSEHOVERWIDTH_VALNAME,
1985                             buf, fWinIni ))
1986         {
1987             mouse_hover_width = uiParam;
1988             spi_loaded[spi_idx] = TRUE;
1989         }
1990         else
1991             ret = FALSE;
1992         break;
1993     }
1994         
1995     case SPI_GETMOUSEHOVERHEIGHT:               /*    100  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
1996         if (!pvParam) return FALSE;
1997
1998         spi_idx = SPI_SETMOUSEHOVERHEIGHT_IDX;
1999         if (!spi_loaded[spi_idx])
2000         {
2001             WCHAR buf[10];
2002
2003             if (SYSPARAMS_Load( SPI_SETMOUSEHOVERHEIGHT_REGKEY,
2004                                 SPI_SETMOUSEHOVERHEIGHT_VALNAME,
2005                                 buf, sizeof(buf) ))
2006                 mouse_hover_height = atoiW( buf );
2007
2008             spi_loaded[spi_idx] = TRUE;
2009         }
2010         *(INT *)pvParam = mouse_hover_height;
2011         break;
2012
2013     case SPI_SETMOUSEHOVERHEIGHT:               /*    101  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
2014     {
2015         WCHAR buf[10];
2016
2017         spi_idx = SPI_SETMOUSEHOVERHEIGHT_IDX;
2018         wsprintfW(buf, CSu, uiParam);
2019
2020         if (SYSPARAMS_Save( SPI_SETMOUSEHOVERHEIGHT_REGKEY,
2021                             SPI_SETMOUSEHOVERHEIGHT_VALNAME,
2022                             buf, fWinIni ))
2023         {
2024             mouse_hover_height = uiParam;
2025             spi_loaded[spi_idx] = TRUE;
2026         }
2027         else
2028             ret = FALSE;
2029         break;
2030     }
2031     
2032     case SPI_GETMOUSEHOVERTIME:                 /*    102  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
2033         if (!pvParam) return FALSE;
2034
2035         spi_idx = SPI_SETMOUSEHOVERTIME_IDX;
2036         if (!spi_loaded[spi_idx])
2037         {
2038             WCHAR buf[10];
2039
2040             if (SYSPARAMS_Load( SPI_SETMOUSEHOVERTIME_REGKEY,
2041                                 SPI_SETMOUSEHOVERTIME_VALNAME,
2042                                 buf, sizeof(buf) ))
2043                 mouse_hover_time = atoiW( buf );
2044
2045             spi_loaded[spi_idx] = TRUE;
2046         }
2047         *(INT *)pvParam = mouse_hover_time;
2048         break;
2049
2050     case SPI_SETMOUSEHOVERTIME:                 /*    103  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
2051     {
2052         WCHAR buf[10];
2053
2054         spi_idx = SPI_SETMOUSEHOVERTIME_IDX;
2055         wsprintfW(buf, CSu, uiParam);
2056
2057         if (SYSPARAMS_Save( SPI_SETMOUSEHOVERTIME_REGKEY,
2058                             SPI_SETMOUSEHOVERTIME_VALNAME,
2059                             buf, fWinIni ))
2060         {
2061             mouse_hover_time = uiParam;
2062             spi_loaded[spi_idx] = TRUE;
2063         }
2064         else
2065             ret = FALSE;
2066         break;
2067     }
2068     
2069     case SPI_GETWHEELSCROLLLINES:               /*    104  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
2070         if (!pvParam) return FALSE;
2071
2072         spi_idx = SPI_SETMOUSESCROLLLINES_IDX;
2073         if (!spi_loaded[spi_idx])
2074         {
2075             WCHAR buf[10];
2076
2077             if (SYSPARAMS_Load( SPI_SETMOUSESCROLLLINES_REGKEY,
2078                                 SPI_SETMOUSESCROLLLINES_VALNAME,
2079                                 buf, sizeof(buf) ))
2080                 mouse_scroll_lines = atoiW( buf );
2081
2082             spi_loaded[spi_idx] = TRUE;
2083         }
2084         *(INT *)pvParam = mouse_scroll_lines;
2085         break;
2086
2087     case SPI_SETWHEELSCROLLLINES:               /*    105  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
2088     {
2089         WCHAR buf[10];
2090
2091         spi_idx = SPI_SETMOUSESCROLLLINES_IDX;
2092         wsprintfW(buf, CSu, uiParam);
2093
2094         if (SYSPARAMS_Save( SPI_SETMOUSESCROLLLINES_REGKEY,
2095                             SPI_SETMOUSESCROLLLINES_VALNAME,
2096                             buf, fWinIni ))
2097         {
2098             mouse_scroll_lines = uiParam;
2099             spi_loaded[spi_idx] = TRUE;
2100         }
2101         else
2102             ret = FALSE;
2103         break;
2104     }
2105     
2106     case SPI_GETMENUSHOWDELAY:                  /*    106  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
2107         if (!pvParam) return FALSE;
2108
2109         spi_idx = SPI_SETMENUSHOWDELAY_IDX;
2110         if (!spi_loaded[spi_idx])
2111         {
2112             WCHAR buf[10];
2113
2114             if (SYSPARAMS_Load( SPI_SETMENUSHOWDELAY_REGKEY,
2115                                 SPI_SETMENUSHOWDELAY_VALNAME,
2116                                 buf, sizeof(buf) ))
2117                 menu_show_delay = atoiW( buf );
2118
2119             spi_loaded[spi_idx] = TRUE;
2120         }
2121         *(INT *)pvParam = menu_show_delay;
2122         break;
2123
2124     case SPI_SETMENUSHOWDELAY:                  /*    107  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
2125     {
2126         WCHAR buf[10];
2127
2128         spi_idx = SPI_SETMENUSHOWDELAY_IDX;
2129         wsprintfW(buf, CSu, uiParam);
2130
2131         if (SYSPARAMS_Save( SPI_SETMENUSHOWDELAY_REGKEY,
2132                             SPI_SETMENUSHOWDELAY_VALNAME,
2133                             buf, fWinIni ))
2134         {
2135             menu_show_delay = uiParam;
2136             spi_loaded[spi_idx] = TRUE;
2137         }
2138         else
2139             ret = FALSE;
2140         break;
2141     }
2142     
2143     WINE_SPI_FIXME(SPI_GETSHOWIMEUI);           /*    110  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
2144     WINE_SPI_FIXME(SPI_SETSHOWIMEUI);           /*    111  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
2145     WINE_SPI_FIXME(SPI_GETMOUSESPEED);          /*    112  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2146     WINE_SPI_FIXME(SPI_SETMOUSESPEED);          /*    113  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2147
2148     case SPI_GETSCREENSAVERRUNNING:             /*    114  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2149         if (!pvParam) return FALSE;
2150
2151         spi_idx = SPI_SETSCREENSAVERRUNNING_IDX;
2152         if (!spi_loaded[spi_idx])
2153         {
2154             WCHAR buf[5];
2155
2156             if (SYSPARAMS_Load( SPI_SETSCREENSAVERRUNNING_REGKEY,
2157                                 SPI_SETSCREENSAVERRUNNING_VALNAME, buf, sizeof(buf) ))
2158                 screensaver_running  = atoiW( buf );
2159             spi_loaded[spi_idx] = TRUE;
2160         }
2161
2162         *(BOOL *)pvParam = screensaver_running;
2163         break;
2164
2165     case SPI_GETDESKWALLPAPER:                  /*    115  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2166     {
2167         WCHAR buf[MAX_PATH];
2168
2169         if (!pvParam) return FALSE;
2170
2171         if (uiParam > MAX_PATH)
2172         {
2173             uiParam = MAX_PATH;
2174         }
2175
2176         if (SYSPARAMS_Load(SPI_SETDESKWALLPAPER_REGKEY, SPI_SETDESKWALLPAPER_VALNAME, buf, sizeof(buf)))
2177         {
2178             lstrcpynW((WCHAR*)pvParam, buf, uiParam);
2179         }
2180         else
2181         {
2182             /* Return an empty string */
2183             memset((WCHAR*)pvParam, 0, uiParam);
2184         }
2185
2186         break;
2187     }
2188
2189     WINE_SPI_FIXME(SPI_GETACTIVEWINDOWTRACKING);/* 0x1000  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2190     WINE_SPI_FIXME(SPI_SETACTIVEWINDOWTRACKING);/* 0x1001  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2191     WINE_SPI_FIXME(SPI_GETMENUANIMATION);       /* 0x1002  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2192     WINE_SPI_FIXME(SPI_SETMENUANIMATION);       /* 0x1003  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2193     WINE_SPI_FIXME(SPI_GETCOMBOBOXANIMATION);   /* 0x1004  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2194     WINE_SPI_FIXME(SPI_SETCOMBOBOXANIMATION);   /* 0x1005  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2195
2196     case SPI_GETLISTBOXSMOOTHSCROLLING:    /* 0x1006  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2197         if (!pvParam) return FALSE;
2198
2199         spi_idx = SPI_SETLISTBOXSMOOTHSCROLLING_IDX;
2200         if (!spi_loaded[spi_idx])
2201         {
2202             WCHAR buf[5];
2203
2204             if (SYSPARAMS_Load( SPI_SETLISTBOXSMOOTHSCROLLING_REGKEY,
2205                                 SPI_SETLISTBOXSMOOTHSCROLLING_VALNAME, buf, sizeof(buf) ))
2206             {
2207                 if ((buf[0]&0x01) == 0x01)
2208                 {
2209                     listbox_smoothscrolling = TRUE;
2210                 }
2211             }
2212             spi_loaded[spi_idx] = TRUE;
2213         }
2214
2215         *(BOOL *)pvParam = listbox_smoothscrolling;
2216
2217         break;
2218
2219     WINE_SPI_FIXME(SPI_SETLISTBOXSMOOTHSCROLLING);/* 0x1007  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2220
2221     case SPI_GETGRADIENTCAPTIONS:    /* 0x1008  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2222         if (!pvParam) return FALSE;
2223
2224         spi_idx = SPI_SETGRADIENTCAPTIONS_IDX;
2225         if (!spi_loaded[spi_idx])
2226         {
2227             WCHAR buf[5];
2228
2229             if (SYSPARAMS_Load( SPI_USERPREFERENCEMASK_REGKEY,
2230                                 SPI_USERPREFERENCEMASK_VALNAME, buf, sizeof(buf) ))
2231             {
2232                 if ((buf[0]&0x10) == 0x10)
2233                 {
2234                     gradient_captions = TRUE;
2235                 }
2236             }
2237             spi_loaded[spi_idx] = TRUE;
2238         }
2239
2240         *(BOOL *)pvParam = gradient_captions;
2241
2242         break;
2243
2244     WINE_SPI_FIXME(SPI_SETGRADIENTCAPTIONS);    /* 0x1009  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2245
2246     case SPI_GETKEYBOARDCUES:     /* 0x100A  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2247         if (!pvParam) return FALSE;
2248
2249         spi_idx = SPI_SETKEYBOARDCUES_IDX;
2250         if (!spi_loaded[spi_idx])
2251         {
2252             WCHAR buf[5];
2253
2254             if (SYSPARAMS_Load( SPI_USERPREFERENCEMASK_REGKEY,
2255                                 SPI_USERPREFERENCEMASK_VALNAME, buf, sizeof(buf) ))
2256             {
2257                 if ((buf[0]&0x20) == 0x20)
2258                 {
2259                     keyboard_cues = TRUE;
2260                 }
2261             }
2262             spi_loaded[spi_idx] = TRUE;
2263         }
2264
2265         *(BOOL *)pvParam = keyboard_cues;
2266
2267         break;
2268
2269     WINE_SPI_FIXME(SPI_SETKEYBOARDCUES);        /* 0x100B  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2270     WINE_SPI_FIXME(SPI_GETACTIVEWNDTRKZORDER);  /* 0x100C  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2271     WINE_SPI_FIXME(SPI_SETACTIVEWNDTRKZORDER);  /* 0x100D  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2272     case SPI_GETHOTTRACKING:    /* 0x100E  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2273         if (!pvParam) return FALSE;
2274
2275         spi_idx = SPI_SETHOTTRACKING_IDX;
2276         if (!spi_loaded[spi_idx])
2277         {
2278             WCHAR buf[5];
2279
2280             if (SYSPARAMS_Load( SPI_USERPREFERENCEMASK_REGKEY,
2281                                 SPI_USERPREFERENCEMASK_VALNAME, buf, sizeof(buf) ))
2282             {
2283                 if ((buf[0]&0x80) == 0x80)
2284                 {
2285                     hot_tracking = TRUE;
2286                 }
2287             }
2288             spi_loaded[spi_idx] = TRUE;
2289         }
2290
2291         *(BOOL *)pvParam = hot_tracking;
2292
2293         break;
2294
2295     WINE_SPI_FIXME(SPI_SETHOTTRACKING);         /* 0x100F  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2296     WINE_SPI_FIXME(SPI_GETSELECTIONFADE);       /* 0x1014  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2297     WINE_SPI_FIXME(SPI_SETSELECTIONFADE);       /* 0x1015  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2298     WINE_SPI_FIXME(SPI_GETDROPSHADOW);          /* 0x1024  _WIN32_WINNT >= 0x510 */
2299     WINE_SPI_FIXME(SPI_SETDROPSHADOW);          /* 0x1025  _WIN32_WINNT >= 0x510 */
2300     WINE_SPI_FIXME(SPI_GETFOREGROUNDLOCKTIMEOUT);/* 0x2000  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2301     WINE_SPI_FIXME(SPI_SETFOREGROUNDLOCKTIMEOUT);/* 0x2001  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2302     WINE_SPI_FIXME(SPI_GETACTIVEWNDTRKTIMEOUT); /* 0x2002  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2303     WINE_SPI_FIXME(SPI_SETACTIVEWNDTRKTIMEOUT); /* 0x2003  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2304     WINE_SPI_FIXME(SPI_GETFOREGROUNDFLASHCOUNT);/* 0x2004  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2305     WINE_SPI_FIXME(SPI_SETFOREGROUNDFLASHCOUNT);/* 0x2005  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2306     WINE_SPI_FIXME(SPI_GETCARETWIDTH);          /* 0x2006  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2307     WINE_SPI_FIXME(SPI_SETCARETWIDTH);          /* 0x2007  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2308     WINE_SPI_FIXME(SPI_GETMOUSECLICKLOCKTIME);  /* 0x2008  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2309     WINE_SPI_FIXME(SPI_SETMOUSECLICKLOCKTIME);  /* 0x2009  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2310     WINE_SPI_FIXME(SPI_GETFONTSMOOTHINGTYPE);   /* 0x200A  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2311     WINE_SPI_FIXME(SPI_SETFONTSMOOTHINGTYPE);   /* 0x200B  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2312
2313     default:
2314         FIXME( "Unknown action: %u\n", uiAction );
2315         SetLastError( ERROR_INVALID_SPI_VALUE );
2316         ret = FALSE;
2317         break;
2318     }
2319
2320     if (ret)
2321         SYSPARAMS_NotifyChange( uiAction, fWinIni );
2322     return ret;
2323
2324 #undef WINE_SPI_FIXME
2325 #undef WINE_SPI_WARN
2326 }
2327
2328
2329 /***********************************************************************
2330  *              SystemParametersInfo (USER.483)
2331  */
2332 BOOL16 WINAPI SystemParametersInfo16( UINT16 uAction, UINT16 uParam,
2333                                       LPVOID lpvParam, UINT16 fuWinIni )
2334 {
2335     BOOL16 ret;
2336
2337     TRACE("(%u, %u, %p, %u)\n", uAction, uParam, lpvParam, fuWinIni);
2338
2339     switch (uAction)
2340     {
2341     case SPI_GETBEEP:                           /*      1 */
2342     case SPI_GETSCREENSAVEACTIVE:               /*     16 */
2343     case SPI_GETICONTITLEWRAP:                  /*     25 */
2344     case SPI_GETMENUDROPALIGNMENT:              /*     27 */
2345     case SPI_GETFASTTASKSWITCH:                 /*     35 */
2346     case SPI_GETDRAGFULLWINDOWS:                /*     38  WINVER >= 0x0400 */
2347     {
2348         BOOL tmp;
2349         ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
2350         if (ret && lpvParam)
2351             *(BOOL16 *)lpvParam = tmp;
2352         break;
2353     }
2354
2355     case SPI_GETBORDER:                         /*      5 */
2356     case SPI_ICONHORIZONTALSPACING:             /*     13 */
2357     case SPI_GETSCREENSAVETIMEOUT:              /*     14 */
2358     case SPI_GETGRIDGRANULARITY:                /*     18 */
2359     case SPI_GETKEYBOARDDELAY:                  /*     22 */
2360     case SPI_ICONVERTICALSPACING:               /*     24 */
2361     {
2362         INT tmp;
2363         ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
2364         if (ret && lpvParam)
2365             *(INT16 *)lpvParam = tmp;
2366         break;
2367     }
2368
2369     case SPI_GETKEYBOARDSPEED:                  /*     10 */
2370     {
2371         DWORD tmp;
2372         ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
2373         if (ret && lpvParam)
2374             *(WORD *)lpvParam = tmp;
2375         break;
2376     }
2377
2378     case SPI_GETICONTITLELOGFONT:               /*     31 */
2379     {
2380         LOGFONTA tmp;
2381         ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
2382         if (ret && lpvParam)
2383             SYSPARAMS_LogFont32ATo16( &tmp, (LPLOGFONT16)lpvParam );
2384         break;
2385     }
2386
2387     case SPI_GETNONCLIENTMETRICS:               /*     41  WINVER >= 0x400 */
2388     {
2389         NONCLIENTMETRICSA tmp;
2390         LPNONCLIENTMETRICS16 lpnm16 = (LPNONCLIENTMETRICS16)lpvParam;
2391         if (lpnm16 && lpnm16->cbSize == sizeof(NONCLIENTMETRICS16))
2392         {
2393             tmp.cbSize = sizeof(NONCLIENTMETRICSA);
2394             ret = SystemParametersInfoA( uAction, uParam, &tmp, fuWinIni );
2395             if (ret)
2396                 SYSPARAMS_NonClientMetrics32ATo16( &tmp, lpnm16 );
2397         }
2398         else /* winfile 95 sets cbSize to 340 */
2399             ret = SystemParametersInfoA( uAction, uParam, lpvParam, fuWinIni );
2400         break;
2401     }
2402
2403     case SPI_GETWORKAREA:                       /*     48  WINVER >= 0x400 */
2404     {
2405         RECT tmp;
2406         ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
2407         if (ret && lpvParam)
2408         {
2409             RECT16 *r16 = (RECT16 *)lpvParam;
2410             r16->left   = tmp.left;
2411             r16->top    = tmp.top;
2412             r16->right  = tmp.right;
2413             r16->bottom = tmp.bottom;
2414         }
2415         break;
2416     }
2417
2418     case SPI_GETMOUSEHOVERWIDTH:                /*     98  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
2419     case SPI_GETMOUSEHOVERHEIGHT:               /*    100  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
2420     case SPI_GETMOUSEHOVERTIME:                 /*    102  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
2421     {
2422         UINT tmp;
2423         ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
2424         if (ret && lpvParam)
2425             *(UINT16 *)lpvParam = tmp;
2426         break;
2427     }
2428
2429     default:
2430         ret = SystemParametersInfoA( uAction, uParam, lpvParam, fuWinIni );
2431     }
2432
2433     return ret;
2434 }
2435
2436 /***********************************************************************
2437  *              SystemParametersInfoA (USER32.@)
2438  */
2439 BOOL WINAPI SystemParametersInfoA( UINT uiAction, UINT uiParam,
2440                                    PVOID pvParam, UINT fuWinIni )
2441 {
2442     BOOL ret;
2443
2444     TRACE("(%u, %u, %p, %u)\n", uiAction, uiParam, pvParam, fuWinIni);
2445
2446     switch (uiAction)
2447     {
2448     case SPI_SETDESKWALLPAPER:                  /*     20 */
2449     case SPI_SETDESKPATTERN:                    /*     21 */
2450     {
2451         WCHAR buffer[256];
2452         if (pvParam)
2453             if (!MultiByteToWideChar( CP_ACP, 0, (LPSTR)pvParam, -1,
2454                                       buffer, sizeof(buffer)/sizeof(WCHAR) ))
2455                 buffer[sizeof(buffer)/sizeof(WCHAR)-1] = 0;
2456         ret = SystemParametersInfoW( uiAction, uiParam, pvParam ? buffer : NULL, fuWinIni );
2457         break;
2458     }
2459
2460     case SPI_GETICONTITLELOGFONT:               /*     31 */
2461     {
2462         LOGFONTW tmp;
2463         ret = SystemParametersInfoW( uiAction, uiParam, pvParam ? &tmp : NULL, fuWinIni );
2464         if (ret && pvParam)
2465             SYSPARAMS_LogFont32WTo32A( &tmp, (LPLOGFONTA)pvParam );
2466         break;
2467     }
2468
2469     case SPI_GETNONCLIENTMETRICS:               /*     41  WINVER >= 0x400 */
2470     {
2471         NONCLIENTMETRICSW tmp;
2472         LPNONCLIENTMETRICSA lpnmA = (LPNONCLIENTMETRICSA)pvParam;
2473         if (lpnmA && lpnmA->cbSize == sizeof(NONCLIENTMETRICSA))
2474         {
2475             tmp.cbSize = sizeof(NONCLIENTMETRICSW);
2476             ret = SystemParametersInfoW( uiAction, uiParam, &tmp, fuWinIni );
2477             if (ret)
2478                 SYSPARAMS_NonClientMetrics32WTo32A( &tmp, lpnmA );
2479         }
2480         else
2481             ret = FALSE;
2482         break;
2483     }
2484
2485     case SPI_GETICONMETRICS:                    /*     45  WINVER >= 0x400 */
2486     {
2487         ICONMETRICSW tmp;
2488         LPICONMETRICSA lpimA = (LPICONMETRICSA)pvParam;
2489         if (lpimA && lpimA->cbSize == sizeof(ICONMETRICSA))
2490         {
2491             tmp.cbSize = sizeof(ICONMETRICSW);
2492             ret = SystemParametersInfoW( uiAction, uiParam, &tmp, fuWinIni );
2493             if (ret)
2494             {
2495                 lpimA->iHorzSpacing = tmp.iHorzSpacing;
2496                 lpimA->iVertSpacing = tmp.iVertSpacing;
2497                 lpimA->iTitleWrap   = tmp.iTitleWrap;
2498                 SYSPARAMS_LogFont32WTo32A( &tmp.lfFont, &lpimA->lfFont );
2499             }
2500         }
2501         else
2502             ret = FALSE;
2503         break;
2504     }
2505
2506     case SPI_GETHIGHCONTRAST:                   /*     66  WINVER >= 0x400 */
2507     {
2508         HIGHCONTRASTW tmp;
2509         LPHIGHCONTRASTA lphcA = (LPHIGHCONTRASTA)pvParam;
2510         if (lphcA && lphcA->cbSize == sizeof(HIGHCONTRASTA))
2511         {
2512             tmp.cbSize = sizeof(HIGHCONTRASTW);
2513             ret = SystemParametersInfoW( uiAction, uiParam, &tmp, fuWinIni );
2514             if (ret)
2515             {
2516                 lphcA->dwFlags = tmp.dwFlags;
2517                 lphcA->lpszDefaultScheme = NULL;  /* FIXME? */
2518             }
2519         }
2520         else
2521             ret = FALSE;
2522         break;
2523     }
2524
2525     default:
2526         ret = SystemParametersInfoW( uiAction, uiParam, pvParam, fuWinIni );
2527         break;
2528     }
2529     return ret;
2530 }
2531
2532
2533 /***********************************************************************
2534  *              GetSystemMetrics (USER32.@)
2535  */
2536 INT WINAPI GetSystemMetrics( INT index )
2537 {
2538     /* some metrics are dynamic */
2539     switch (index)
2540     {
2541     case SM_CXSCREEN:
2542     case SM_CXFULLSCREEN:
2543     case SM_CXVIRTUALSCREEN:
2544         return GetDeviceCaps( display_dc, HORZRES );
2545     case SM_CYSCREEN:
2546     case SM_CYVIRTUALSCREEN:
2547         return GetDeviceCaps( display_dc, VERTRES );
2548     case SM_CYFULLSCREEN:
2549         return GetDeviceCaps( display_dc, VERTRES ) - sysMetrics[SM_CYCAPTION];
2550
2551     /* FIXME: How do I calculate these? */
2552     case SM_CXMAXTRACK:
2553         return GetDeviceCaps( display_dc, HORZRES ) + 4 + 2 * sysMetrics[SM_CXFRAME];
2554     case SM_CYMAXTRACK:
2555         return GetDeviceCaps( display_dc, VERTRES ) + 4 + 2 * sysMetrics[SM_CYFRAME];
2556     case SM_CXMAXIMIZED:
2557         return GetDeviceCaps( display_dc, HORZRES ) + 2 * sysMetrics[SM_CXFRAME];
2558     case SM_CYMAXIMIZED:
2559         return GetDeviceCaps( display_dc, VERTRES ) + 2 * sysMetrics[SM_CYFRAME];
2560
2561     default:
2562         if ((index < 0) || (index > SM_CMETRICS)) return 0;
2563         return sysMetrics[index];
2564     }
2565 }
2566
2567
2568 /**********************************************************************
2569  *              SetDoubleClickTime (USER32.@)
2570  */
2571 BOOL WINAPI SetDoubleClickTime( UINT interval )
2572 {
2573     return SystemParametersInfoW(SPI_SETDOUBLECLICKTIME, interval, 0, 0);
2574 }
2575
2576
2577 /**********************************************************************
2578  *              GetDoubleClickTime (USER32.@)
2579  */
2580 UINT WINAPI GetDoubleClickTime(void)
2581 {
2582     WCHAR buf[10];
2583
2584     if (!spi_loaded[SPI_SETDOUBLECLICKTIME_IDX])
2585     {
2586         if (SYSPARAMS_Load( SPI_SETDOUBLECLICKTIME_REGKEY,
2587                             SPI_SETDOUBLECLICKTIME_VALNAME,
2588                             buf, sizeof(buf) ))
2589         {
2590             double_click_time = atoiW( buf );
2591             if (!double_click_time) double_click_time = 500;
2592         }
2593         spi_loaded[SPI_SETDOUBLECLICKTIME_IDX] = TRUE;
2594     }
2595     return double_click_time;
2596 }