user32: Downgrade a FIXME to a WARN.
[wine] / dlls / user32 / 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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
29 #define NONAMELESSUNION
30 #define NONAMELESSSTRUCT
31
32 #include "windef.h"
33 #include "winbase.h"
34 #include "winnls.h"
35 #include "wingdi.h"
36 #include "winreg.h"
37 #include "wine/winuser16.h"
38 #include "winerror.h"
39
40 #include "controls.h"
41 #include "user_private.h"
42 #include "wine/unicode.h"
43 #include "wine/debug.h"
44
45 WINE_DEFAULT_DEBUG_CHANNEL(system);
46
47 /* System parameter indexes */
48 enum spi_index
49 {
50     SPI_SETBEEP_IDX,
51     SPI_SETMOUSE_IDX,
52     SPI_SETBORDER_IDX,
53     SPI_SETKEYBOARDSPEED_IDX,
54     SPI_ICONHORIZONTALSPACING_IDX,
55     SPI_SETSCREENSAVETIMEOUT_IDX,
56     SPI_SETGRIDGRANULARITY_IDX,
57     SPI_SETKEYBOARDDELAY_IDX,
58     SPI_ICONVERTICALSPACING_IDX,
59     SPI_SETICONTITLEWRAP_IDX,
60     SPI_SETMENUDROPALIGNMENT_IDX,
61     SPI_SETDOUBLECLKWIDTH_IDX,
62     SPI_SETDOUBLECLKHEIGHT_IDX,
63     SPI_SETDOUBLECLICKTIME_IDX,
64     SPI_SETMOUSEBUTTONSWAP_IDX,
65     SPI_SETDRAGFULLWINDOWS_IDX,
66     SPI_SETWORKAREA_IDX,
67     SPI_SETSHOWSOUNDS_IDX,
68     SPI_SETKEYBOARDPREF_IDX,
69     SPI_SETSCREENREADER_IDX,
70     SPI_SETSCREENSAVERRUNNING_IDX,
71     SPI_SETFONTSMOOTHING_IDX,
72     SPI_SETLISTBOXSMOOTHSCROLLING_IDX,
73     SPI_SETMOUSEHOVERWIDTH_IDX,
74     SPI_SETMOUSEHOVERHEIGHT_IDX,
75     SPI_SETMOUSEHOVERTIME_IDX,
76     SPI_SETMOUSESCROLLCHARS_IDX,
77     SPI_SETMOUSESCROLLLINES_IDX,
78     SPI_SETMENUSHOWDELAY_IDX,
79     SPI_SETICONTITLELOGFONT_IDX,
80     SPI_SETLOWPOWERACTIVE_IDX,
81     SPI_SETSNAPTODEFBUTTON_IDX,
82     SPI_SETPOWEROFFACTIVE_IDX,
83     SPI_USERPREFERENCEMASK_IDX,
84     SPI_NONCLIENTMETRICS_IDX,
85     SPI_MINIMIZEDMETRICS_IDX,
86     SPI_SETFOREGROUNDLOCKTIMEOUT_IDX,
87     SPI_CARETWIDTH_IDX,
88     SPI_SETMOUSESPEED_IDX,
89     SPI_SETFONTSMOOTHINGTYPE_IDX,
90     SPI_SETFONTSMOOTHINGCONTRAST_IDX,
91     SPI_SETFONTSMOOTHINGORIENTATION_IDX,
92     SPI_INDEX_COUNT
93 };
94
95 static const char * const DefSysColors[] =
96 {
97     "Scrollbar", "212 208 200",              /* COLOR_SCROLLBAR */
98     "Background", "58 110 165",              /* COLOR_BACKGROUND */
99     "ActiveTitle", "10 36 106",              /* COLOR_ACTIVECAPTION */
100     "InactiveTitle", "128 128 128",          /* COLOR_INACTIVECAPTION */
101     "Menu", "212 208 200",                   /* COLOR_MENU */
102     "Window", "255 255 255",                 /* COLOR_WINDOW */
103     "WindowFrame", "0 0 0",                  /* COLOR_WINDOWFRAME */
104     "MenuText", "0 0 0",                     /* COLOR_MENUTEXT */
105     "WindowText", "0 0 0",                   /* COLOR_WINDOWTEXT */
106     "TitleText", "255 255 255",              /* COLOR_CAPTIONTEXT */
107     "ActiveBorder", "212 208 200",           /* COLOR_ACTIVEBORDER */
108     "InactiveBorder", "212 208 200",         /* COLOR_INACTIVEBORDER */
109     "AppWorkSpace", "128 128 128",           /* COLOR_APPWORKSPACE */
110     "Hilight", "10 36 106",                  /* COLOR_HIGHLIGHT */
111     "HilightText", "255 255 255",            /* COLOR_HIGHLIGHTTEXT */
112     "ButtonFace", "212 208 200",             /* COLOR_BTNFACE */
113     "ButtonShadow", "128 128 128",           /* COLOR_BTNSHADOW */
114     "GrayText", "128 128 128",               /* COLOR_GRAYTEXT */
115     "ButtonText", "0 0 0",                   /* COLOR_BTNTEXT */
116     "InactiveTitleText", "212 208 200",      /* COLOR_INACTIVECAPTIONTEXT */
117     "ButtonHilight", "255 255 255",          /* COLOR_BTNHIGHLIGHT */
118     "ButtonDkShadow", "64 64 64",            /* COLOR_3DDKSHADOW */
119     "ButtonLight", "212 208 200",            /* COLOR_3DLIGHT */
120     "InfoText", "0 0 0",                     /* COLOR_INFOTEXT */
121     "InfoWindow", "255 255 225",             /* COLOR_INFOBK */
122     "ButtonAlternateFace", "181 181 181",    /* COLOR_ALTERNATEBTNFACE */
123     "HotTrackingColor", "0 0 128",           /* COLOR_HOTLIGHT */
124     "GradientActiveTitle", "166 202 240",    /* COLOR_GRADIENTACTIVECAPTION */
125     "GradientInactiveTitle", "192 192 192",  /* COLOR_GRADIENTINACTIVECAPTION */
126     "MenuHilight", "10 36 106",              /* COLOR_MENUHILIGHT */
127     "MenuBar", "212 208 200"                 /* COLOR_MENUBAR */
128 };
129
130 /**
131  * Names of the registry subkeys of HKEY_CURRENT_USER key and value names
132  * for the system parameters.
133  * Names of the keys are created by adding string "_REGKEY" to
134  * "SET" action names, value names are created by adding "_REG_NAME"
135  * to the "SET" action name.
136  */
137 static const WCHAR SPI_SETBEEP_REGKEY[]=                      {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','S','o','u','n','d',0};
138 static const WCHAR SPI_SETBEEP_VALNAME[]=                     {'B','e','e','p',0};
139 static const WCHAR SPI_SETMOUSE_REGKEY[]=                     {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','M','o','u','s','e',0};
140 static const WCHAR SPI_SETMOUSE_VALNAME1[]=                   {'M','o','u','s','e','T','h','r','e','s','h','o','l','d','1',0};
141 static const WCHAR SPI_SETMOUSE_VALNAME2[]=                   {'M','o','u','s','e','T','h','r','e','s','h','o','l','d','2',0};
142 static const WCHAR SPI_SETMOUSE_VALNAME3[]=                   {'M','o','u','s','e','S','p','e','e','d',0};
143 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','\\',
144                                                                'W','i','n','d','o','w','M','e','t','r','i','c','s',0};
145 static const WCHAR SPI_SETBORDER_VALNAME[]=                   {'B','o','r','d','e','r','W','i','d','t','h',0};
146 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};
147 static const WCHAR SPI_SETKEYBOARDSPEED_VALNAME[]=            {'K','e','y','b','o','a','r','d','S','p','e','e','d',0};
148 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','\\',
149                                                                'W','i','n','d','o','w','M','e','t','r','i','c','s',0};
150 static const WCHAR SPI_ICONHORIZONTALSPACING_VALNAME[]=       {'I','c','o','n','S','p','a','c','i','n','g',0};
151 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};
152 static const WCHAR SPI_SETSCREENSAVETIMEOUT_VALNAME[]=        {'S','c','r','e','e','n','S','a','v','e','T','i','m','e','O','u','t',0};
153 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};
154 static const WCHAR SPI_SETSCREENSAVEACTIVE_VALNAME[]=         {'S','c','r','e','e','n','S','a','v','e','A','c','t','i','v','e',0};
155 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};
156 static const WCHAR SPI_SETGRIDGRANULARITY_VALNAME[]=          {'G','r','i','d','G','r','a','n','u','l','a','r','i','t','y',0};
157 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};
158 static const WCHAR SPI_SETKEYBOARDDELAY_VALNAME[]=            {'K','e','y','b','o','a','r','d','D','e','l','a','y',0};
159 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','\\',
160                                                                'W','i','n','d','o','w','M','e','t','r','i','c','s',0};
161 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};
162 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','\\',
163                                                                'W','i','n','d','o','w','M','e','t','r','i','c','s',0};
164 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};
165 static const WCHAR SPI_SETICONTITLEWRAP_VALNAME[]=            {'I','c','o','n','T','i','t','l','e','W','r','a','p',0};
166 static const WCHAR SPI_SETICONTITLELOGFONT_REGKEY[]=          {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p','\\',
167                                                                'W','i','n','d','o','w','M','e','t','r','i','c','s',0};
168 static const WCHAR SPI_SETICONTITLELOGFONT_VALNAME[]=         {'I','c','o','n','F','o','n','t',0};
169 static const WCHAR SPI_SETMENUDROPALIGNMENT_REGKEY1[]=        {'S','o','f','t','w','a','r','e','\\',
170                                                                'M','i','c','r','o','s','o','f','t','\\',
171                                                                'W','i','n','d','o','w','s',' ','N','T','\\',
172                                                                'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
173                                                                'W','i','n','d','o','w','s',0};
174 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};
175 static const WCHAR SPI_SETMENUDROPALIGNMENT_VALNAME[]=        {'M','e','n','u','D','r','o','p','A','l','i','g','n','m','e','n','t',0};
176 static const WCHAR SPI_SETSNAPTODEFBUTTON_REGKEY[]=           {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','M','o','u','s','e',0};
177 static const WCHAR SPI_SETSNAPTODEFBUTTON_VALNAME[]=          {'S','n','a','p','T','o','D','e','f','a','u','l','t','B','u','t','t','o','n',0};
178 static const WCHAR SPI_SETDOUBLECLKWIDTH_REGKEY1[]=           {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','M','o','u','s','e',0};
179 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};
180 static const WCHAR SPI_SETDOUBLECLKWIDTH_VALNAME[]=           {'D','o','u','b','l','e','C','l','i','c','k','W','i','d','t','h',0};
181 static const WCHAR SPI_SETDOUBLECLKHEIGHT_REGKEY1[]=          {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','M','o','u','s','e',0};
182 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};
183 static const WCHAR SPI_SETDOUBLECLKHEIGHT_VALNAME[]=          {'D','o','u','b','l','e','C','l','i','c','k','H','e','i','g','h','t',0};
184 static const WCHAR SPI_SETDOUBLECLICKTIME_REGKEY[]=           {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','M','o','u','s','e',0};
185 static const WCHAR SPI_SETDOUBLECLICKTIME_VALNAME[]=          {'D','o','u','b','l','e','C','l','i','c','k','S','p','e','e','d',0};
186 static const WCHAR SPI_SETMOUSEBUTTONSWAP_REGKEY[]=           {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','M','o','u','s','e',0};
187 static const WCHAR SPI_SETMOUSEBUTTONSWAP_VALNAME[]=          {'S','w','a','p','M','o','u','s','e','B','u','t','t','o','n','s',0};
188 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};
189 static const WCHAR SPI_SETDRAGFULLWINDOWS_VALNAME[]=          {'D','r','a','g','F','u','l','l','W','i','n','d','o','w','s',0};
190 static const WCHAR SPI_SETSHOWSOUNDS_REGKEY[]=                {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\',
191                                                                'A','c','c','e','s','s','i','b','i','l','i','t','y','\\',
192                                                                'S','h','o','w','S','o','u','n','d','s',0};
193 static const WCHAR SPI_SETSHOWSOUNDS_VALNAME[]=               {'O','n',0};
194 static const WCHAR SPI_SETKEYBOARDPREF_REGKEY[]=              {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\',
195                                                                'A','c','c','e','s','s','i','b','i','l','i','t','y','\\',
196                                                                'K','e','y','b','o','a','r','d',' ','P','r','e','f','e','r','e','n','c','e',0};
197 static const WCHAR SPI_SETKEYBOARDPREF_VALNAME[]=             {'O','n',0};
198 static const WCHAR SPI_SETSCREENREADER_REGKEY[]=              {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\',
199                                                                'A','c','c','e','s','s','i','b','i','l','i','t','y','\\',
200                                                                'B','l','i','n','d',' ','A','c','c','e','s','s',0};
201 static const WCHAR SPI_SETSCREENREADER_VALNAME[]=             {'O','n',0};
202 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};
203 static const WCHAR SPI_SETDESKWALLPAPER_VALNAME[]=            {'W','a','l','l','p','a','p','e','r',0};
204 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};
205 static const WCHAR SPI_SETFONTSMOOTHING_VALNAME[]=            {'F','o','n','t','S','m','o','o','t','h','i','n','g',0};
206 static const WCHAR SPI_SETLOWPOWERACTIVE_REGKEY[]=            {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
207 static const WCHAR SPI_SETLOWPOWERACTIVE_VALNAME[]=           {'L','o','w','P','o','w','e','r','A','c','t','i','v','e',0};
208 static const WCHAR SPI_SETPOWEROFFACTIVE_REGKEY[]=            {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
209 static const WCHAR SPI_SETPOWEROFFACTIVE_VALNAME[]=           {'P','o','w','e','r','O','f','f','A','c','t','i','v','e',0};
210 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};
211 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};
212 static const WCHAR SPI_SETMOUSEHOVERWIDTH_REGKEY[]=           {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','M','o','u','s','e',0};
213 static const WCHAR SPI_SETMOUSEHOVERWIDTH_VALNAME[]=          {'M','o','u','s','e','H','o','v','e','r','W','i','d','t','h',0};
214 static const WCHAR SPI_SETMOUSEHOVERHEIGHT_REGKEY[]=          {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','M','o','u','s','e',0};
215 static const WCHAR SPI_SETMOUSEHOVERHEIGHT_VALNAME[]=         {'M','o','u','s','e','H','o','v','e','r','H','e','i','g','h','t',0};
216 static const WCHAR SPI_SETMOUSEHOVERTIME_REGKEY[]=            {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','M','o','u','s','e',0};
217 static const WCHAR SPI_SETMOUSEHOVERTIME_VALNAME[]=           {'M','o','u','s','e','H','o','v','e','r','T','i','m','e',0};
218 static const WCHAR SPI_SETMOUSESCROLLCHARS_REGKEY[]=          {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
219 static const WCHAR SPI_SETMOUSESCROLLCHARS_VALNAME[]=         {'W','h','e','e','l','S','c','r','o','l','l','C','h','a','r','s',0};
220 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};
221 static const WCHAR SPI_SETMOUSESCROLLLINES_VALNAME[]=         {'W','h','e','e','l','S','c','r','o','l','l','L','i','n','e','s',0};
222 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};
223 static const WCHAR SPI_SETMENUSHOWDELAY_VALNAME[]=            {'M','e','n','u','S','h','o','w','D','e','l','a','y',0};
224 static const WCHAR SPI_SETFOREGROUNDLOCKTIMEOUT_REGKEY[]=     {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
225 static const WCHAR SPI_SETFOREGROUNDLOCKTIMEOUT_VALNAME[]=    {'F','o','r','e','g','r','o','u','n','d','L','o','c','k','T','i','m','e','o','u','t',0};
226 static const WCHAR SPI_CARETWIDTH_REGKEY[]=                   {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
227 static const WCHAR SPI_CARETWIDTH_VALNAME[]=                  {'C','a','r','e','t','W','i','d','t','h',0};
228 static const WCHAR SPI_SETMOUSESPEED_REGKEY[]=                {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','M','o','u','s','e',0};
229 static const WCHAR SPI_SETMOUSESPEED_VALNAME[]=               {'M','o','u','s','e','S','e','n','s','i','t','i','v','i','t','y',0};
230 static const WCHAR SPI_SETFONTSMOOTHINGTYPE_REGKEY[]=         {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
231 static const WCHAR SPI_SETFONTSMOOTHINGTYPE_VALNAME[]=        {'F','o','n','t','S','m','o','o','t','h','i','n','g','T','y','p','e',0};
232 static const WCHAR SPI_SETFONTSMOOTHINGCONTRAST_REGKEY[]=     {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
233 static const WCHAR SPI_SETFONTSMOOTHINGCONTRAST_VALNAME[]=    {'F','o','n','t','S','m','o','o','t','h','i','n','g','G','a','m','m','a',0};
234 static const WCHAR SPI_SETFONTSMOOTHINGORIENTATION_REGKEY[]=  {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
235 static const WCHAR SPI_SETFONTSMOOTHINGORIENTATION_VALNAME[]= {'F','o','n','t','S','m','o','o','t','h','i','n','g','O','r','i','e','n','t','a','t','i','o','n',0};
236
237 /* FIXME - real values */
238 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};
239 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};
240
241 static const WCHAR METRICS_REGKEY[]=                  {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p','\\',
242                                                        'W','i','n','d','o','w','M','e','t','r','i','c','s',0};
243 static const WCHAR METRICS_SCROLLWIDTH_VALNAME[]=     {'S','c','r','o','l','l','W','i','d','t','h',0};
244 static const WCHAR METRICS_SCROLLHEIGHT_VALNAME[]=    {'S','c','r','o','l','l','H','e','i','g','h','t',0};
245 static const WCHAR METRICS_CAPTIONWIDTH_VALNAME[]=    {'C','a','p','t','i','o','n','W','i','d','t','h',0};
246 static const WCHAR METRICS_CAPTIONHEIGHT_VALNAME[]=   {'C','a','p','t','i','o','n','H','e','i','g','h','t',0};
247 static const WCHAR METRICS_SMCAPTIONWIDTH_VALNAME[]=  {'S','m','C','a','p','t','i','o','n','W','i','d','t','h',0};
248 static const WCHAR METRICS_SMCAPTIONHEIGHT_VALNAME[]= {'S','m','C','a','p','t','i','o','n','H','e','i','g','h','t',0};
249 static const WCHAR METRICS_MENUWIDTH_VALNAME[]=       {'M','e','n','u','W','i','d','t','h',0};
250 static const WCHAR METRICS_MENUHEIGHT_VALNAME[]=      {'M','e','n','u','H','e','i','g','h','t',0};
251 static const WCHAR METRICS_ICONSIZE_VALNAME[]=        {'S','h','e','l','l',' ','I','c','o','n',' ','S','i','z','e',0};
252 static const WCHAR METRICS_BORDERWIDTH_VALNAME[]=     {'B','o','r','d','e','r','W','i','d','t','h',0};
253 static const WCHAR METRICS_CAPTIONLOGFONT_VALNAME[]=  {'C','a','p','t','i','o','n','F','o','n','t',0};
254 static const WCHAR METRICS_SMCAPTIONLOGFONT_VALNAME[]={'S','m','C','a','p','t','i','o','n','F','o','n','t',0};
255 static const WCHAR METRICS_MENULOGFONT_VALNAME[]=     {'M','e','n','u','F','o','n','t',0};
256 static const WCHAR METRICS_MESSAGELOGFONT_VALNAME[]=  {'M','e','s','s','a','g','e','F','o','n','t',0};
257 static const WCHAR METRICS_STATUSLOGFONT_VALNAME[]=   {'S','t','a','t','u','s','F','o','n','t',0};
258 /* minimized metrics */
259 static const WCHAR METRICS_MINWIDTH_VALNAME[] =   {'M','i','n','W','i','d','t','h','\0'}; 
260 static const WCHAR METRICS_MINHORZGAP_VALNAME[] = {'M','i','n','H','o','r','z','G','a','p','\0'};
261 static const WCHAR METRICS_MINVERTGAP_VALNAME[] = {'M','i','n','V','e','r','t','G','a','p','\0'};
262 static const WCHAR METRICS_MINARRANGE_VALNAME[] = {'M','i','n','A','r','r','a','n','g','e','\0'}; 
263
264 static const WCHAR WINE_CURRENT_USER_REGKEY[] = {'S','o','f','t','w','a','r','e','\\',
265                                                  'W','i','n','e',0};
266
267 /* volatile registry branch under WINE_CURRENT_USER_REGKEY for temporary values storage */
268 static const WCHAR WINE_CURRENT_USER_REGKEY_TEMP_PARAMS[] = {'T','e','m','p','o','r','a','r','y',' ',
269                                                              'S','y','s','t','e','m',' ',
270                                                              'P','a','r','a','m','e','t','e','r','s',0};
271
272 static const WCHAR Yes[]=                                    {'Y','e','s',0};
273 static const WCHAR No[]=                                     {'N','o',0};
274 static const WCHAR Desktop[]=                                {'D','e','s','k','t','o','p',0};
275 static const WCHAR Pattern[]=                                {'P','a','t','t','e','r','n',0};
276 static const WCHAR MenuFont[]=                               {'M','e','n','u','F','o','n','t',0};
277 static const WCHAR MenuFontSize[]=                           {'M','e','n','u','F','o','n','t','S','i','z','e',0};
278 static const WCHAR StatusFont[]=                             {'S','t','a','t','u','s','F','o','n','t',0};
279 static const WCHAR StatusFontSize[]=                         {'S','t','a','t','u','s','F','o','n','t','S','i','z','e',0};
280 static const WCHAR MessageFont[]=                            {'M','e','s','s','a','g','e','F','o','n','t',0};
281 static const WCHAR MessageFontSize[]=                        {'M','e','s','s','a','g','e','F','o','n','t','S','i','z','e',0};
282 static const WCHAR System[]=                                 {'S','y','s','t','e','m',0};
283 static const WCHAR IconTitleSize[]=                          {'I','c','o','n','T','i','t','l','e','S','i','z','e',0};
284 static const WCHAR IconTitleFaceName[]=                      {'I','c','o','n','T','i','t','l','e','F','a','c','e','N','a','m','e',0};
285 static const WCHAR defPattern[]=                             {'0',' ','0',' ','0',' ','0',' ','0',' ','0',' ','0',' ','0',0};
286 static const WCHAR CSu[]=                                    {'%','u',0};
287 static const WCHAR CSd[]=                                    {'%','d',0};
288
289 /* Indicators whether system parameter value is loaded */
290 static char spi_loaded[SPI_INDEX_COUNT];
291
292 static BOOL notify_change = TRUE;
293
294 /* System parameters storage */
295 static BOOL beep_active = TRUE;
296 static int mouse_threshold1 = 6;
297 static int mouse_threshold2 = 10;
298 static int mouse_speed = 1;
299 static UINT border = 1;
300 static UINT keyboard_speed = 31;
301 static UINT screensave_timeout = 300;
302 static UINT grid_granularity = 0;
303 static UINT keyboard_delay = 1;
304 static UINT double_click_width = 4;
305 static UINT double_click_height = 4;
306 static UINT double_click_time = 500;
307 static BOOL drag_full_windows = FALSE;
308 static RECT work_area;
309 static BOOL keyboard_pref = TRUE;
310 static BOOL screen_reader = FALSE;
311 static UINT mouse_hover_width = 4;
312 static UINT mouse_hover_height = 4;
313 static UINT mouse_hover_time = 400;
314 static UINT mouse_scroll_chars = 3;
315 static UINT mouse_scroll_lines = 3;
316 static UINT menu_show_delay = 400;
317 static UINT menu_drop_alignment = 0;
318 static BOOL screensaver_running = FALSE;
319 static UINT font_smoothing = 0;  /* 0x01 for 95/98/NT, 0x02 for 98/ME/2k/XP */
320 static BOOL lowpoweractive = FALSE;
321 static BOOL poweroffactive = FALSE;
322 static BOOL show_sounds = FALSE;
323 static BOOL snap_to_default_button = FALSE;
324 static BOOL swap_buttons = FALSE;
325 static UINT foreground_lock_timeout = 0;
326 static UINT caret_width = 1;
327 static UINT mouse_sensitivity = 10;
328 static UINT font_smoothing_type = 0;
329 static UINT font_smoothing_contrast = 0;
330 static UINT font_smoothing_orientation = 0;
331 static BYTE user_prefs[4];
332
333 static MINIMIZEDMETRICS minimized_metrics =
334 {
335     sizeof(MINIMIZEDMETRICS),
336     154,      /* iWidth */
337     0,        /* iHorzGap */
338     0,        /* iVertGap */
339     ARW_HIDE  /* iArrange */
340 };
341
342 static ICONMETRICSW icon_metrics =
343 {
344     sizeof(ICONMETRICSW),
345     75,   /* iHorzSpacing */
346     75,   /* iVertSpacing */
347     TRUE, /* iTitleWrap */
348     { -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET,
349       OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH }   /* lfFont */
350 };
351
352 static NONCLIENTMETRICSW nonclient_metrics =
353 {
354     sizeof(NONCLIENTMETRICSW),
355     1,     /* iBorderWidth */
356     16,    /* iScrollWidth */
357     16,    /* iScrollHeight */
358     18,    /* iCaptionWidth */
359     18,    /* iCaptionHeight */
360     { 0 }, /* lfCaptionFont */
361     13,    /* iSmCaptionWidth */
362     15,    /* iSmCaptionHeight */
363     { 0 }, /* lfSmCaptionFont */
364     18,    /* iMenuWidth */
365     18,    /* iMenuHeight */
366     { 0 }, /* lfMenuFont */
367     { 0 }, /* lfStatusFont */
368     { 0 }  /* lfMessageFont */
369 };
370
371 /* some additional non client metric info */
372 static TEXTMETRICW tmMenuFont;
373 static UINT CaptionFontAvCharWidth;
374
375 static SIZE icon_size = { 32, 32 };
376
377 #define NUM_SYS_COLORS     (COLOR_MENUBAR+1)
378
379 static COLORREF SysColors[NUM_SYS_COLORS];
380 static HBRUSH SysColorBrushes[NUM_SYS_COLORS];
381 static HPEN   SysColorPens[NUM_SYS_COLORS];
382
383 static const WORD wPattern55AA[] = { 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa };
384
385 HBRUSH SYSCOLOR_55AABrush = 0;
386
387 extern void CDECL __wine_make_gdi_object_system( HGDIOBJ handle, BOOL set );
388
389
390 /* This function is a copy of the one in objects/font.c */
391 static void SYSPARAMS_LogFont32ATo16( const LOGFONTA* font32, LPLOGFONT16 font16 )
392 {
393     font16->lfHeight = font32->lfHeight;
394     font16->lfWidth = font32->lfWidth;
395     font16->lfEscapement = font32->lfEscapement;
396     font16->lfOrientation = font32->lfOrientation;
397     font16->lfWeight = font32->lfWeight;
398     font16->lfItalic = font32->lfItalic;
399     font16->lfUnderline = font32->lfUnderline;
400     font16->lfStrikeOut = font32->lfStrikeOut;
401     font16->lfCharSet = font32->lfCharSet;
402     font16->lfOutPrecision = font32->lfOutPrecision;
403     font16->lfClipPrecision = font32->lfClipPrecision;
404     font16->lfQuality = font32->lfQuality;
405     font16->lfPitchAndFamily = font32->lfPitchAndFamily;
406     lstrcpynA( font16->lfFaceName, font32->lfFaceName, LF_FACESIZE );
407 }
408
409 static void SYSPARAMS_LogFont16To32W( const LOGFONT16 *font16, LPLOGFONTW font32 )
410 {
411     font32->lfHeight = font16->lfHeight;
412     font32->lfWidth = font16->lfWidth;
413     font32->lfEscapement = font16->lfEscapement;
414     font32->lfOrientation = font16->lfOrientation;
415     font32->lfWeight = font16->lfWeight;
416     font32->lfItalic = font16->lfItalic;
417     font32->lfUnderline = font16->lfUnderline;
418     font32->lfStrikeOut = font16->lfStrikeOut;
419     font32->lfCharSet = font16->lfCharSet;
420     font32->lfOutPrecision = font16->lfOutPrecision;
421     font32->lfClipPrecision = font16->lfClipPrecision;
422     font32->lfQuality = font16->lfQuality;
423     font32->lfPitchAndFamily = font16->lfPitchAndFamily;
424     MultiByteToWideChar( CP_ACP, 0, font16->lfFaceName, -1, font32->lfFaceName, LF_FACESIZE );
425     font32->lfFaceName[LF_FACESIZE-1] = 0;
426 }
427
428 static void SYSPARAMS_LogFont32WTo32A( const LOGFONTW* font32W, LPLOGFONTA font32A )
429 {
430     font32A->lfHeight = font32W->lfHeight;
431     font32A->lfWidth = font32W->lfWidth;
432     font32A->lfEscapement = font32W->lfEscapement;
433     font32A->lfOrientation = font32W->lfOrientation;
434     font32A->lfWeight = font32W->lfWeight;
435     font32A->lfItalic = font32W->lfItalic;
436     font32A->lfUnderline = font32W->lfUnderline;
437     font32A->lfStrikeOut = font32W->lfStrikeOut;
438     font32A->lfCharSet = font32W->lfCharSet;
439     font32A->lfOutPrecision = font32W->lfOutPrecision;
440     font32A->lfClipPrecision = font32W->lfClipPrecision;
441     font32A->lfQuality = font32W->lfQuality;
442     font32A->lfPitchAndFamily = font32W->lfPitchAndFamily;
443     WideCharToMultiByte( CP_ACP, 0, font32W->lfFaceName, -1, font32A->lfFaceName, LF_FACESIZE, NULL, NULL );
444     font32A->lfFaceName[LF_FACESIZE-1] = 0;
445 }
446
447 static void SYSPARAMS_LogFont32ATo32W( const LOGFONTA* font32A, LPLOGFONTW font32W )
448 {
449     font32W->lfHeight = font32A->lfHeight;
450     font32W->lfWidth = font32A->lfWidth;
451     font32W->lfEscapement = font32A->lfEscapement;
452     font32W->lfOrientation = font32A->lfOrientation;
453     font32W->lfWeight = font32A->lfWeight;
454     font32W->lfItalic = font32A->lfItalic;
455     font32W->lfUnderline = font32A->lfUnderline;
456     font32W->lfStrikeOut = font32A->lfStrikeOut;
457     font32W->lfCharSet = font32A->lfCharSet;
458     font32W->lfOutPrecision = font32A->lfOutPrecision;
459     font32W->lfClipPrecision = font32A->lfClipPrecision;
460     font32W->lfQuality = font32A->lfQuality;
461     font32W->lfPitchAndFamily = font32A->lfPitchAndFamily;
462     MultiByteToWideChar( CP_ACP, 0, font32A->lfFaceName, -1, font32W->lfFaceName, LF_FACESIZE );
463     font32W->lfFaceName[LF_FACESIZE-1] = 0;
464 }
465
466 static void SYSPARAMS_NonClientMetrics32ATo16( const NONCLIENTMETRICSA* lpnm32, LPNONCLIENTMETRICS16 lpnm16 )
467 {
468     lpnm16->iBorderWidth        = lpnm32->iBorderWidth;
469     lpnm16->iScrollWidth        = lpnm32->iScrollWidth;
470     lpnm16->iScrollHeight       = lpnm32->iScrollHeight;
471     lpnm16->iCaptionWidth       = lpnm32->iCaptionWidth;
472     lpnm16->iCaptionHeight      = lpnm32->iCaptionHeight;
473     SYSPARAMS_LogFont32ATo16( &lpnm32->lfCaptionFont,   &lpnm16->lfCaptionFont );
474     lpnm16->iSmCaptionWidth     = lpnm32->iSmCaptionWidth;
475     lpnm16->iSmCaptionHeight    = lpnm32->iSmCaptionHeight;
476     SYSPARAMS_LogFont32ATo16( &lpnm32->lfSmCaptionFont, &lpnm16->lfSmCaptionFont );
477     lpnm16->iMenuWidth          = lpnm32->iMenuWidth;
478     lpnm16->iMenuHeight         = lpnm32->iMenuHeight;
479     SYSPARAMS_LogFont32ATo16( &lpnm32->lfMenuFont,      &lpnm16->lfMenuFont );
480     SYSPARAMS_LogFont32ATo16( &lpnm32->lfStatusFont,    &lpnm16->lfStatusFont );
481     SYSPARAMS_LogFont32ATo16( &lpnm32->lfMessageFont,   &lpnm16->lfMessageFont );
482 }
483
484 static void SYSPARAMS_NonClientMetrics32WTo32A( const NONCLIENTMETRICSW* lpnm32W, LPNONCLIENTMETRICSA lpnm32A )
485 {
486     lpnm32A->iBorderWidth       = lpnm32W->iBorderWidth;
487     lpnm32A->iScrollWidth       = lpnm32W->iScrollWidth;
488     lpnm32A->iScrollHeight      = lpnm32W->iScrollHeight;
489     lpnm32A->iCaptionWidth      = lpnm32W->iCaptionWidth;
490     lpnm32A->iCaptionHeight     = lpnm32W->iCaptionHeight;
491     SYSPARAMS_LogFont32WTo32A(  &lpnm32W->lfCaptionFont,        &lpnm32A->lfCaptionFont );
492     lpnm32A->iSmCaptionWidth    = lpnm32W->iSmCaptionWidth;
493     lpnm32A->iSmCaptionHeight   = lpnm32W->iSmCaptionHeight;
494     SYSPARAMS_LogFont32WTo32A( &lpnm32W->lfSmCaptionFont,       &lpnm32A->lfSmCaptionFont );
495     lpnm32A->iMenuWidth         = lpnm32W->iMenuWidth;
496     lpnm32A->iMenuHeight        = lpnm32W->iMenuHeight;
497     SYSPARAMS_LogFont32WTo32A( &lpnm32W->lfMenuFont,            &lpnm32A->lfMenuFont );
498     SYSPARAMS_LogFont32WTo32A( &lpnm32W->lfStatusFont,          &lpnm32A->lfStatusFont );
499     SYSPARAMS_LogFont32WTo32A( &lpnm32W->lfMessageFont,         &lpnm32A->lfMessageFont );
500 }
501
502 static void SYSPARAMS_NonClientMetrics32ATo32W( const NONCLIENTMETRICSA* lpnm32A, LPNONCLIENTMETRICSW lpnm32W )
503 {
504     lpnm32W->iBorderWidth       = lpnm32A->iBorderWidth;
505     lpnm32W->iScrollWidth       = lpnm32A->iScrollWidth;
506     lpnm32W->iScrollHeight      = lpnm32A->iScrollHeight;
507     lpnm32W->iCaptionWidth      = lpnm32A->iCaptionWidth;
508     lpnm32W->iCaptionHeight     = lpnm32A->iCaptionHeight;
509     SYSPARAMS_LogFont32ATo32W(  &lpnm32A->lfCaptionFont,        &lpnm32W->lfCaptionFont );
510     lpnm32W->iSmCaptionWidth    = lpnm32A->iSmCaptionWidth;
511     lpnm32W->iSmCaptionHeight   = lpnm32A->iSmCaptionHeight;
512     SYSPARAMS_LogFont32ATo32W( &lpnm32A->lfSmCaptionFont,       &lpnm32W->lfSmCaptionFont );
513     lpnm32W->iMenuWidth         = lpnm32A->iMenuWidth;
514     lpnm32W->iMenuHeight        = lpnm32A->iMenuHeight;
515     SYSPARAMS_LogFont32ATo32W( &lpnm32A->lfMenuFont,            &lpnm32W->lfMenuFont );
516     SYSPARAMS_LogFont32ATo32W( &lpnm32A->lfStatusFont,          &lpnm32W->lfStatusFont );
517     SYSPARAMS_LogFont32ATo32W( &lpnm32A->lfMessageFont,         &lpnm32W->lfMessageFont );
518 }
519
520
521 /* Helper functions to retrieve monitors info */
522
523 struct monitor_info
524 {
525     int count;
526     RECT virtual_rect;
527 };
528
529 static BOOL CALLBACK monitor_info_proc( HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM lp )
530 {
531     struct monitor_info *info = (struct monitor_info *)lp;
532     info->count++;
533     UnionRect( &info->virtual_rect, &info->virtual_rect, rect );
534     return TRUE;
535 }
536
537 static void get_monitors_info( struct monitor_info *info )
538 {
539     info->count = 0;
540     SetRectEmpty( &info->virtual_rect );
541     EnumDisplayMonitors( 0, NULL, monitor_info_proc, (LPARAM)info );
542 }
543
544
545 /* get text metrics and/or "average" char width of the specified logfont 
546  * for the specified dc */
547 static void get_text_metr_size( HDC hdc, LOGFONTW *plf, TEXTMETRICW * ptm, UINT *psz)
548 {
549     HFONT hfont, hfontsav;
550     TEXTMETRICW tm;
551     if( !ptm) ptm = &tm;
552     hfont = CreateFontIndirectW( plf);
553     if( !hfont || ( hfontsav = SelectObject( hdc, hfont)) == NULL ) {
554         ptm->tmHeight = -1;
555         if( psz) *psz = 10;
556         if( hfont) DeleteObject( hfont);
557         return;
558     }
559     GetTextMetricsW( hdc, ptm);
560     if( psz)
561         if( !(*psz = GdiGetCharDimensions( hdc, ptm, NULL)))
562             *psz = 10;
563     SelectObject( hdc, hfontsav);
564     DeleteObject( hfont);
565 }
566
567 /***********************************************************************
568  *           get_volatile_regkey
569  *
570  * Return a handle to the volatile registry key used to store
571  * non-permanently modified parameters.
572  */
573 static HKEY get_volatile_regkey(void)
574 {
575     static HKEY volatile_key;
576
577     if (!volatile_key)
578     {
579         HKEY key;
580         /* This must be non-volatile! */
581         if (RegCreateKeyExW( HKEY_CURRENT_USER, WINE_CURRENT_USER_REGKEY,
582                              0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0,
583                              &key, 0 ) != ERROR_SUCCESS)
584         {
585             ERR("Can't create wine registry branch\n");
586         }
587         else
588         {
589             /* @@ Wine registry key: HKCU\Software\Wine\Temporary System Parameters */
590             if (RegCreateKeyExW( key, WINE_CURRENT_USER_REGKEY_TEMP_PARAMS,
591                                  0, 0, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, 0,
592                                  &volatile_key, 0 ) != ERROR_SUCCESS)
593                 ERR("Can't create non-permanent wine registry branch\n");
594
595             RegCloseKey(key);
596         }
597     }
598     return volatile_key;
599 }
600
601 /***********************************************************************
602  *           SYSPARAMS_NotifyChange
603  *
604  * Sends notification about system parameter update.
605  */
606 static void SYSPARAMS_NotifyChange( UINT uiAction, UINT fWinIni )
607 {
608     static const WCHAR emptyW[1];
609
610     if (notify_change)
611     {
612         if (fWinIni & SPIF_UPDATEINIFILE)
613         {
614             if (fWinIni & (SPIF_SENDWININICHANGE | SPIF_SENDCHANGE))
615                 SendMessageTimeoutW(HWND_BROADCAST, WM_SETTINGCHANGE,
616                                     uiAction, (LPARAM) emptyW,
617                                     SMTO_ABORTIFHUNG, 2000, NULL );
618         }
619         else
620         {
621             /* FIXME notify other wine processes with internal message */
622         }
623     }
624 }
625
626
627 /***********************************************************************
628  * Loads system parameter from user profile.
629  */
630 static BOOL SYSPARAMS_LoadRaw( LPCWSTR lpRegKey, LPCWSTR lpValName, LPBYTE lpBuf, DWORD count )
631 {
632     BOOL ret = FALSE;
633     DWORD type;
634     HKEY hKey;
635
636     memset( lpBuf, 0, count );
637     if ((RegOpenKeyW( get_volatile_regkey(), lpRegKey, &hKey ) == ERROR_SUCCESS) ||
638         (RegOpenKeyW( HKEY_CURRENT_USER, lpRegKey, &hKey ) == ERROR_SUCCESS))
639     {
640         ret = !RegQueryValueExW( hKey, lpValName, NULL, &type, lpBuf, &count);
641         RegCloseKey( hKey );
642     }
643     return ret;
644 }
645
646 static BOOL SYSPARAMS_Load( LPCWSTR lpRegKey, LPCWSTR lpValName, LPWSTR lpBuf, DWORD count )
647 {
648   return SYSPARAMS_LoadRaw( lpRegKey, lpValName, (LPBYTE)lpBuf, count );
649 }
650
651 /***********************************************************************
652  * Saves system parameter to user profile.
653  */
654
655 /* Save data as-is */
656 static BOOL SYSPARAMS_SaveRaw( LPCWSTR lpRegKey, LPCWSTR lpValName, 
657                                const BYTE* lpValue, DWORD valueSize, 
658                                DWORD type, UINT fWinIni )
659 {
660     HKEY hKey;
661     HKEY hBaseKey;
662     DWORD dwOptions;
663     BOOL ret = FALSE;
664
665     if (fWinIni & SPIF_UPDATEINIFILE)
666     {
667         hBaseKey = HKEY_CURRENT_USER;
668         dwOptions = 0;
669     }
670     else
671     {
672         hBaseKey = get_volatile_regkey();
673         dwOptions = REG_OPTION_VOLATILE;
674     }
675
676     if (RegCreateKeyExW( hBaseKey, lpRegKey,
677                          0, 0, dwOptions, KEY_ALL_ACCESS,
678                          0, &hKey, 0 ) == ERROR_SUCCESS)
679     {
680         if (RegSetValueExW( hKey, lpValName, 0, type,
681                             lpValue, valueSize) == ERROR_SUCCESS)
682         {
683             ret = TRUE;
684             if (hBaseKey == HKEY_CURRENT_USER)
685                 RegDeleteKeyW( get_volatile_regkey(), lpRegKey );
686         }
687         RegCloseKey( hKey );
688     }
689     return ret;
690 }
691
692 /* Convenience function to save strings */
693 static BOOL SYSPARAMS_Save( LPCWSTR lpRegKey, LPCWSTR lpValName, LPCWSTR lpValue,
694                             UINT fWinIni )
695 {
696     return SYSPARAMS_SaveRaw( lpRegKey, lpValName, (const BYTE*)lpValue, 
697         (strlenW(lpValue) + 1)*sizeof(WCHAR), REG_SZ, fWinIni );
698 }
699
700 /* Convenience function to save logical fonts */
701 static BOOL SYSPARAMS_SaveLogFont( LPCWSTR lpRegKey, LPCWSTR lpValName,
702                                     LPLOGFONTW plf, UINT fWinIni )
703 {
704     return SYSPARAMS_SaveRaw( lpRegKey, lpValName, (const BYTE*)plf, 
705         sizeof( LOGFONTW), REG_BINARY, fWinIni );
706 }
707
708
709 static inline HDC get_display_dc(void)
710 {
711     static const WCHAR DISPLAY[] = {'D','I','S','P','L','A','Y',0};
712     static HDC display_dc;
713     if (!display_dc)
714     {
715         display_dc = CreateICW( DISPLAY, NULL, NULL, NULL );
716         __wine_make_gdi_object_system( display_dc, TRUE );
717     }
718     return display_dc;
719 }
720
721 static inline int get_display_dpi(void)
722 {
723     static int display_dpi;
724     if (!display_dpi) display_dpi = GetDeviceCaps( get_display_dc(), LOGPIXELSY );
725     return display_dpi;
726 }
727
728 /***********************************************************************
729  * SYSPARAMS_Twips2Pixels
730  *
731  * Convert a dimension value that was obtained from the registry.  These are
732  * quoted as being "twips" values if negative and pixels if positive.
733  * One inch is 1440 twips. So to convert, divide by 1440 to get inches and
734  * multiply that by the dots-per-inch to get the size in pixels. 
735  * See for example
736  *   MSDN Library - April 2001 -> Resource Kits ->
737  *       Windows 2000 Resource Kit Reference ->
738  *       Technical Reference to the Windows 2000 Registry ->
739  *       HKEY_CURRENT_USER -> Control Panel -> Desktop -> WindowMetrics
740  */
741 static inline int SYSPARAMS_Twips2Pixels(int x)
742 {
743     if (x < 0)
744         x = (-x * get_display_dpi() + 720) / 1440;
745     return x;
746 }
747
748 /***********************************************************************
749  * get_reg_metric
750  *
751  * Get a registry entry from the already open key.  This allows us to open the
752  * section once and read several values.
753  *
754  * Of course this function belongs somewhere more usable but here will do
755  * for now.
756  */
757 static int get_reg_metric( HKEY hkey, LPCWSTR lpValName, int default_value )
758 {
759     int value = default_value;
760     if (hkey)
761     {
762         WCHAR buffer[128];
763         DWORD type, count = sizeof(buffer);
764         if(!RegQueryValueExW( hkey, lpValName, NULL, &type, (LPBYTE)buffer, &count) )
765         {
766             if (type != REG_SZ)
767             {
768                 /* Are there any utilities for converting registry entries
769                  * between formats?
770                  */
771                 /* FIXME_(reg)("We need reg format converter\n"); */
772             }
773             else
774                 value = atoiW(buffer);
775         }
776     }
777     return SYSPARAMS_Twips2Pixels(value);
778 }
779
780
781 /*************************************************************************
782  *             SYSPARAMS_SetSysColor
783  */
784 static void SYSPARAMS_SetSysColor( int index, COLORREF color )
785 {
786     if (index < 0 || index >= NUM_SYS_COLORS) return;
787     SysColors[index] = color;
788     if (SysColorBrushes[index])
789     {
790         __wine_make_gdi_object_system( SysColorBrushes[index], FALSE);
791         DeleteObject( SysColorBrushes[index] );
792     }
793     SysColorBrushes[index] = CreateSolidBrush( color );
794     __wine_make_gdi_object_system( SysColorBrushes[index], TRUE);
795
796     if (SysColorPens[index])
797     {
798         __wine_make_gdi_object_system( SysColorPens[index], FALSE);
799         DeleteObject( SysColorPens[index] );
800     }
801     SysColorPens[index] = CreatePen( PS_SOLID, 1, color );
802     __wine_make_gdi_object_system( SysColorPens[index], TRUE);
803 }
804
805 /* load a uint parameter from the registry */
806 static BOOL get_uint_param( unsigned int idx, LPCWSTR regkey, LPCWSTR value,
807                             UINT *value_ptr, UINT *ret_ptr )
808 {
809     if (!ret_ptr) return FALSE;
810     if (!spi_loaded[idx])
811     {
812         WCHAR buf[12];
813
814         if (SYSPARAMS_Load( regkey, value, buf, sizeof(buf) )) *value_ptr = atoiW( buf );
815         spi_loaded[idx] = TRUE;
816     }
817     *ret_ptr = *value_ptr;
818     return TRUE;
819 }
820
821 /* load a twips parameter from the registry */
822 static BOOL get_twips_param( unsigned int idx, LPCWSTR regkey, LPCWSTR value,
823                              UINT *value_ptr, UINT *ret_ptr )
824 {
825     if (!ret_ptr) return FALSE;
826     if (!spi_loaded[idx])
827     {
828         WCHAR buf[12];
829
830         if (SYSPARAMS_Load( regkey, value, buf, sizeof(buf) ))
831             *value_ptr = SYSPARAMS_Twips2Pixels( atoiW(buf) );
832         spi_loaded[idx] = TRUE;
833     }
834     *ret_ptr = *value_ptr;
835     return TRUE;
836 }
837
838 /* load a boolean parameter from the registry */
839 static inline BOOL get_bool_param( unsigned int idx, LPCWSTR regkey, LPCWSTR value,
840                                    BOOL *value_ptr, BOOL *ret_ptr )
841 {
842     return get_uint_param( idx, regkey, value, (UINT *)value_ptr, (UINT *)ret_ptr );
843 }
844
845 /* set a uint parameter that is mirrored in two different registry locations */
846 static BOOL set_uint_param_mirrored( unsigned int idx, LPCWSTR regkey, LPCWSTR regkey_mirror,
847                                      LPCWSTR value, UINT *value_ptr, UINT new_val, UINT fWinIni )
848 {
849     WCHAR buf[12];
850
851     wsprintfW(buf, CSu, new_val);
852     if (!SYSPARAMS_Save( regkey, value, buf, fWinIni )) return FALSE;
853     if (regkey_mirror) SYSPARAMS_Save( regkey_mirror, value, buf, fWinIni );
854     *value_ptr = new_val;
855     spi_loaded[idx] = TRUE;
856     return TRUE;
857 }
858
859 /* save an int parameter in registry */
860 static BOOL save_int_param( LPCWSTR regkey, LPCWSTR value, INT *value_ptr,
861                             INT new_val, UINT fWinIni )
862 {
863     WCHAR buf[12];
864
865     wsprintfW(buf, CSd, new_val);
866     if (!SYSPARAMS_Save( regkey, value, buf, fWinIni )) return FALSE;
867     if( value_ptr) *value_ptr = new_val;
868     return TRUE;
869 }
870
871 /* set an int parameter in the registry */
872 static inline BOOL set_int_param( unsigned int idx, LPCWSTR regkey, LPCWSTR value,
873                                   INT *value_ptr, INT new_val, UINT fWinIni )
874 {
875     BOOL ret = save_int_param( regkey, value, value_ptr, new_val, fWinIni );
876     if (ret) spi_loaded[idx] = TRUE;
877     return ret;
878 }
879
880 /* set a uint parameter in the registry */
881 static inline BOOL set_uint_param( unsigned int idx, LPCWSTR regkey, LPCWSTR value,
882                                    UINT *value_ptr, UINT new_val, UINT fWinIni )
883 {
884     return set_uint_param_mirrored( idx, regkey, NULL, value, value_ptr, new_val, fWinIni );
885 }
886
887 /* set a boolean parameter that is mirrored in two different registry locations */
888 static inline BOOL set_bool_param_mirrored( unsigned int idx, LPCWSTR regkey, LPCWSTR regkey_mirror,
889                                             LPCWSTR value, BOOL *value_ptr, BOOL new_val, UINT fWinIni )
890 {
891     return set_uint_param_mirrored( idx, regkey, regkey_mirror, value,
892                                     (UINT *)value_ptr, new_val, fWinIni );
893 }
894
895 /* set a boolean parameter in the registry */
896 static inline BOOL set_bool_param( unsigned int idx, LPCWSTR regkey, LPCWSTR value,
897                                    BOOL *value_ptr, BOOL new_val, UINT fWinIni )
898 {
899     return set_uint_param( idx, regkey, value, (UINT *)value_ptr, new_val, fWinIni );
900 }
901
902 /* load a boolean parameter from the user preference key */
903 static BOOL get_user_pref_param( UINT offset, UINT mask, BOOL *ret_ptr )
904 {
905     if (!ret_ptr) return FALSE;
906
907     if (!spi_loaded[SPI_USERPREFERENCEMASK_IDX])
908     {
909         SYSPARAMS_LoadRaw( SPI_USERPREFERENCEMASK_REGKEY,
910                            SPI_USERPREFERENCEMASK_VALNAME,
911                            user_prefs, sizeof(user_prefs) );
912         spi_loaded[SPI_USERPREFERENCEMASK_IDX] = TRUE;
913     }
914     *ret_ptr = (user_prefs[offset] & mask) != 0;
915     return TRUE;
916 }
917
918 /* set a boolean parameter in the user preference key */
919 static BOOL set_user_pref_param( UINT offset, UINT mask, BOOL value, BOOL fWinIni )
920 {
921     SYSPARAMS_LoadRaw( SPI_USERPREFERENCEMASK_REGKEY,
922                        SPI_USERPREFERENCEMASK_VALNAME,
923                        user_prefs, sizeof(user_prefs) );
924     spi_loaded[SPI_USERPREFERENCEMASK_IDX] = TRUE;
925
926     if (value) user_prefs[offset] |= mask;
927     else user_prefs[offset] &= ~mask;
928
929     SYSPARAMS_SaveRaw( SPI_USERPREFERENCEMASK_REGKEY,
930                        SPI_USERPREFERENCEMASK_VALNAME,
931                        user_prefs, sizeof(user_prefs), REG_BINARY, fWinIni );
932     return TRUE;
933 }
934
935 /***********************************************************************
936  *           SYSPARAMS_Init
937  *
938  * Initialisation of the system metrics array.
939  */
940 void SYSPARAMS_Init(void)
941 {
942     HKEY hkey; /* key to the window metrics area of the registry */
943     int i, r, g, b;
944     char buffer[100];
945     HBITMAP h55AABitmap;
946
947     /* initialize system colors */
948
949     if (RegCreateKeyExA(HKEY_CURRENT_USER, "Control Panel\\Colors", 0, 0, 0, KEY_ALL_ACCESS, 0, &hkey, 0))
950         hkey = 0;
951     for (i = 0; i < NUM_SYS_COLORS; i++)
952     {
953         BOOL bOk = FALSE;
954
955         /* first try, registry */
956         if (hkey)
957         {
958             DWORD dwDataSize = sizeof(buffer);
959             if (!(RegQueryValueExA(hkey,DefSysColors[i*2], 0, 0, (LPBYTE) buffer, &dwDataSize)))
960                 if (sscanf( buffer, "%d %d %d", &r, &g, &b ) == 3) bOk = TRUE;
961         }
962
963         /* second try, win.ini */
964         if (!bOk)
965         {
966             GetProfileStringA( "colors", DefSysColors[i*2], DefSysColors[i*2+1], buffer, 100 );
967             if (sscanf( buffer, " %d %d %d", &r, &g, &b ) == 3) bOk = TRUE;
968         }
969
970         /* last chance, take the default */
971         if (!bOk)
972         {
973             int iNumColors = sscanf( DefSysColors[i*2+1], " %d %d %d", &r, &g, &b );
974             assert (iNumColors==3);
975         }
976
977         SYSPARAMS_SetSysColor( i, RGB(r,g,b) );
978     }
979     if (hkey) RegCloseKey( hkey );
980
981     /* create 55AA bitmap */
982
983     h55AABitmap = CreateBitmap( 8, 8, 1, 1, wPattern55AA );
984     SYSCOLOR_55AABrush = CreatePatternBrush( h55AABitmap );
985     __wine_make_gdi_object_system( SYSCOLOR_55AABrush, TRUE );
986 }
987
988
989 /***********************************************************************
990  *              reg_get_logfont
991  *
992  *  Tries to retrieve logfont info from the specified key and value
993  */
994 static BOOL reg_get_logfont(LPCWSTR key, LPCWSTR value, LOGFONTW *lf)
995 {
996     HKEY hkey;
997     LOGFONTW lfbuf;
998     DWORD type, size;
999     BOOL found = FALSE;
1000     HKEY base_keys[2];
1001     int i;
1002
1003     base_keys[0] = get_volatile_regkey();
1004     base_keys[1] = HKEY_CURRENT_USER;
1005
1006     for(i = 0; i < 2 && !found; i++)
1007     {
1008         if(RegOpenKeyW(base_keys[i], key, &hkey) == ERROR_SUCCESS)
1009         {
1010             size = sizeof(lfbuf);
1011             if(RegQueryValueExW(hkey, value, NULL, &type, (LPBYTE)&lfbuf, &size) == ERROR_SUCCESS &&
1012                     type == REG_BINARY)
1013             {
1014                 if( size == sizeof(lfbuf))
1015                 {
1016                     found = TRUE;
1017                     memcpy(lf, &lfbuf, size);
1018                 } else if( size == sizeof( LOGFONT16))
1019                 {    /* win9x-winME format */
1020                     found = TRUE;
1021                     SYSPARAMS_LogFont16To32W( (LOGFONT16*) &lfbuf, lf);
1022                 } else
1023                     WARN("Unknown format in key %s value %s, size is %d\n",
1024                             debugstr_w( key), debugstr_w( value), size);
1025             }
1026             RegCloseKey(hkey);
1027         }
1028     }
1029     if( found && lf->lfHeight > 0) { 
1030         /* positive height value means points ( inch/72 ) */
1031         lf->lfHeight = -MulDiv( lf->lfHeight, get_display_dpi(), 72);
1032     }
1033     return found;
1034 }
1035
1036 /* load all the minimized metrics */
1037 static void load_minimized_metrics(void)
1038 {
1039     HKEY hkey;
1040     if (RegOpenKeyExW (HKEY_CURRENT_USER, METRICS_REGKEY,
1041                        0, KEY_QUERY_VALUE, &hkey) != ERROR_SUCCESS) hkey = 0;
1042
1043     minimized_metrics.iWidth = max( get_reg_metric(hkey,
1044             METRICS_MINWIDTH_VALNAME, minimized_metrics.iWidth), 0);
1045     minimized_metrics.iHorzGap = max( get_reg_metric(hkey,
1046             METRICS_MINHORZGAP_VALNAME, minimized_metrics.iHorzGap), 0);
1047     minimized_metrics.iVertGap = max( get_reg_metric(hkey,
1048             METRICS_MINVERTGAP_VALNAME, minimized_metrics.iVertGap), 0);
1049     minimized_metrics.iArrange = 0x0f & get_reg_metric(hkey,
1050             METRICS_MINARRANGE_VALNAME, minimized_metrics.iArrange);
1051
1052     if (hkey) RegCloseKey( hkey );
1053     spi_loaded[SPI_MINIMIZEDMETRICS_IDX] = TRUE;
1054 }
1055
1056 /* adjust some of the raw values found in the registry */
1057 static void normalize_nonclientmetrics( NONCLIENTMETRICSW *pncm)
1058 {
1059     TEXTMETRICW tm;
1060     if( pncm->iBorderWidth < 1) pncm->iBorderWidth = 1;
1061     if( pncm->iCaptionWidth < 8) pncm->iCaptionWidth = 8;
1062     if( pncm->iScrollWidth < 8) pncm->iScrollWidth = 8;
1063     if( pncm->iScrollHeight < 8) pncm->iScrollHeight = 8;
1064
1065     /* get some extra metrics */
1066     get_text_metr_size( get_display_dc(), &pncm->lfMenuFont,
1067             &tmMenuFont, NULL);
1068     get_text_metr_size( get_display_dc(), &pncm->lfCaptionFont,
1069             NULL, &CaptionFontAvCharWidth);
1070
1071     /* adjust some heights to the corresponding font */
1072     pncm->iMenuHeight = max( pncm->iMenuHeight,
1073             2 + tmMenuFont.tmHeight + tmMenuFont.tmExternalLeading);
1074     get_text_metr_size( get_display_dc(), &pncm->lfCaptionFont, &tm, NULL);
1075     pncm->iCaptionHeight = max( pncm->iCaptionHeight, 2 + tm.tmHeight);
1076     get_text_metr_size( get_display_dc(), &pncm->lfSmCaptionFont, &tm, NULL);
1077     pncm->iSmCaptionHeight = max( pncm->iSmCaptionHeight, 2 + tm.tmHeight);
1078 }
1079
1080 /* load all the non-client metrics */
1081 static void load_nonclient_metrics(void)
1082 {
1083     HKEY hkey;
1084     NONCLIENTMETRICSW ncm;
1085     INT r;
1086
1087     ncm.cbSize = sizeof (ncm);
1088     if (RegOpenKeyExW (HKEY_CURRENT_USER, METRICS_REGKEY,
1089                        0, KEY_QUERY_VALUE, &hkey) != ERROR_SUCCESS) hkey = 0;
1090
1091     /* initialize geometry entries */
1092     ncm.iBorderWidth =  get_reg_metric(hkey, METRICS_BORDERWIDTH_VALNAME, 1);
1093     ncm.iScrollWidth = get_reg_metric(hkey, METRICS_SCROLLWIDTH_VALNAME, 16);
1094     ncm.iScrollHeight = get_reg_metric(hkey, METRICS_SCROLLHEIGHT_VALNAME, 16);
1095
1096     /* size of the normal caption buttons */
1097     ncm.iCaptionHeight = get_reg_metric(hkey, METRICS_CAPTIONHEIGHT_VALNAME, 18);
1098     ncm.iCaptionWidth = get_reg_metric(hkey, METRICS_CAPTIONWIDTH_VALNAME, ncm.iCaptionHeight);
1099
1100     /* caption font metrics */
1101     if (!reg_get_logfont(METRICS_REGKEY, METRICS_CAPTIONLOGFONT_VALNAME, &ncm.lfCaptionFont))
1102     {
1103         SystemParametersInfoW( SPI_GETICONTITLELOGFONT, 0, &ncm.lfCaptionFont, 0 );
1104         ncm.lfCaptionFont.lfWeight = FW_BOLD;
1105     }
1106
1107     /* size of the small caption buttons */
1108     ncm.iSmCaptionWidth = get_reg_metric(hkey, METRICS_SMCAPTIONWIDTH_VALNAME, 13);
1109     ncm.iSmCaptionHeight = get_reg_metric(hkey, METRICS_SMCAPTIONHEIGHT_VALNAME, 15);
1110
1111     /* small caption font metrics */
1112     if (!reg_get_logfont(METRICS_REGKEY, METRICS_SMCAPTIONLOGFONT_VALNAME, &ncm.lfSmCaptionFont))
1113         SystemParametersInfoW( SPI_GETICONTITLELOGFONT, 0, &ncm.lfSmCaptionFont, 0 );
1114
1115     /* menus, FIXME: names of wine.conf entries are bogus */
1116
1117     /* size of the menu (MDI) buttons */
1118     ncm.iMenuHeight = get_reg_metric(hkey, METRICS_MENUHEIGHT_VALNAME, 18);
1119     ncm.iMenuWidth = get_reg_metric(hkey, METRICS_MENUWIDTH_VALNAME, ncm.iMenuHeight);
1120
1121     /* menu font metrics */
1122     if (!reg_get_logfont(METRICS_REGKEY, METRICS_MENULOGFONT_VALNAME, &ncm.lfMenuFont))
1123     {
1124         SystemParametersInfoW( SPI_GETICONTITLELOGFONT, 0, &ncm.lfMenuFont, 0 );
1125         GetProfileStringW( Desktop, MenuFont, ncm.lfCaptionFont.lfFaceName,
1126                            ncm.lfMenuFont.lfFaceName, LF_FACESIZE );
1127         r = GetProfileIntW( Desktop, MenuFontSize, 0 );
1128         if (r)
1129             ncm.lfMenuFont.lfHeight = -r;
1130         ncm.lfMenuFont.lfWeight = FW_NORMAL;
1131     }
1132
1133     /* status bar font metrics */
1134     if (!reg_get_logfont(METRICS_REGKEY, METRICS_STATUSLOGFONT_VALNAME, &ncm.lfStatusFont))
1135     {
1136         SystemParametersInfoW( SPI_GETICONTITLELOGFONT, 0, &ncm.lfStatusFont, 0 );
1137         GetProfileStringW( Desktop, StatusFont, ncm.lfCaptionFont.lfFaceName,
1138                            ncm.lfStatusFont.lfFaceName, LF_FACESIZE );
1139         r = GetProfileIntW( Desktop, StatusFontSize, 0 );
1140         if (r)
1141             ncm.lfStatusFont.lfHeight = -r;
1142         ncm.lfStatusFont.lfWeight = FW_NORMAL;
1143     }
1144
1145     /* message font metrics */
1146     if (!reg_get_logfont(METRICS_REGKEY, METRICS_MESSAGELOGFONT_VALNAME, &ncm.lfMessageFont))
1147     {
1148         SystemParametersInfoW( SPI_GETICONTITLELOGFONT, 0, &ncm.lfMessageFont, 0 );
1149         GetProfileStringW( Desktop, MessageFont, ncm.lfCaptionFont.lfFaceName,
1150                            ncm.lfMessageFont.lfFaceName, LF_FACESIZE );
1151         r = GetProfileIntW( Desktop, MessageFontSize, 0 );
1152         if (r)
1153             ncm.lfMessageFont.lfHeight = -r;
1154         ncm.lfMessageFont.lfWeight = FW_NORMAL;
1155     }
1156
1157     /* some extra fields not in the nonclient structure */
1158     icon_size.cx = icon_size.cy = get_reg_metric( hkey, METRICS_ICONSIZE_VALNAME, 32 );
1159
1160     if (hkey) RegCloseKey( hkey );
1161     normalize_nonclientmetrics( &ncm);
1162     nonclient_metrics = ncm;
1163     spi_loaded[SPI_NONCLIENTMETRICS_IDX] = TRUE;
1164 }
1165
1166 static BOOL CALLBACK enum_monitors( HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM lp )
1167 {
1168     MONITORINFO mi;
1169
1170     mi.cbSize = sizeof(mi);
1171     if (GetMonitorInfoW( monitor, &mi ) && (mi.dwFlags & MONITORINFOF_PRIMARY))
1172     {
1173         LPRECT work = (LPRECT)lp;
1174         *work = mi.rcWork;
1175         return FALSE;
1176     }
1177     return TRUE;
1178 }
1179
1180 /***********************************************************************
1181  *              SystemParametersInfoW (USER32.@)
1182  *
1183  *     Each system parameter has flag which shows whether the parameter
1184  * is loaded or not. Parameters, stored directly in SysParametersInfo are
1185  * loaded from registry only when they are requested and the flag is
1186  * "false", after the loading the flag is set to "true". On interprocess
1187  * notification of the parameter change the corresponding parameter flag is
1188  * set to "false". The parameter value will be reloaded when it is requested
1189  * the next time.
1190  *     Parameters, backed by or depend on GetSystemMetrics are processed
1191  * differently. These parameters are always loaded. They are reloaded right
1192  * away on interprocess change notification. We can't do lazy loading because
1193  * we don't want to complicate GetSystemMetrics.
1194  *     Parameters, backed by X settings are read from corresponding setting.
1195  * On the parameter change request the setting is changed. Interprocess change
1196  * notifications are ignored.
1197  *     When parameter value is updated the changed value is stored in permanent
1198  * registry branch if saving is requested. Otherwise it is stored
1199  * in temporary branch
1200  *
1201  * Some SPI values can also be stored as Twips values in the registry,
1202  * don't forget the conversion!
1203  */
1204 BOOL WINAPI SystemParametersInfoW( UINT uiAction, UINT uiParam,
1205                                    PVOID pvParam, UINT fWinIni )
1206 {
1207 #define WINE_SPI_FIXME(x) \
1208     case x: \
1209         { \
1210             static BOOL warn = TRUE; \
1211             if (warn) \
1212             { \
1213                 warn = FALSE; \
1214                 FIXME( "Unimplemented action: %u (%s)\n", x, #x ); \
1215             } \
1216         } \
1217         SetLastError( ERROR_INVALID_SPI_VALUE ); \
1218         ret = FALSE; \
1219         break
1220 #define WINE_SPI_WARN(x) \
1221     case x: \
1222         WARN( "Ignored action: %u (%s)\n", x, #x ); \
1223         break
1224
1225     BOOL ret = TRUE;
1226     unsigned spi_idx = 0;
1227
1228     switch (uiAction)
1229     {
1230     case SPI_GETBEEP:                           /*      1 */
1231         if (!pvParam) return FALSE;
1232
1233         spi_idx = SPI_SETBEEP_IDX;
1234         if (!spi_loaded[spi_idx])
1235         {
1236             WCHAR buf[5];
1237
1238             if (SYSPARAMS_Load( SPI_SETBEEP_REGKEY, SPI_SETBEEP_VALNAME, buf, sizeof(buf) ))
1239                 beep_active  = !lstrcmpiW( Yes, buf );
1240             spi_loaded[spi_idx] = TRUE;
1241         }
1242
1243         *(BOOL *)pvParam = beep_active;
1244         break;
1245
1246     case SPI_SETBEEP:                           /*      2 */
1247         spi_idx = SPI_SETBEEP_IDX;
1248         if (SYSPARAMS_Save( SPI_SETBEEP_REGKEY, SPI_SETBEEP_VALNAME,
1249                             (uiParam ? Yes : No), fWinIni ))
1250         {
1251             beep_active = uiParam;
1252             spi_loaded[spi_idx] = TRUE;
1253         }
1254         else
1255             ret = FALSE;
1256         break;
1257
1258     case SPI_GETMOUSE:                          /*      3 */
1259         if (!pvParam) return FALSE;
1260
1261         spi_idx = SPI_SETMOUSE_IDX;
1262         if (!spi_loaded[spi_idx])
1263         {
1264             WCHAR buf[12];
1265
1266             if (SYSPARAMS_Load( SPI_SETMOUSE_REGKEY, SPI_SETMOUSE_VALNAME1,
1267                                 buf, sizeof(buf) ))
1268                 mouse_threshold1 = atoiW( buf );
1269             if (SYSPARAMS_Load( SPI_SETMOUSE_REGKEY, SPI_SETMOUSE_VALNAME2,
1270                                 buf, sizeof(buf) ))
1271                 mouse_threshold2 = atoiW( buf );
1272             if (SYSPARAMS_Load( SPI_SETMOUSE_REGKEY, SPI_SETMOUSE_VALNAME3,
1273                                 buf, sizeof(buf) ))
1274                 mouse_speed = atoiW( buf );
1275             spi_loaded[spi_idx] = TRUE;
1276         }
1277         ((INT *)pvParam)[0] = mouse_threshold1;
1278         ((INT *)pvParam)[1] = mouse_threshold2;
1279         ((INT *)pvParam)[2] = mouse_speed;
1280         break;
1281
1282     case SPI_SETMOUSE:                          /*      4 */
1283     {
1284         if (!pvParam) return FALSE;
1285         ret = set_int_param( SPI_SETMOUSE_IDX, SPI_SETMOUSE_REGKEY, SPI_SETMOUSE_VALNAME1,
1286                              &mouse_threshold1, ((INT *)pvParam)[0], fWinIni);
1287         if( ret) {
1288             save_int_param( SPI_SETMOUSE_REGKEY, SPI_SETMOUSE_VALNAME2,
1289                             &mouse_threshold2, ((INT *)pvParam)[1], fWinIni);
1290             save_int_param( SPI_SETMOUSE_REGKEY, SPI_SETMOUSE_VALNAME3,
1291                             &mouse_speed, ((INT *)pvParam)[2], fWinIni);
1292         }
1293         break;
1294     }
1295
1296     case SPI_GETBORDER:
1297         ret = get_twips_param( SPI_SETBORDER_IDX,
1298                                SPI_SETBORDER_REGKEY,
1299                                SPI_SETBORDER_VALNAME,
1300                                &border, pvParam );
1301         if( *(INT*)pvParam < 1) *(INT*)pvParam = 1; 
1302         break;
1303
1304     case SPI_SETBORDER:
1305         nonclient_metrics.iBorderWidth = uiParam > 0 ? uiParam : 1;
1306         /* raw value goes to registry */
1307         ret = set_uint_param( SPI_SETBORDER_IDX,
1308                               SPI_SETBORDER_REGKEY,
1309                               SPI_SETBORDER_VALNAME,
1310                               &border, uiParam, fWinIni );
1311         break;
1312
1313     case SPI_GETKEYBOARDSPEED:
1314         ret = get_uint_param( SPI_SETKEYBOARDSPEED_IDX,
1315                               SPI_SETKEYBOARDSPEED_REGKEY,
1316                               SPI_SETKEYBOARDSPEED_VALNAME,
1317                               &keyboard_speed, pvParam );
1318         break;
1319
1320     case SPI_SETKEYBOARDSPEED:
1321         if (uiParam > 31) uiParam = 31;
1322         ret = set_uint_param( SPI_SETKEYBOARDSPEED_IDX,
1323                               SPI_SETKEYBOARDSPEED_REGKEY,
1324                               SPI_SETKEYBOARDSPEED_VALNAME,
1325                               &keyboard_speed, uiParam, fWinIni );
1326         break;
1327
1328     /* not implemented in Windows */
1329     WINE_SPI_WARN(SPI_LANGDRIVER);              /*     12 */
1330
1331     case SPI_ICONHORIZONTALSPACING:
1332         if (pvParam != NULL)
1333         {
1334             ret = get_twips_param( SPI_ICONHORIZONTALSPACING_IDX,
1335                                    SPI_ICONHORIZONTALSPACING_REGKEY,
1336                                    SPI_ICONHORIZONTALSPACING_VALNAME,
1337                                    (UINT*)&icon_metrics.iHorzSpacing, pvParam );
1338         }
1339         else
1340         {
1341             if (uiParam < 32) uiParam = 32;
1342             ret = set_uint_param( SPI_ICONHORIZONTALSPACING_IDX,
1343                                   SPI_ICONHORIZONTALSPACING_REGKEY,
1344                                   SPI_ICONHORIZONTALSPACING_VALNAME,
1345                                   (UINT*)&icon_metrics.iHorzSpacing, uiParam, fWinIni );
1346         }
1347         break;
1348
1349     case SPI_GETSCREENSAVETIMEOUT:
1350         ret = get_uint_param( SPI_SETSCREENSAVETIMEOUT_IDX,
1351                               SPI_SETSCREENSAVETIMEOUT_REGKEY,
1352                               SPI_SETSCREENSAVETIMEOUT_VALNAME,
1353                               &screensave_timeout, pvParam );
1354         break;
1355
1356     case SPI_SETSCREENSAVETIMEOUT:
1357         ret = set_uint_param( SPI_SETSCREENSAVETIMEOUT_IDX,
1358                               SPI_SETSCREENSAVETIMEOUT_REGKEY,
1359                               SPI_SETSCREENSAVETIMEOUT_VALNAME,
1360                               &screensave_timeout, uiParam, fWinIni );
1361         break;
1362
1363     case SPI_GETSCREENSAVEACTIVE:               /*     16 */
1364         if (!pvParam) return FALSE;
1365         *(BOOL *)pvParam = USER_Driver->pGetScreenSaveActive();
1366         break;
1367
1368     case SPI_SETSCREENSAVEACTIVE:               /*     17 */
1369     {
1370         WCHAR buf[12];
1371
1372         wsprintfW(buf, CSu, uiParam);
1373         USER_Driver->pSetScreenSaveActive( uiParam );
1374         /* saved value does not affect Wine */
1375         SYSPARAMS_Save( SPI_SETSCREENSAVEACTIVE_REGKEY,
1376                         SPI_SETSCREENSAVEACTIVE_VALNAME,
1377                         buf, fWinIni );
1378         break;
1379     }
1380
1381     case SPI_GETGRIDGRANULARITY:
1382         ret = get_uint_param( SPI_SETGRIDGRANULARITY_IDX,
1383                               SPI_SETGRIDGRANULARITY_REGKEY,
1384                               SPI_SETGRIDGRANULARITY_VALNAME,
1385                               &grid_granularity, pvParam );
1386         break;
1387
1388     case SPI_SETGRIDGRANULARITY:
1389         ret = set_uint_param( SPI_SETGRIDGRANULARITY_IDX,
1390                               SPI_SETGRIDGRANULARITY_REGKEY,
1391                               SPI_SETGRIDGRANULARITY_VALNAME,
1392                               &grid_granularity, uiParam, fWinIni );
1393         break;
1394
1395     case SPI_SETDESKWALLPAPER:                  /*     20 */
1396         if (!pvParam || !SetDeskWallPaper( pvParam )) return FALSE;
1397         SYSPARAMS_Save(SPI_SETDESKWALLPAPER_REGKEY, SPI_SETDESKWALLPAPER_VALNAME, pvParam, fWinIni);
1398         break;
1399         
1400     case SPI_SETDESKPATTERN:                    /*     21 */
1401         /* FIXME: the ability to specify a pattern in pvParam
1402            doesn't seem to be documented for Win32 */
1403         if ((INT16)uiParam == -1)
1404         {
1405             WCHAR buf[256];
1406             GetProfileStringW( Desktop, Pattern,
1407                                defPattern,
1408                                buf, sizeof(buf)/sizeof(WCHAR) );
1409             ret = DESKTOP_SetPattern( buf );
1410         } else
1411             ret = DESKTOP_SetPattern( pvParam );
1412         break;
1413
1414     case SPI_GETKEYBOARDDELAY:
1415         ret = get_uint_param( SPI_SETKEYBOARDDELAY_IDX,
1416                               SPI_SETKEYBOARDDELAY_REGKEY,
1417                               SPI_SETKEYBOARDDELAY_VALNAME,
1418                               &keyboard_delay, pvParam );
1419         break;
1420
1421     case SPI_SETKEYBOARDDELAY:
1422         ret = set_uint_param( SPI_SETKEYBOARDDELAY_IDX,
1423                               SPI_SETKEYBOARDDELAY_REGKEY,
1424                               SPI_SETKEYBOARDDELAY_VALNAME,
1425                               &keyboard_delay, uiParam, fWinIni );
1426         break;
1427
1428     case SPI_ICONVERTICALSPACING:
1429         if (pvParam != NULL)
1430         {
1431             ret = get_twips_param( SPI_ICONVERTICALSPACING_IDX,
1432                                    SPI_ICONVERTICALSPACING_REGKEY,
1433                                    SPI_ICONVERTICALSPACING_VALNAME,
1434                                    (UINT*)&icon_metrics.iVertSpacing, pvParam );
1435             if( icon_metrics.iVertSpacing < 32) 
1436                 icon_metrics.iVertSpacing = 32;
1437         }
1438         else
1439         {
1440             if (uiParam < 32) uiParam = 32;
1441             ret = set_uint_param( SPI_ICONVERTICALSPACING_IDX,
1442                                   SPI_ICONVERTICALSPACING_REGKEY,
1443                                   SPI_ICONVERTICALSPACING_VALNAME,
1444                                   (UINT*)&icon_metrics.iVertSpacing, uiParam, fWinIni );
1445         }
1446         break;
1447
1448     case SPI_GETICONTITLEWRAP:
1449         ret = get_bool_param( SPI_SETICONTITLEWRAP_IDX,
1450                               SPI_SETICONTITLEWRAP_REGKEY1,
1451                               SPI_SETICONTITLEWRAP_VALNAME,
1452                               &icon_metrics.iTitleWrap, pvParam );
1453         break;
1454
1455     case SPI_SETICONTITLEWRAP:
1456         ret = set_bool_param_mirrored( SPI_SETICONTITLEWRAP_IDX,
1457                                        SPI_SETICONTITLEWRAP_REGKEY1,
1458                                        SPI_SETICONTITLEWRAP_REGKEY2,
1459                                        SPI_SETICONTITLEWRAP_VALNAME,
1460                                        &icon_metrics.iTitleWrap, uiParam, fWinIni );
1461         break;
1462
1463     case SPI_GETMENUDROPALIGNMENT:
1464         ret = get_uint_param( SPI_SETMENUDROPALIGNMENT_IDX,
1465                               SPI_SETMENUDROPALIGNMENT_REGKEY1,
1466                               SPI_SETMENUDROPALIGNMENT_VALNAME,
1467                               &menu_drop_alignment, pvParam );
1468         break;
1469
1470     case SPI_SETMENUDROPALIGNMENT:
1471         ret = set_uint_param_mirrored( SPI_SETMENUDROPALIGNMENT_IDX,
1472                                        SPI_SETMENUDROPALIGNMENT_REGKEY1,
1473                                        SPI_SETMENUDROPALIGNMENT_REGKEY2,
1474                                        SPI_SETMENUDROPALIGNMENT_VALNAME,
1475                                        &menu_drop_alignment, uiParam, fWinIni );
1476         break;
1477
1478     case SPI_SETDOUBLECLKWIDTH:
1479         ret = set_uint_param_mirrored( SPI_SETDOUBLECLKWIDTH_IDX,
1480                                        SPI_SETDOUBLECLKWIDTH_REGKEY1,
1481                                        SPI_SETDOUBLECLKWIDTH_REGKEY2,
1482                                        SPI_SETDOUBLECLKWIDTH_VALNAME,
1483                                        &double_click_width, uiParam, fWinIni );
1484         break;
1485
1486     case SPI_SETDOUBLECLKHEIGHT:
1487         ret = set_uint_param_mirrored( SPI_SETDOUBLECLKHEIGHT_IDX,
1488                                        SPI_SETDOUBLECLKHEIGHT_REGKEY1,
1489                                        SPI_SETDOUBLECLKHEIGHT_REGKEY2,
1490                                        SPI_SETDOUBLECLKHEIGHT_VALNAME,
1491                                        &double_click_height, uiParam, fWinIni );
1492         break;
1493
1494     case SPI_GETICONTITLELOGFONT:
1495     {
1496         LOGFONTW lfDefault;
1497
1498         if (!pvParam) return FALSE;
1499
1500         spi_idx = SPI_SETICONTITLELOGFONT_IDX;
1501         if (!spi_loaded[spi_idx])
1502         {
1503             if (!reg_get_logfont( SPI_SETICONTITLELOGFONT_REGKEY,
1504                                   SPI_SETICONTITLELOGFONT_VALNAME, &icon_metrics.lfFont ))
1505             {
1506                 INT r;
1507
1508                 /*
1509                  * The 'default GDI fonts' seems to be returned.
1510                  * If a returned font is not a correct font in your environment,
1511                  * please try to fix objects/gdiobj.c at first.
1512                  */
1513                 GetObjectW( GetStockObject( DEFAULT_GUI_FONT ), sizeof(LOGFONTW), &lfDefault );
1514
1515                 GetProfileStringW( Desktop, IconTitleFaceName,
1516                                    lfDefault.lfFaceName,
1517                                    icon_metrics.lfFont.lfFaceName,
1518                                    LF_FACESIZE );
1519                 
1520                 r = GetProfileIntW( Desktop, IconTitleSize, 0 );
1521                 if (r)
1522                     icon_metrics.lfFont.lfHeight = -r;
1523                 else
1524                     icon_metrics.lfFont.lfHeight = lfDefault.lfHeight;
1525
1526                 icon_metrics.lfFont.lfWidth = 0;
1527                 icon_metrics.lfFont.lfEscapement = icon_metrics.lfFont.lfOrientation = 0;
1528                 icon_metrics.lfFont.lfWeight = FW_NORMAL;
1529                 icon_metrics.lfFont.lfItalic = FALSE;
1530                 icon_metrics.lfFont.lfStrikeOut = FALSE;
1531                 icon_metrics.lfFont.lfUnderline = FALSE;
1532                 icon_metrics.lfFont.lfCharSet = lfDefault.lfCharSet; /* at least 'charset' should not be hard-coded */
1533                 icon_metrics.lfFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
1534                 icon_metrics.lfFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
1535                 icon_metrics.lfFont.lfQuality = DEFAULT_QUALITY;
1536                 icon_metrics.lfFont.lfPitchAndFamily = DEFAULT_PITCH;
1537                 spi_loaded[spi_idx] = TRUE;
1538             }
1539         }
1540         *(LOGFONTW *)pvParam = icon_metrics.lfFont;
1541         break;
1542     }
1543
1544     case SPI_SETDOUBLECLICKTIME:
1545         ret = set_uint_param( SPI_SETDOUBLECLICKTIME_IDX,
1546                               SPI_SETDOUBLECLICKTIME_REGKEY,
1547                               SPI_SETDOUBLECLICKTIME_VALNAME,
1548                               &double_click_time, uiParam, fWinIni );
1549         break;
1550
1551     case SPI_SETMOUSEBUTTONSWAP:
1552         ret = set_bool_param( SPI_SETMOUSEBUTTONSWAP_IDX,
1553                               SPI_SETMOUSEBUTTONSWAP_REGKEY,
1554                               SPI_SETMOUSEBUTTONSWAP_VALNAME,
1555                               &swap_buttons, uiParam, fWinIni );
1556         break;
1557
1558     case SPI_SETICONTITLELOGFONT:               /*     34 */
1559         if( uiParam == sizeof(LOGFONTW)) {
1560             ret = SYSPARAMS_SaveLogFont( SPI_SETICONTITLELOGFONT_REGKEY,
1561                     SPI_SETICONTITLELOGFONT_VALNAME, pvParam, fWinIni);
1562             if( ret) {
1563                 icon_metrics.lfFont = *(LOGFONTW *)pvParam;
1564                 spi_loaded[SPI_SETICONTITLELOGFONT_IDX] = TRUE;
1565             }
1566         } else
1567             ret = FALSE;
1568         break;
1569
1570     case SPI_GETFASTTASKSWITCH:                 /*     35 */
1571         if (!pvParam) return FALSE;
1572         *(BOOL *)pvParam = 1;
1573         break;
1574
1575     case SPI_SETFASTTASKSWITCH:                 /*     36 */
1576         /* the action is disabled */
1577         ret = FALSE;
1578         break;
1579
1580     case SPI_SETDRAGFULLWINDOWS:
1581         ret = set_bool_param( SPI_SETDRAGFULLWINDOWS_IDX,
1582                               SPI_SETDRAGFULLWINDOWS_REGKEY,
1583                               SPI_SETDRAGFULLWINDOWS_VALNAME,
1584                               &drag_full_windows, uiParam, fWinIni );
1585         break;
1586
1587     case SPI_GETDRAGFULLWINDOWS:
1588         ret = get_bool_param( SPI_SETDRAGFULLWINDOWS_IDX,
1589                               SPI_SETDRAGFULLWINDOWS_REGKEY,
1590                               SPI_SETDRAGFULLWINDOWS_VALNAME,
1591                               &drag_full_windows, pvParam );
1592         break;
1593
1594     case SPI_GETNONCLIENTMETRICS:
1595     {
1596         LPNONCLIENTMETRICSW lpnm = pvParam;
1597
1598         if (!spi_loaded[SPI_NONCLIENTMETRICS_IDX]) load_nonclient_metrics();
1599
1600         if (lpnm && lpnm->cbSize == sizeof(NONCLIENTMETRICSW))
1601             *lpnm = nonclient_metrics;
1602         else
1603             ret = FALSE;
1604         break;
1605     }
1606
1607     case SPI_SETNONCLIENTMETRICS:
1608     {
1609         LPNONCLIENTMETRICSW lpnm = pvParam;
1610
1611         if (lpnm && lpnm->cbSize == sizeof(NONCLIENTMETRICSW))
1612         {
1613             NONCLIENTMETRICSW ncm;
1614             ret = set_uint_param( SPI_SETBORDER_IDX,
1615                     SPI_SETBORDER_REGKEY, SPI_SETBORDER_VALNAME,
1616                     &border, lpnm->iBorderWidth, fWinIni );
1617             if( ret) ret = save_int_param( METRICS_REGKEY,
1618                     METRICS_SCROLLWIDTH_VALNAME, NULL,
1619                     lpnm->iScrollWidth, fWinIni );
1620             if( ret) ret = save_int_param( METRICS_REGKEY,
1621                     METRICS_SCROLLHEIGHT_VALNAME, NULL,
1622                     lpnm->iScrollHeight, fWinIni );
1623             if( ret) ret = save_int_param( METRICS_REGKEY,
1624                     METRICS_CAPTIONWIDTH_VALNAME, NULL,
1625                     lpnm->iCaptionWidth, fWinIni );
1626             if( ret) ret = save_int_param( METRICS_REGKEY,
1627                     METRICS_CAPTIONHEIGHT_VALNAME, NULL,
1628                     lpnm->iCaptionHeight, fWinIni );
1629             if( ret) ret = save_int_param( METRICS_REGKEY,
1630                     METRICS_SMCAPTIONWIDTH_VALNAME, NULL,
1631                     lpnm->iSmCaptionWidth, fWinIni );
1632             if( ret) ret = save_int_param( METRICS_REGKEY,
1633                     METRICS_SMCAPTIONHEIGHT_VALNAME, NULL,
1634                     lpnm->iSmCaptionHeight, fWinIni );
1635             if( ret) ret = save_int_param( METRICS_REGKEY,
1636                     METRICS_MENUWIDTH_VALNAME, NULL,
1637                     lpnm->iMenuWidth, fWinIni );
1638             if( ret) ret = save_int_param( METRICS_REGKEY,
1639                     METRICS_MENUHEIGHT_VALNAME, NULL,
1640                     lpnm->iMenuHeight, fWinIni );
1641             if( ret) ret = SYSPARAMS_SaveLogFont(
1642                     METRICS_REGKEY, METRICS_MENULOGFONT_VALNAME,
1643                     &lpnm->lfMenuFont, fWinIni);
1644             if( ret) ret = SYSPARAMS_SaveLogFont(
1645                     METRICS_REGKEY, METRICS_CAPTIONLOGFONT_VALNAME,
1646                     &lpnm->lfCaptionFont, fWinIni);
1647             if( ret) ret = SYSPARAMS_SaveLogFont(
1648                     METRICS_REGKEY, METRICS_SMCAPTIONLOGFONT_VALNAME,
1649                     &lpnm->lfSmCaptionFont, fWinIni);
1650             if( ret) ret = SYSPARAMS_SaveLogFont(
1651                     METRICS_REGKEY, METRICS_STATUSLOGFONT_VALNAME,
1652                     &lpnm->lfStatusFont, fWinIni);
1653             if( ret) ret = SYSPARAMS_SaveLogFont(
1654                     METRICS_REGKEY, METRICS_MESSAGELOGFONT_VALNAME,
1655                     &lpnm->lfMessageFont, fWinIni);
1656             if( ret) {
1657                 ncm = *lpnm;
1658                 normalize_nonclientmetrics( &ncm);
1659                 nonclient_metrics = ncm;
1660                 spi_loaded[SPI_NONCLIENTMETRICS_IDX] = TRUE;
1661             }
1662         }
1663         break;
1664     }
1665
1666     case SPI_GETMINIMIZEDMETRICS:
1667     {
1668         MINIMIZEDMETRICS * lpMm = pvParam;
1669         if (lpMm && lpMm->cbSize == sizeof(*lpMm)) {
1670             if( spi_loaded[SPI_MINIMIZEDMETRICS_IDX]) load_minimized_metrics();
1671             *lpMm = minimized_metrics;
1672         } else
1673             ret = FALSE;
1674         break;
1675     }
1676
1677     case SPI_SETMINIMIZEDMETRICS:
1678     {
1679         MINIMIZEDMETRICS * lpMm = pvParam;
1680         if (lpMm && lpMm->cbSize == sizeof(*lpMm)) {
1681             ret = save_int_param( METRICS_REGKEY, METRICS_MINWIDTH_VALNAME,
1682                                   &minimized_metrics.iWidth, max( lpMm->iWidth, 0), fWinIni);
1683             if( ret) ret = save_int_param( METRICS_REGKEY,
1684                                            METRICS_MINHORZGAP_VALNAME, &minimized_metrics.iHorzGap,
1685                                            max( lpMm->iHorzGap, 0), fWinIni);
1686             if( ret) ret = save_int_param( METRICS_REGKEY,
1687                                            METRICS_MINVERTGAP_VALNAME, &minimized_metrics.iVertGap,
1688                                            max( lpMm->iVertGap, 0), fWinIni);
1689             if( ret) ret = save_int_param( METRICS_REGKEY,
1690                                            METRICS_MINARRANGE_VALNAME, &minimized_metrics.iArrange,
1691                                            0x0f & lpMm->iArrange, fWinIni);
1692             if( ret) spi_loaded[SPI_MINIMIZEDMETRICS_IDX] = TRUE;
1693         } else
1694             ret = FALSE;
1695         break;
1696     }
1697
1698     case SPI_GETICONMETRICS:
1699     {
1700         LPICONMETRICSW lpIcon = pvParam;
1701         if(lpIcon && lpIcon->cbSize == sizeof(*lpIcon))
1702         {
1703             SystemParametersInfoW( SPI_ICONHORIZONTALSPACING, 0,
1704                                    &lpIcon->iHorzSpacing, FALSE );
1705             SystemParametersInfoW( SPI_ICONVERTICALSPACING, 0,
1706                                    &lpIcon->iVertSpacing, FALSE );
1707             SystemParametersInfoW( SPI_GETICONTITLEWRAP, 0,
1708                                    &lpIcon->iTitleWrap, FALSE );
1709             SystemParametersInfoW( SPI_GETICONTITLELOGFONT, 0,
1710                                    &lpIcon->lfFont, FALSE );
1711         }
1712         else
1713         {
1714             ret = FALSE;
1715         }
1716         break;
1717     }
1718
1719     case SPI_SETICONMETRICS:
1720     {
1721         LPICONMETRICSW lpIcon = pvParam;
1722         if (lpIcon && lpIcon->cbSize == sizeof(*lpIcon)) {
1723             ret = set_int_param( SPI_ICONVERTICALSPACING_IDX,
1724                                  SPI_ICONVERTICALSPACING_REGKEY,
1725                                  SPI_ICONVERTICALSPACING_VALNAME,
1726                                  &icon_metrics.iVertSpacing,
1727                                  lpIcon->iVertSpacing, fWinIni);
1728             if( ret) {
1729                 ret = set_int_param( SPI_ICONHORIZONTALSPACING_IDX,
1730                                      SPI_ICONHORIZONTALSPACING_REGKEY,
1731                                      SPI_ICONHORIZONTALSPACING_VALNAME,
1732                                      &icon_metrics.iHorzSpacing,
1733                                      lpIcon->iHorzSpacing, fWinIni );
1734             }
1735             if( ret) {
1736                 ret = set_bool_param_mirrored( SPI_SETICONTITLEWRAP_IDX,
1737                     SPI_SETICONTITLEWRAP_REGKEY1, SPI_SETICONTITLEWRAP_REGKEY2,
1738                     SPI_SETICONTITLEWRAP_VALNAME, &icon_metrics.iTitleWrap,
1739                     lpIcon->iTitleWrap, fWinIni );
1740             }
1741             if( ret) ret = SYSPARAMS_SaveLogFont( SPI_SETICONTITLELOGFONT_REGKEY,
1742                     SPI_SETICONTITLELOGFONT_VALNAME, &lpIcon->lfFont, fWinIni);
1743             if( ret) {
1744                 icon_metrics.lfFont = lpIcon->lfFont;
1745                 spi_loaded[SPI_SETICONTITLELOGFONT_IDX] = TRUE;
1746             }
1747         } else
1748             ret = FALSE;
1749         break;
1750     }
1751
1752     case SPI_SETWORKAREA:                       /*     47  WINVER >= 0x400 */
1753     {
1754         if (!pvParam) return FALSE;
1755
1756         spi_idx = SPI_SETWORKAREA_IDX;
1757         CopyRect( &work_area, pvParam );
1758         spi_loaded[spi_idx] = TRUE;
1759         break;
1760     }
1761
1762     case SPI_GETWORKAREA:                       /*     48  WINVER >= 0x400 */
1763     {
1764         if (!pvParam) return FALSE;
1765
1766         spi_idx = SPI_SETWORKAREA_IDX;
1767         if (!spi_loaded[spi_idx])
1768         {
1769             SetRect( &work_area, 0, 0,
1770                      GetSystemMetrics( SM_CXSCREEN ),
1771                      GetSystemMetrics( SM_CYSCREEN ) );
1772             EnumDisplayMonitors( 0, NULL, enum_monitors, (LPARAM)&work_area );
1773             spi_loaded[spi_idx] = TRUE;
1774         }
1775         CopyRect( pvParam, &work_area );
1776         TRACE("work area %s\n", wine_dbgstr_rect( &work_area ));
1777         break;
1778     }
1779
1780     WINE_SPI_FIXME(SPI_SETPENWINDOWS);          /*     49  WINVER >= 0x400 */
1781
1782     case SPI_GETFILTERKEYS:                     /*     50 */
1783     {
1784         LPFILTERKEYS lpFilterKeys = pvParam;
1785         WARN("SPI_GETFILTERKEYS not fully implemented\n");
1786         if (lpFilterKeys && lpFilterKeys->cbSize == sizeof(FILTERKEYS))
1787         {
1788             /* Indicate that no FilterKeys feature available */
1789             lpFilterKeys->dwFlags = 0;
1790             lpFilterKeys->iWaitMSec = 0;
1791             lpFilterKeys->iDelayMSec = 0;
1792             lpFilterKeys->iRepeatMSec = 0;
1793             lpFilterKeys->iBounceMSec = 0;
1794          }
1795         else
1796         {
1797             ret = FALSE;
1798         }
1799         break;
1800     }
1801     WINE_SPI_FIXME(SPI_SETFILTERKEYS);          /*     51 */
1802
1803     case SPI_GETTOGGLEKEYS:                     /*     52 */
1804     {
1805         LPTOGGLEKEYS lpToggleKeys = pvParam;
1806         WARN("SPI_GETTOGGLEKEYS not fully implemented\n");
1807         if (lpToggleKeys && lpToggleKeys->cbSize == sizeof(TOGGLEKEYS))
1808         {
1809             /* Indicate that no ToggleKeys feature available */
1810             lpToggleKeys->dwFlags = 0;
1811         }
1812         else
1813         {
1814             ret = FALSE;
1815         }
1816         break;
1817     }
1818     WINE_SPI_FIXME(SPI_SETTOGGLEKEYS);          /*     53 */
1819
1820     case SPI_GETMOUSEKEYS:                      /*     54 */
1821     {
1822         LPMOUSEKEYS lpMouseKeys = pvParam;
1823         WARN("SPI_GETMOUSEKEYS not fully implemented\n");
1824         if (lpMouseKeys && lpMouseKeys->cbSize == sizeof(MOUSEKEYS))
1825         {
1826             /* Indicate that no MouseKeys feature available */
1827             lpMouseKeys->dwFlags = 0;
1828             lpMouseKeys->iMaxSpeed = 360;
1829             lpMouseKeys->iTimeToMaxSpeed = 1000;
1830             lpMouseKeys->iCtrlSpeed = 0;
1831             lpMouseKeys->dwReserved1 = 0;
1832             lpMouseKeys->dwReserved2 = 0;
1833         }
1834         else
1835         {
1836             ret = FALSE;
1837         }
1838         break;
1839     }
1840     WINE_SPI_FIXME(SPI_SETMOUSEKEYS);           /*     55 */
1841
1842     case SPI_GETSHOWSOUNDS:
1843         ret = get_bool_param( SPI_SETSHOWSOUNDS_IDX,
1844                               SPI_SETSHOWSOUNDS_REGKEY,
1845                               SPI_SETSHOWSOUNDS_VALNAME,
1846                               &show_sounds, pvParam );
1847         break;
1848
1849     case SPI_SETSHOWSOUNDS:
1850         ret = set_bool_param( SPI_SETSHOWSOUNDS_IDX,
1851                               SPI_SETSHOWSOUNDS_REGKEY,
1852                               SPI_SETSHOWSOUNDS_VALNAME,
1853                               &show_sounds, uiParam, fWinIni );
1854         break;
1855
1856     case SPI_GETSTICKYKEYS:                     /*     58 */
1857     {
1858         LPSTICKYKEYS lpStickyKeys = pvParam;
1859         WARN("SPI_GETSTICKYKEYS not fully implemented\n");
1860         if (lpStickyKeys && lpStickyKeys->cbSize == sizeof(STICKYKEYS))
1861         {
1862             /* Indicate that no StickyKeys feature available */
1863             lpStickyKeys->dwFlags = 0;
1864         }
1865         else
1866         {
1867             ret = FALSE;
1868         }
1869         break;
1870     }
1871     WINE_SPI_FIXME(SPI_SETSTICKYKEYS);          /*     59 */
1872
1873     case SPI_GETACCESSTIMEOUT:                  /*     60 */
1874     {
1875         LPACCESSTIMEOUT lpAccessTimeout = pvParam;
1876         WARN("SPI_GETACCESSTIMEOUT not fully implemented\n");
1877         if (lpAccessTimeout && lpAccessTimeout->cbSize == sizeof(ACCESSTIMEOUT))
1878         {
1879             /* Indicate that no accessibility features timeout is available */
1880             lpAccessTimeout->dwFlags = 0;
1881             lpAccessTimeout->iTimeOutMSec = 0;
1882         }
1883         else
1884         {
1885             ret = FALSE;
1886         }
1887         break;
1888     }
1889     WINE_SPI_FIXME(SPI_SETACCESSTIMEOUT);       /*     61 */
1890
1891     case SPI_GETSERIALKEYS:                     /*     62  WINVER >= 0x400 */
1892     {
1893         LPSERIALKEYSW lpSerialKeysW = pvParam;
1894         WARN("SPI_GETSERIALKEYS not fully implemented\n");
1895         if (lpSerialKeysW && lpSerialKeysW->cbSize == sizeof(SERIALKEYSW))
1896         {
1897             /* Indicate that no SerialKeys feature available */
1898             lpSerialKeysW->dwFlags = 0;
1899             lpSerialKeysW->lpszActivePort = NULL;
1900             lpSerialKeysW->lpszPort = NULL;
1901             lpSerialKeysW->iBaudRate = 0;
1902             lpSerialKeysW->iPortState = 0;
1903         }
1904         else
1905         {
1906             ret = FALSE;
1907         }
1908         break;
1909     }
1910     WINE_SPI_FIXME(SPI_SETSERIALKEYS);          /*     63  WINVER >= 0x400 */
1911
1912     case SPI_GETSOUNDSENTRY:                    /*     64 */
1913     {
1914         LPSOUNDSENTRYW lpSoundSentryW = pvParam;
1915         WARN("SPI_GETSOUNDSENTRY not fully implemented\n");
1916         if (lpSoundSentryW && lpSoundSentryW->cbSize == sizeof(SOUNDSENTRYW))
1917         {
1918             /* Indicate that no SoundSentry feature available */
1919             lpSoundSentryW->dwFlags = 0;
1920             lpSoundSentryW->iFSTextEffect = 0;
1921             lpSoundSentryW->iFSTextEffectMSec = 0;
1922             lpSoundSentryW->iFSTextEffectColorBits = 0;
1923             lpSoundSentryW->iFSGrafEffect = 0;
1924             lpSoundSentryW->iFSGrafEffectMSec = 0;
1925             lpSoundSentryW->iFSGrafEffectColor = 0;
1926             lpSoundSentryW->iWindowsEffect = 0;
1927             lpSoundSentryW->iWindowsEffectMSec = 0;
1928             lpSoundSentryW->lpszWindowsEffectDLL = 0;
1929             lpSoundSentryW->iWindowsEffectOrdinal = 0;
1930         }
1931         else
1932         {
1933             ret = FALSE;
1934         }
1935         break;
1936     }
1937     WINE_SPI_FIXME(SPI_SETSOUNDSENTRY);         /*     65 */
1938
1939     case SPI_GETHIGHCONTRAST:                   /*     66  WINVER >= 0x400 */
1940     {
1941         LPHIGHCONTRASTW lpHighContrastW = pvParam;
1942         WARN("SPI_GETHIGHCONTRAST not fully implemented\n");
1943         if (lpHighContrastW && lpHighContrastW->cbSize == sizeof(HIGHCONTRASTW))
1944         {
1945             /* Indicate that no high contrast feature available */
1946             lpHighContrastW->dwFlags = 0;
1947             lpHighContrastW->lpszDefaultScheme = NULL;
1948         }
1949         else
1950         {
1951             ret = FALSE;
1952         }
1953         break;
1954     }
1955     WINE_SPI_FIXME(SPI_SETHIGHCONTRAST);        /*     67  WINVER >= 0x400 */
1956
1957     case SPI_GETKEYBOARDPREF:
1958         ret = get_bool_param( SPI_SETKEYBOARDPREF_IDX,
1959                               SPI_SETKEYBOARDPREF_REGKEY,
1960                               SPI_SETKEYBOARDPREF_VALNAME,
1961                               &keyboard_pref, pvParam );
1962         break;
1963
1964     case SPI_SETKEYBOARDPREF:
1965         ret = set_bool_param( SPI_SETKEYBOARDPREF_IDX,
1966                               SPI_SETKEYBOARDPREF_REGKEY,
1967                               SPI_SETKEYBOARDPREF_VALNAME,
1968                               &keyboard_pref, uiParam, fWinIni );
1969         break;
1970
1971     case SPI_GETSCREENREADER:
1972         ret = get_bool_param( SPI_SETSCREENREADER_IDX,
1973                               SPI_SETSCREENREADER_REGKEY,
1974                               SPI_SETSCREENREADER_VALNAME,
1975                               &screen_reader, pvParam );
1976         break;
1977
1978     case SPI_SETSCREENREADER:
1979         ret = set_bool_param( SPI_SETSCREENREADER_IDX,
1980                               SPI_SETSCREENREADER_REGKEY,
1981                               SPI_SETSCREENREADER_VALNAME,
1982                               &screen_reader, uiParam, fWinIni );
1983         break;
1984
1985     case SPI_GETANIMATION:                      /*     72  WINVER >= 0x400 */
1986     {
1987         LPANIMATIONINFO lpAnimInfo = pvParam;
1988
1989         /* Tell it "disabled" */
1990         if (lpAnimInfo && lpAnimInfo->cbSize == sizeof(ANIMATIONINFO))
1991             lpAnimInfo->iMinAnimate = 0; /* Minimise and restore animation is disabled (nonzero == enabled) */
1992         else
1993             ret = FALSE;
1994         break;
1995     }
1996     WINE_SPI_WARN(SPI_SETANIMATION);            /*     73  WINVER >= 0x400 */
1997
1998     case SPI_GETFONTSMOOTHING:
1999     {
2000         UINT tmpval;
2001         ret = get_uint_param( SPI_SETFONTSMOOTHING_IDX,
2002                               SPI_SETFONTSMOOTHING_REGKEY,
2003                               SPI_SETFONTSMOOTHING_VALNAME,
2004                               &font_smoothing, &tmpval );
2005         if (!pvParam) ret = FALSE;
2006
2007         if (ret)
2008             *(UINT *) pvParam = ( tmpval != 0);
2009         break;
2010     }
2011     case SPI_SETFONTSMOOTHING:
2012         uiParam = uiParam ? 2 : 0; /* Win NT4/2k/XP behavior */
2013         ret = set_uint_param( SPI_SETFONTSMOOTHING_IDX,
2014                               SPI_SETFONTSMOOTHING_REGKEY,
2015                               SPI_SETFONTSMOOTHING_VALNAME,
2016                               &font_smoothing, uiParam, fWinIni );
2017         break;
2018
2019     WINE_SPI_FIXME(SPI_SETDRAGWIDTH);           /*     76  WINVER >= 0x400 */
2020     WINE_SPI_FIXME(SPI_SETDRAGHEIGHT);          /*     77  WINVER >= 0x400 */
2021
2022     WINE_SPI_FIXME(SPI_SETHANDHELD);            /*     78  WINVER >= 0x400 */
2023
2024     WINE_SPI_FIXME(SPI_GETLOWPOWERTIMEOUT);     /*     79  WINVER >= 0x400 */
2025     WINE_SPI_FIXME(SPI_GETPOWEROFFTIMEOUT);     /*     80  WINVER >= 0x400 */
2026     WINE_SPI_FIXME(SPI_SETLOWPOWERTIMEOUT);     /*     81  WINVER >= 0x400 */
2027     WINE_SPI_FIXME(SPI_SETPOWEROFFTIMEOUT);     /*     82  WINVER >= 0x400 */
2028
2029     case SPI_GETLOWPOWERACTIVE:
2030         ret = get_bool_param( SPI_SETLOWPOWERACTIVE_IDX,
2031                               SPI_SETLOWPOWERACTIVE_REGKEY,
2032                               SPI_SETLOWPOWERACTIVE_VALNAME,
2033                               &lowpoweractive, pvParam );
2034         break;
2035
2036     case SPI_GETPOWEROFFACTIVE:
2037         ret = get_bool_param( SPI_SETPOWEROFFACTIVE_IDX,
2038                               SPI_SETPOWEROFFACTIVE_REGKEY,
2039                               SPI_SETPOWEROFFACTIVE_VALNAME,
2040                               &poweroffactive, pvParam );
2041         break;
2042
2043     case SPI_SETLOWPOWERACTIVE:
2044         ret = set_bool_param( SPI_SETLOWPOWERACTIVE_IDX,
2045                               SPI_SETLOWPOWERACTIVE_REGKEY,
2046                               SPI_SETLOWPOWERACTIVE_VALNAME,
2047                               &lowpoweractive, uiParam, fWinIni );
2048         break;
2049
2050     case SPI_SETPOWEROFFACTIVE:
2051         ret = set_bool_param( SPI_SETPOWEROFFACTIVE_IDX,
2052                               SPI_SETPOWEROFFACTIVE_REGKEY,
2053                               SPI_SETPOWEROFFACTIVE_VALNAME,
2054                               &poweroffactive, uiParam, fWinIni );
2055         break;
2056
2057     WINE_SPI_FIXME(SPI_SETCURSORS);             /*     87  WINVER >= 0x400 */
2058     WINE_SPI_FIXME(SPI_SETICONS);               /*     88  WINVER >= 0x400 */
2059
2060     case SPI_GETDEFAULTINPUTLANG:       /*     89  WINVER >= 0x400 */
2061         ret = GetKeyboardLayout(0) ? TRUE : FALSE;
2062         break;
2063
2064     WINE_SPI_FIXME(SPI_SETDEFAULTINPUTLANG);    /*     90  WINVER >= 0x400 */
2065
2066     WINE_SPI_FIXME(SPI_SETLANGTOGGLE);          /*     91  WINVER >= 0x400 */
2067
2068     case SPI_GETWINDOWSEXTENSION:               /*     92  WINVER >= 0x400 */
2069         WARN("pretend no support for Win9x Plus! for now.\n");
2070         ret = FALSE; /* yes, this is the result value */
2071         break;
2072
2073     WINE_SPI_FIXME(SPI_SETMOUSETRAILS);         /*     93  WINVER >= 0x400 */
2074     WINE_SPI_FIXME(SPI_GETMOUSETRAILS);         /*     94  WINVER >= 0x400 */
2075
2076     case SPI_GETSNAPTODEFBUTTON:                /*     95  WINVER >= 0x400 */
2077         ret = get_bool_param( SPI_SETSNAPTODEFBUTTON_IDX,
2078                               SPI_SETSNAPTODEFBUTTON_REGKEY,
2079                               SPI_SETSNAPTODEFBUTTON_VALNAME,
2080                               &snap_to_default_button, pvParam );
2081         break;
2082
2083     case SPI_SETSNAPTODEFBUTTON:                /*     96  WINVER >= 0x400 */
2084         ret = set_bool_param( SPI_SETSNAPTODEFBUTTON_IDX,
2085                               SPI_SETSNAPTODEFBUTTON_REGKEY,
2086                               SPI_SETSNAPTODEFBUTTON_VALNAME,
2087                               &snap_to_default_button, uiParam, fWinIni );
2088         break;
2089
2090     case SPI_SETSCREENSAVERRUNNING:
2091         ret = set_bool_param( SPI_SETSCREENSAVERRUNNING_IDX,
2092                               SPI_SETSCREENSAVERRUNNING_REGKEY,
2093                               SPI_SETSCREENSAVERRUNNING_VALNAME,
2094                               &screensaver_running, uiParam, fWinIni );
2095         break;
2096
2097     case SPI_GETMOUSEHOVERWIDTH:
2098         ret = get_uint_param( SPI_SETMOUSEHOVERWIDTH_IDX,
2099                               SPI_SETMOUSEHOVERWIDTH_REGKEY,
2100                               SPI_SETMOUSEHOVERWIDTH_VALNAME,
2101                               &mouse_hover_width, pvParam );
2102         break;
2103
2104     case SPI_SETMOUSEHOVERWIDTH:
2105         ret = set_uint_param( SPI_SETMOUSEHOVERWIDTH_IDX,
2106                               SPI_SETMOUSEHOVERWIDTH_REGKEY,
2107                               SPI_SETMOUSEHOVERWIDTH_VALNAME,
2108                               &mouse_hover_width, uiParam, fWinIni );
2109         break;
2110
2111     case SPI_GETMOUSEHOVERHEIGHT:
2112         ret = get_uint_param( SPI_SETMOUSEHOVERHEIGHT_IDX,
2113                               SPI_SETMOUSEHOVERHEIGHT_REGKEY,
2114                               SPI_SETMOUSEHOVERHEIGHT_VALNAME,
2115                               &mouse_hover_height, pvParam );
2116         break;
2117
2118     case SPI_SETMOUSEHOVERHEIGHT:
2119         ret = set_uint_param( SPI_SETMOUSEHOVERHEIGHT_IDX,
2120                               SPI_SETMOUSEHOVERHEIGHT_REGKEY,
2121                               SPI_SETMOUSEHOVERHEIGHT_VALNAME,
2122                               &mouse_hover_height, uiParam, fWinIni );
2123         break;
2124
2125     case SPI_GETMOUSEHOVERTIME:
2126         ret = get_uint_param( SPI_SETMOUSEHOVERTIME_IDX,
2127                               SPI_SETMOUSEHOVERTIME_REGKEY,
2128                               SPI_SETMOUSEHOVERTIME_VALNAME,
2129                               &mouse_hover_time, pvParam );
2130         break;
2131
2132     case SPI_SETMOUSEHOVERTIME:
2133         ret = set_uint_param( SPI_SETMOUSEHOVERTIME_IDX,
2134                               SPI_SETMOUSEHOVERTIME_REGKEY,
2135                               SPI_SETMOUSEHOVERTIME_VALNAME,
2136                               &mouse_hover_time, uiParam, fWinIni );
2137         break;
2138
2139     case SPI_GETWHEELSCROLLLINES:
2140         ret = get_uint_param( SPI_SETMOUSESCROLLLINES_IDX,
2141                               SPI_SETMOUSESCROLLLINES_REGKEY,
2142                               SPI_SETMOUSESCROLLLINES_VALNAME,
2143                               &mouse_scroll_lines, pvParam );
2144         break;
2145
2146     case SPI_SETWHEELSCROLLLINES:
2147         ret = set_uint_param( SPI_SETMOUSESCROLLLINES_IDX,
2148                               SPI_SETMOUSESCROLLLINES_REGKEY,
2149                               SPI_SETMOUSESCROLLLINES_VALNAME,
2150                               &mouse_scroll_lines, uiParam, fWinIni );
2151         break;
2152
2153     case SPI_GETMENUSHOWDELAY:
2154         ret = get_uint_param( SPI_SETMENUSHOWDELAY_IDX,
2155                               SPI_SETMENUSHOWDELAY_REGKEY,
2156                               SPI_SETMENUSHOWDELAY_VALNAME,
2157                               &menu_show_delay, pvParam );
2158         break;
2159
2160     case SPI_SETMENUSHOWDELAY:
2161         ret = set_uint_param( SPI_SETMENUSHOWDELAY_IDX,
2162                               SPI_SETMENUSHOWDELAY_REGKEY,
2163                               SPI_SETMENUSHOWDELAY_VALNAME,
2164                               &menu_show_delay, uiParam, fWinIni );
2165         break;
2166
2167     case SPI_GETWHEELSCROLLCHARS:                       /*    108  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
2168         ret = get_uint_param( SPI_SETMOUSESCROLLCHARS_IDX,
2169                               SPI_SETMOUSESCROLLCHARS_REGKEY,
2170                               SPI_SETMOUSESCROLLCHARS_VALNAME,
2171                               &mouse_scroll_chars, pvParam );
2172         break;
2173
2174     case SPI_SETWHEELSCROLLCHARS:                       /*    109  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
2175         ret = set_uint_param( SPI_SETMOUSESCROLLCHARS_IDX,
2176                               SPI_SETMOUSESCROLLCHARS_REGKEY,
2177                               SPI_SETMOUSESCROLLCHARS_VALNAME,
2178                               &mouse_scroll_chars, uiParam, fWinIni );
2179         break;
2180
2181     WINE_SPI_FIXME(SPI_GETSHOWIMEUI);           /*    110  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
2182     WINE_SPI_FIXME(SPI_SETSHOWIMEUI);           /*    111  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
2183
2184     case SPI_GETMOUSESPEED:             /*    112  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2185         ret = get_uint_param( SPI_SETMOUSESPEED_IDX,
2186                               SPI_SETMOUSESPEED_REGKEY,
2187                               SPI_SETMOUSESPEED_VALNAME,
2188                               &mouse_sensitivity, pvParam );
2189         break;
2190
2191     case SPI_SETMOUSESPEED:                     /*    113  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2192         ret = set_uint_param( SPI_SETMOUSESPEED_IDX,
2193                               SPI_SETMOUSESPEED_REGKEY,
2194                               SPI_SETMOUSESPEED_VALNAME,
2195                               &mouse_sensitivity, PtrToInt(pvParam), fWinIni );
2196
2197         break;
2198
2199     case SPI_GETSCREENSAVERRUNNING:
2200         ret = get_bool_param( SPI_SETSCREENSAVERRUNNING_IDX,
2201                               SPI_SETSCREENSAVERRUNNING_REGKEY,
2202                               SPI_SETSCREENSAVERRUNNING_VALNAME,
2203                               &screensaver_running, pvParam );
2204         break;
2205
2206     case SPI_GETDESKWALLPAPER:                  /*    115  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2207     {
2208         WCHAR buf[MAX_PATH];
2209
2210         if (!pvParam) return FALSE;
2211
2212         if (uiParam > MAX_PATH)
2213         {
2214             uiParam = MAX_PATH;
2215         }
2216
2217         if (SYSPARAMS_Load(SPI_SETDESKWALLPAPER_REGKEY, SPI_SETDESKWALLPAPER_VALNAME, buf, sizeof(buf)))
2218         {
2219             lstrcpynW(pvParam, buf, uiParam);
2220         }
2221         else
2222         {
2223             /* Return an empty string */
2224             memset(pvParam, 0, uiParam);
2225         }
2226
2227         break;
2228     }
2229
2230     WINE_SPI_FIXME(SPI_GETACTIVEWINDOWTRACKING);/* 0x1000  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2231     WINE_SPI_FIXME(SPI_SETACTIVEWINDOWTRACKING);/* 0x1001  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2232     case SPI_GETMENUANIMATION:             /* 0x1002  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2233         ret = get_user_pref_param( 0, 0x02, pvParam );
2234         break;
2235
2236     case SPI_SETMENUANIMATION:             /* 0x1003  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2237         ret = set_user_pref_param( 0, 0x02, PtrToUlong(pvParam), fWinIni );
2238         break;
2239
2240     case SPI_GETCOMBOBOXANIMATION:         /* 0x1004  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2241         ret = get_user_pref_param( 0, 0x04, pvParam );
2242         break;
2243
2244     case SPI_SETCOMBOBOXANIMATION:         /* 0x1005  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2245         ret = set_user_pref_param( 0, 0x04, PtrToUlong(pvParam), fWinIni );
2246         break;
2247
2248     case SPI_GETLISTBOXSMOOTHSCROLLING:    /* 0x1006  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2249         ret = get_user_pref_param( 0, 0x08, pvParam );
2250         break;
2251
2252     case SPI_SETLISTBOXSMOOTHSCROLLING:    /* 0x1007  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2253         ret = set_user_pref_param( 0, 0x08, PtrToUlong(pvParam), fWinIni );
2254         break;
2255
2256     case SPI_GETGRADIENTCAPTIONS:
2257         ret = get_user_pref_param( 0, 0x10, pvParam );
2258         break;
2259
2260     case SPI_SETGRADIENTCAPTIONS:
2261         ret = set_user_pref_param( 0, 0x10, PtrToUlong(pvParam), fWinIni );
2262         break;
2263
2264     case SPI_GETKEYBOARDCUES:
2265         ret = get_user_pref_param( 0, 0x20, pvParam );
2266         break;
2267
2268     case SPI_SETKEYBOARDCUES:
2269         ret = set_user_pref_param( 0, 0x20, PtrToUlong(pvParam), fWinIni );
2270         break;
2271
2272     WINE_SPI_FIXME(SPI_GETACTIVEWNDTRKZORDER);  /* 0x100C  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2273     WINE_SPI_FIXME(SPI_SETACTIVEWNDTRKZORDER);  /* 0x100D  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2274     case SPI_GETHOTTRACKING:
2275         ret = get_user_pref_param( 0, 0x80, pvParam );
2276         break;
2277
2278     case SPI_SETHOTTRACKING:
2279         ret = set_user_pref_param( 0, 0x80, PtrToUlong(pvParam), fWinIni );
2280         break;
2281
2282     WINE_SPI_FIXME(SPI_GETMENUFADE);            /* 0x1012  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2283     WINE_SPI_FIXME(SPI_SETMENUFADE);            /* 0x1013  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2284     case SPI_GETSELECTIONFADE:                  /* 0x1014  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2285         ret = get_user_pref_param( 1, 0x04, pvParam );
2286         break;
2287
2288     case SPI_SETSELECTIONFADE:                  /* 0x1015  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2289         ret = set_user_pref_param( 1, 0x04, PtrToUlong(pvParam), fWinIni );
2290         break;
2291
2292     case SPI_GETTOOLTIPANIMATION:               /* 0x1016  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2293         ret = get_user_pref_param( 1, 0x08, pvParam );
2294         break;
2295
2296     case SPI_SETTOOLTIPANIMATION:               /* 0x1017  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2297         ret = set_user_pref_param( 1, 0x08, PtrToUlong(pvParam), fWinIni );
2298         break;
2299
2300     case SPI_GETTOOLTIPFADE:                    /* 0x1018  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2301         ret = get_user_pref_param( 1, 0x10, pvParam );
2302         break;
2303
2304     case SPI_SETTOOLTIPFADE:                    /* 0x1019  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2305         ret = set_user_pref_param( 1, 0x10, PtrToUlong(pvParam), fWinIni );
2306         break;
2307
2308     case SPI_GETCURSORSHADOW:                   /* 0x101A  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2309         ret = get_user_pref_param( 1, 0x20, pvParam );
2310         break;
2311
2312     case SPI_SETCURSORSHADOW:                   /* 0x101B  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2313         ret = set_user_pref_param( 1, 0x20, PtrToUlong(pvParam), fWinIni );
2314         break;
2315
2316     WINE_SPI_FIXME(SPI_GETMOUSESONAR);          /* 0x101C  _WIN32_WINNT >= 0x510 || _WIN32_WINDOW >= 0x490*/
2317     WINE_SPI_FIXME(SPI_SETMOUSESONAR);          /* 0x101D  _WIN32_WINNT >= 0x510 || _WIN32_WINDOW >= 0x490*/
2318     WINE_SPI_FIXME(SPI_GETMOUSECLICKLOCK);      /* 0x101E  _WIN32_WINNT >= 0x510 || _WIN32_WINDOW >= 0x490*/
2319     WINE_SPI_FIXME(SPI_SETMOUSECLICKLOCK);      /* 0x101F  _WIN32_WINNT >= 0x510 || _WIN32_WINDOW >= 0x490*/
2320     WINE_SPI_FIXME(SPI_GETMOUSEVANISH);         /* 0x1020  _WIN32_WINNT >= 0x510 || _WIN32_WINDOW >= 0x490*/
2321     WINE_SPI_FIXME(SPI_SETMOUSEVANISH);         /* 0x1021  _WIN32_WINNT >= 0x510 || _WIN32_WINDOW >= 0x490*/
2322     case SPI_GETFLATMENU:
2323         ret = get_user_pref_param( 2, 0x02, pvParam );
2324         break;
2325
2326     case SPI_SETFLATMENU:
2327         ret = set_user_pref_param( 2, 0x02, PtrToUlong(pvParam), fWinIni );
2328         break;
2329
2330     WINE_SPI_FIXME(SPI_GETDROPSHADOW);          /* 0x1024  _WIN32_WINNT >= 0x510 */
2331     WINE_SPI_FIXME(SPI_SETDROPSHADOW);          /* 0x1025  _WIN32_WINNT >= 0x510 */
2332     WINE_SPI_FIXME(SPI_GETBLOCKSENDINPUTRESETS);
2333     WINE_SPI_FIXME(SPI_SETBLOCKSENDINPUTRESETS);
2334     case SPI_GETUIEFFECTS:
2335         ret = get_user_pref_param( 3, 0x80, pvParam );
2336         break;
2337
2338     case SPI_SETUIEFFECTS:
2339         /* FIXME: this probably should mask other UI effect values when unset */
2340         ret = set_user_pref_param( 3, 0x80, PtrToUlong(pvParam), fWinIni );
2341         break;
2342
2343     case SPI_GETFOREGROUNDLOCKTIMEOUT:          /* 0x2000  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2344         ret = get_uint_param( SPI_SETFOREGROUNDLOCKTIMEOUT_IDX,
2345                               SPI_SETFOREGROUNDLOCKTIMEOUT_REGKEY,
2346                               SPI_SETFOREGROUNDLOCKTIMEOUT_VALNAME,
2347                               &foreground_lock_timeout, pvParam );
2348         break;
2349
2350     case SPI_SETFOREGROUNDLOCKTIMEOUT:          /* 0x2001  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2351         /* FIXME: this should check that the calling thread
2352          * is able to change the foreground window */
2353         ret = set_uint_param( SPI_SETFOREGROUNDLOCKTIMEOUT_IDX,
2354                               SPI_SETFOREGROUNDLOCKTIMEOUT_REGKEY,
2355                               SPI_SETFOREGROUNDLOCKTIMEOUT_VALNAME,
2356                               &foreground_lock_timeout, PtrToUlong(pvParam), fWinIni );
2357         break;
2358
2359     WINE_SPI_FIXME(SPI_GETACTIVEWNDTRKTIMEOUT); /* 0x2002  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2360     WINE_SPI_FIXME(SPI_SETACTIVEWNDTRKTIMEOUT); /* 0x2003  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2361     WINE_SPI_FIXME(SPI_GETFOREGROUNDFLASHCOUNT);/* 0x2004  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2362     WINE_SPI_FIXME(SPI_SETFOREGROUNDFLASHCOUNT);/* 0x2005  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2363     case SPI_GETCARETWIDTH:          /* 0x2006  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2364         ret = get_uint_param( SPI_CARETWIDTH_IDX,
2365                               SPI_CARETWIDTH_REGKEY,
2366                               SPI_CARETWIDTH_VALNAME,
2367                               &caret_width, pvParam );
2368         break;
2369
2370     case SPI_SETCARETWIDTH:          /* 0x2007  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2371         ret = set_uint_param( SPI_CARETWIDTH_IDX,
2372                               SPI_CARETWIDTH_REGKEY,
2373                               SPI_CARETWIDTH_VALNAME,
2374                               &caret_width, uiParam, fWinIni );
2375         break;
2376
2377     WINE_SPI_FIXME(SPI_GETMOUSECLICKLOCKTIME);  /* 0x2008  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2378     WINE_SPI_FIXME(SPI_SETMOUSECLICKLOCKTIME);  /* 0x2009  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2379     case SPI_GETFONTSMOOTHINGTYPE:              /* 0x200A  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2380         spi_idx = SPI_SETFONTSMOOTHINGTYPE_IDX;
2381         if (!spi_loaded[spi_idx])
2382         {
2383             ret = SYSPARAMS_Load( SPI_SETFONTSMOOTHINGTYPE_REGKEY,
2384                                   SPI_SETFONTSMOOTHINGTYPE_VALNAME,
2385                                   (LPWSTR)&font_smoothing_type,
2386                                   sizeof(font_smoothing_type) );
2387             if ( ret) spi_loaded[spi_idx] = TRUE;
2388         }
2389         if (!pvParam) ret = FALSE;
2390
2391         if (ret)
2392             *(UINT *)pvParam = font_smoothing_type;
2393         break;
2394
2395     case SPI_SETFONTSMOOTHINGTYPE:              /* 0x200B  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2396         spi_idx = SPI_SETFONTSMOOTHINGTYPE_IDX;
2397         if (SYSPARAMS_SaveRaw( SPI_SETFONTSMOOTHINGTYPE_REGKEY,
2398                                SPI_SETFONTSMOOTHINGTYPE_VALNAME,
2399                                (LPBYTE)&pvParam, sizeof(UINT), REG_DWORD, fWinIni ))
2400         {
2401             font_smoothing_type = PtrToUlong(pvParam);
2402             spi_loaded[spi_idx] = TRUE;
2403         }
2404         else
2405             ret = FALSE;
2406         break;
2407
2408     case SPI_GETFONTSMOOTHINGCONTRAST:          /* 0x200C  _WIN32_WINNT >= 0x510 */
2409         spi_idx = SPI_SETFONTSMOOTHINGCONTRAST_IDX;
2410         if (!spi_loaded[spi_idx])
2411         {
2412             ret = SYSPARAMS_Load( SPI_SETFONTSMOOTHINGCONTRAST_REGKEY,
2413                                   SPI_SETFONTSMOOTHINGCONTRAST_VALNAME,
2414                                   (LPWSTR)&font_smoothing_contrast,
2415                                   sizeof(font_smoothing_contrast) );
2416             if (ret)
2417                 spi_loaded[spi_idx] = TRUE;
2418         }
2419         if (!pvParam) ret = FALSE;
2420
2421         if (ret)
2422             *(UINT *)pvParam = font_smoothing_contrast;
2423         break;
2424
2425     case SPI_SETFONTSMOOTHINGCONTRAST:          /* 0x200D  _WIN32_WINNT >= 0x510 */
2426         spi_idx = SPI_SETFONTSMOOTHINGCONTRAST_IDX;
2427         if (SYSPARAMS_SaveRaw( SPI_SETFONTSMOOTHINGCONTRAST_REGKEY,
2428                                SPI_SETFONTSMOOTHINGCONTRAST_VALNAME,
2429                                (LPBYTE)&pvParam, sizeof(UINT), REG_DWORD, fWinIni ))
2430         {
2431             font_smoothing_contrast = PtrToUlong(pvParam);
2432             spi_loaded[spi_idx] = TRUE;
2433         }
2434         else
2435             ret = FALSE;
2436         break;
2437
2438     WINE_SPI_FIXME(SPI_GETFOCUSBORDERWIDTH);    /* 0x200E  _WIN32_WINNT >= 0x510 */
2439     WINE_SPI_FIXME(SPI_SETFOCUSBORDERWIDTH);    /* 0x200F  _WIN32_WINNT >= 0x510 */
2440     WINE_SPI_FIXME(SPI_GETFOCUSBORDERHEIGHT);    /* 0x2010  _WIN32_WINNT >= 0x510 */
2441     WINE_SPI_FIXME(SPI_SETFOCUSBORDERHEIGHT);    /* 0x2011  _WIN32_WINNT >= 0x510 */
2442     case SPI_GETFONTSMOOTHINGORIENTATION:       /* 0x2012 */
2443         spi_idx = SPI_SETFONTSMOOTHINGORIENTATION_IDX;
2444         if (!spi_loaded[spi_idx])
2445         {
2446             ret = SYSPARAMS_Load( SPI_SETFONTSMOOTHINGORIENTATION_REGKEY,
2447                                   SPI_SETFONTSMOOTHINGORIENTATION_VALNAME,
2448                                   (LPWSTR)&font_smoothing_orientation,
2449                                   sizeof(font_smoothing_orientation) );
2450             if (ret)
2451                 spi_loaded[spi_idx] = TRUE;
2452         }
2453         if (!pvParam) ret = FALSE;
2454
2455         if (ret)
2456             *(UINT *)pvParam = font_smoothing_orientation;
2457         break;
2458
2459     case SPI_SETFONTSMOOTHINGORIENTATION:       /* 0x2013 */
2460         spi_idx = SPI_SETFONTSMOOTHINGORIENTATION_IDX;
2461         if (SYSPARAMS_SaveRaw( SPI_SETFONTSMOOTHINGORIENTATION_REGKEY,
2462                                SPI_SETFONTSMOOTHINGORIENTATION_VALNAME,
2463                                (LPBYTE)&pvParam, sizeof(UINT), REG_DWORD, fWinIni ))
2464         {
2465             font_smoothing_orientation = PtrToUlong(pvParam);
2466             spi_loaded[spi_idx] = TRUE;
2467         }
2468         else
2469             ret = FALSE;
2470         break;
2471
2472     default:
2473         FIXME( "Unknown action: %u\n", uiAction );
2474         SetLastError( ERROR_INVALID_SPI_VALUE );
2475         ret = FALSE;
2476         break;
2477     }
2478
2479     if (ret)
2480         SYSPARAMS_NotifyChange( uiAction, fWinIni );
2481     TRACE("(%u, %u, %p, %u) ret %d\n",
2482             uiAction, uiParam, pvParam, fWinIni, ret);
2483     return ret;
2484
2485 #undef WINE_SPI_FIXME
2486 #undef WINE_SPI_WARN
2487 }
2488
2489
2490 /***********************************************************************
2491  *              SystemParametersInfo (USER.483)
2492  */
2493 BOOL16 WINAPI SystemParametersInfo16( UINT16 uAction, UINT16 uParam,
2494                                       LPVOID lpvParam, UINT16 fuWinIni )
2495 {
2496     BOOL16 ret;
2497
2498     TRACE("(%u, %u, %p, %u)\n", uAction, uParam, lpvParam, fuWinIni);
2499
2500     switch (uAction)
2501     {
2502     case SPI_GETBEEP:                           /*      1 */
2503     case SPI_GETSCREENSAVEACTIVE:               /*     16 */
2504     case SPI_GETICONTITLEWRAP:                  /*     25 */
2505     case SPI_GETMENUDROPALIGNMENT:              /*     27 */
2506     case SPI_GETFASTTASKSWITCH:                 /*     35 */
2507     case SPI_GETDRAGFULLWINDOWS:                /*     38  WINVER >= 0x0400 */
2508     {
2509         BOOL tmp;
2510         ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
2511         if (ret && lpvParam)
2512             *(BOOL16 *)lpvParam = tmp;
2513         break;
2514     }
2515
2516     case SPI_GETBORDER:                         /*      5 */
2517     case SPI_ICONHORIZONTALSPACING:             /*     13 */
2518     case SPI_GETSCREENSAVETIMEOUT:              /*     14 */
2519     case SPI_GETGRIDGRANULARITY:                /*     18 */
2520     case SPI_GETKEYBOARDDELAY:                  /*     22 */
2521     case SPI_ICONVERTICALSPACING:               /*     24 */
2522     {
2523         INT tmp;
2524         ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
2525         if (ret && lpvParam)
2526             *(INT16 *)lpvParam = tmp;
2527         break;
2528     }
2529
2530     case SPI_GETKEYBOARDSPEED:                  /*     10 */
2531     {
2532         DWORD tmp;
2533         ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
2534         if (ret && lpvParam)
2535             *(WORD *)lpvParam = tmp;
2536         break;
2537     }
2538
2539     case SPI_GETICONTITLELOGFONT:               /*     31 */
2540     {
2541         LOGFONTA tmp;
2542         ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
2543         if (ret && lpvParam)
2544             SYSPARAMS_LogFont32ATo16( &tmp, (LPLOGFONT16)lpvParam );
2545         break;
2546     }
2547
2548     case SPI_GETNONCLIENTMETRICS:               /*     41  WINVER >= 0x400 */
2549     {
2550         NONCLIENTMETRICSA tmp;
2551         LPNONCLIENTMETRICS16 lpnm16 = (LPNONCLIENTMETRICS16)lpvParam;
2552         if (lpnm16 && lpnm16->cbSize == sizeof(NONCLIENTMETRICS16))
2553         {
2554             tmp.cbSize = sizeof(NONCLIENTMETRICSA);
2555             ret = SystemParametersInfoA( uAction, uParam, &tmp, fuWinIni );
2556             if (ret)
2557                 SYSPARAMS_NonClientMetrics32ATo16( &tmp, lpnm16 );
2558         }
2559         else /* winfile 95 sets cbSize to 340 */
2560             ret = SystemParametersInfoA( uAction, uParam, lpvParam, fuWinIni );
2561         break;
2562     }
2563
2564     case SPI_GETWORKAREA:                       /*     48  WINVER >= 0x400 */
2565     {
2566         RECT tmp;
2567         ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
2568         if (ret && lpvParam)
2569         {
2570             RECT16 *r16 = lpvParam;
2571             r16->left   = tmp.left;
2572             r16->top    = tmp.top;
2573             r16->right  = tmp.right;
2574             r16->bottom = tmp.bottom;
2575         }
2576         break;
2577     }
2578
2579     case SPI_GETMOUSEHOVERWIDTH:                /*     98  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
2580     case SPI_GETMOUSEHOVERHEIGHT:               /*    100  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
2581     case SPI_GETMOUSEHOVERTIME:                 /*    102  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
2582     {
2583         UINT tmp;
2584         ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
2585         if (ret && lpvParam)
2586             *(UINT16 *)lpvParam = tmp;
2587         break;
2588     }
2589
2590     default:
2591         ret = SystemParametersInfoA( uAction, uParam, lpvParam, fuWinIni );
2592     }
2593
2594     return ret;
2595 }
2596
2597 /***********************************************************************
2598  *              SystemParametersInfoA (USER32.@)
2599  */
2600 BOOL WINAPI SystemParametersInfoA( UINT uiAction, UINT uiParam,
2601                                    PVOID pvParam, UINT fuWinIni )
2602 {
2603     BOOL ret;
2604
2605     TRACE("(%u, %u, %p, %u)\n", uiAction, uiParam, pvParam, fuWinIni);
2606
2607     switch (uiAction)
2608     {
2609     case SPI_SETDESKWALLPAPER:                  /*     20 */
2610     case SPI_SETDESKPATTERN:                    /*     21 */
2611     {
2612         WCHAR buffer[256];
2613         if (pvParam)
2614             if (!MultiByteToWideChar( CP_ACP, 0, pvParam, -1, buffer,
2615                                       sizeof(buffer)/sizeof(WCHAR) ))
2616                 buffer[sizeof(buffer)/sizeof(WCHAR)-1] = 0;
2617         ret = SystemParametersInfoW( uiAction, uiParam, pvParam ? buffer : NULL, fuWinIni );
2618         break;
2619     }
2620
2621     case SPI_GETICONTITLELOGFONT:               /*     31 */
2622     {
2623         LOGFONTW tmp;
2624         ret = SystemParametersInfoW( uiAction, uiParam, pvParam ? &tmp : NULL, fuWinIni );
2625         if (ret && pvParam)
2626             SYSPARAMS_LogFont32WTo32A( &tmp, pvParam );
2627         break;
2628     }
2629
2630     case SPI_GETNONCLIENTMETRICS:               /*     41  WINVER >= 0x400 */
2631     {
2632         NONCLIENTMETRICSW tmp;
2633         LPNONCLIENTMETRICSA lpnmA = pvParam;
2634         if (lpnmA && lpnmA->cbSize == sizeof(NONCLIENTMETRICSA))
2635         {
2636             tmp.cbSize = sizeof(NONCLIENTMETRICSW);
2637             ret = SystemParametersInfoW( uiAction, uiParam, &tmp, fuWinIni );
2638             if (ret)
2639                 SYSPARAMS_NonClientMetrics32WTo32A( &tmp, lpnmA );
2640         }
2641         else
2642             ret = FALSE;
2643         break;
2644     }
2645
2646     case SPI_SETNONCLIENTMETRICS:               /*     42  WINVER >= 0x400 */
2647     {
2648         NONCLIENTMETRICSW tmp;
2649         LPNONCLIENTMETRICSA lpnmA = pvParam;
2650         if (lpnmA && lpnmA->cbSize == sizeof(NONCLIENTMETRICSA))
2651         {
2652             tmp.cbSize = sizeof(NONCLIENTMETRICSW);
2653             SYSPARAMS_NonClientMetrics32ATo32W( lpnmA, &tmp );
2654             ret = SystemParametersInfoW( uiAction, uiParam, &tmp, fuWinIni );
2655         }
2656         else
2657             ret = FALSE;
2658         break;
2659     }
2660
2661     case SPI_GETICONMETRICS:                    /*     45  WINVER >= 0x400 */
2662     {
2663         ICONMETRICSW tmp;
2664         LPICONMETRICSA lpimA = pvParam;
2665         if (lpimA && lpimA->cbSize == sizeof(ICONMETRICSA))
2666         {
2667             tmp.cbSize = sizeof(ICONMETRICSW);
2668             ret = SystemParametersInfoW( uiAction, uiParam, &tmp, fuWinIni );
2669             if (ret)
2670             {
2671                 lpimA->iHorzSpacing = tmp.iHorzSpacing;
2672                 lpimA->iVertSpacing = tmp.iVertSpacing;
2673                 lpimA->iTitleWrap   = tmp.iTitleWrap;
2674                 SYSPARAMS_LogFont32WTo32A( &tmp.lfFont, &lpimA->lfFont );
2675             }
2676         }
2677         else
2678             ret = FALSE;
2679         break;
2680     }
2681
2682     case SPI_SETICONMETRICS:                    /*     46  WINVER >= 0x400 */
2683     {
2684         ICONMETRICSW tmp;
2685         LPICONMETRICSA lpimA = pvParam;
2686         if (lpimA && lpimA->cbSize == sizeof(ICONMETRICSA))
2687         {
2688             tmp.cbSize = sizeof(ICONMETRICSW);
2689             tmp.iHorzSpacing = lpimA->iHorzSpacing;
2690             tmp.iVertSpacing = lpimA->iVertSpacing;
2691             tmp.iTitleWrap = lpimA->iTitleWrap;
2692             SYSPARAMS_LogFont32ATo32W(  &lpimA->lfFont, &tmp.lfFont);
2693             ret = SystemParametersInfoW( uiAction, uiParam, &tmp, fuWinIni );
2694         }
2695         else
2696             ret = FALSE;
2697         break;
2698     }
2699
2700     case SPI_GETHIGHCONTRAST:                   /*     66  WINVER >= 0x400 */
2701     {
2702         HIGHCONTRASTW tmp;
2703         LPHIGHCONTRASTA lphcA = pvParam;
2704         if (lphcA && lphcA->cbSize == sizeof(HIGHCONTRASTA))
2705         {
2706             tmp.cbSize = sizeof(HIGHCONTRASTW);
2707             ret = SystemParametersInfoW( uiAction, uiParam, &tmp, fuWinIni );
2708             if (ret)
2709             {
2710                 lphcA->dwFlags = tmp.dwFlags;
2711                 lphcA->lpszDefaultScheme = NULL;  /* FIXME? */
2712             }
2713         }
2714         else
2715             ret = FALSE;
2716         break;
2717     }
2718
2719     case SPI_GETDESKWALLPAPER:                  /*     115 */
2720     {
2721         WCHAR buffer[MAX_PATH];
2722         ret = (SystemParametersInfoW( SPI_GETDESKWALLPAPER, uiParam, buffer, fuWinIni ) &&
2723                WideCharToMultiByte(CP_ACP, 0, buffer, -1, pvParam, uiParam, NULL, NULL));
2724         break;
2725     }
2726
2727     default:
2728         ret = SystemParametersInfoW( uiAction, uiParam, pvParam, fuWinIni );
2729         break;
2730     }
2731     return ret;
2732 }
2733
2734
2735 /***********************************************************************
2736  *              GetSystemMetrics (USER32.@)
2737  */
2738 INT WINAPI GetSystemMetrics( INT index )
2739 {
2740     UINT ret;
2741
2742     /* some metrics are dynamic */
2743     switch (index)
2744     {
2745     case SM_CXSCREEN:
2746         return GetDeviceCaps( get_display_dc(), HORZRES );
2747     case SM_CYSCREEN:
2748         return GetDeviceCaps( get_display_dc(), VERTRES );
2749     case SM_CXVSCROLL:
2750         if (!spi_loaded[SPI_NONCLIENTMETRICS_IDX]) load_nonclient_metrics();
2751         return nonclient_metrics.iScrollWidth;
2752     case SM_CYHSCROLL:
2753         return GetSystemMetrics(SM_CXVSCROLL);
2754     case SM_CYCAPTION:
2755         if (!spi_loaded[SPI_NONCLIENTMETRICS_IDX]) load_nonclient_metrics();
2756         return nonclient_metrics.iCaptionHeight + 1;
2757     case SM_CXBORDER:
2758     case SM_CYBORDER:
2759         /* SM_C{X,Y}BORDER always returns 1 regardless of 'BorderWidth' value in registry */
2760         return 1;
2761     case SM_CXDLGFRAME:
2762     case SM_CYDLGFRAME:
2763         return 3;
2764     case SM_CYVTHUMB:
2765         if (!spi_loaded[SPI_NONCLIENTMETRICS_IDX]) load_nonclient_metrics();
2766         return nonclient_metrics.iScrollHeight;
2767     case SM_CXHTHUMB:
2768         return GetSystemMetrics(SM_CYVTHUMB);
2769     case SM_CXICON:
2770         if (!spi_loaded[SPI_NONCLIENTMETRICS_IDX]) load_nonclient_metrics();
2771         return icon_size.cx;
2772     case SM_CYICON:
2773         if (!spi_loaded[SPI_NONCLIENTMETRICS_IDX]) load_nonclient_metrics();
2774         return icon_size.cy;
2775     case SM_CXCURSOR:
2776     case SM_CYCURSOR:
2777         return 32;
2778     case SM_CYMENU:
2779         return GetSystemMetrics(SM_CYMENUSIZE) + 1;
2780     case SM_CXFULLSCREEN:
2781         /* see the remark for SM_CXMAXIMIZED, at least this formulation is
2782          * correct */
2783         return GetSystemMetrics( SM_CXMAXIMIZED) - 2 * GetSystemMetrics( SM_CXFRAME);
2784     case SM_CYFULLSCREEN:
2785         /* see the remark for SM_CYMAXIMIZED, at least this formulation is
2786          * correct */
2787         return GetSystemMetrics( SM_CYMAXIMIZED) - GetSystemMetrics( SM_CYMIN);
2788     case SM_CYKANJIWINDOW:
2789         return 0;
2790     case SM_MOUSEPRESENT:
2791         return 1;
2792     case SM_CYVSCROLL:
2793         if (!spi_loaded[SPI_NONCLIENTMETRICS_IDX]) load_nonclient_metrics();
2794         return nonclient_metrics.iScrollHeight;
2795     case SM_CXHSCROLL:
2796         if (!spi_loaded[SPI_NONCLIENTMETRICS_IDX]) load_nonclient_metrics();
2797         return nonclient_metrics.iScrollHeight;
2798     case SM_DEBUG:
2799         return 0;
2800     case SM_SWAPBUTTON:
2801         get_bool_param( SPI_SETMOUSEBUTTONSWAP_IDX, SPI_SETMOUSEBUTTONSWAP_REGKEY,
2802                         SPI_SETMOUSEBUTTONSWAP_VALNAME, &swap_buttons, (BOOL*)&ret );
2803         return ret;
2804     case SM_RESERVED1:
2805     case SM_RESERVED2:
2806     case SM_RESERVED3:
2807     case SM_RESERVED4:
2808         return 0;
2809     case SM_CXMIN:
2810         if (!spi_loaded[SPI_NONCLIENTMETRICS_IDX]) load_nonclient_metrics();
2811         return 3 * nonclient_metrics.iCaptionWidth + GetSystemMetrics( SM_CYSIZE) +
2812             4 * CaptionFontAvCharWidth + 2 * GetSystemMetrics( SM_CXFRAME) + 4;
2813     case SM_CYMIN:
2814         return GetSystemMetrics( SM_CYCAPTION) + 2 * GetSystemMetrics( SM_CYFRAME);
2815     case SM_CXSIZE:
2816         if (!spi_loaded[SPI_NONCLIENTMETRICS_IDX]) load_nonclient_metrics();
2817         return nonclient_metrics.iCaptionWidth;
2818     case SM_CYSIZE:
2819         if (!spi_loaded[SPI_NONCLIENTMETRICS_IDX]) load_nonclient_metrics();
2820         return nonclient_metrics.iCaptionHeight;
2821     case SM_CXFRAME:
2822         if (!spi_loaded[SPI_NONCLIENTMETRICS_IDX]) load_nonclient_metrics();
2823         return GetSystemMetrics(SM_CXDLGFRAME) + nonclient_metrics.iBorderWidth;
2824     case SM_CYFRAME:
2825         if (!spi_loaded[SPI_NONCLIENTMETRICS_IDX]) load_nonclient_metrics();
2826         return GetSystemMetrics(SM_CYDLGFRAME) + nonclient_metrics.iBorderWidth;
2827     case SM_CXMINTRACK:
2828         return GetSystemMetrics(SM_CXMIN);
2829     case SM_CYMINTRACK:
2830         return GetSystemMetrics(SM_CYMIN);
2831     case SM_CXDOUBLECLK:
2832         get_uint_param( SPI_SETDOUBLECLKWIDTH_IDX, SPI_SETDOUBLECLKWIDTH_REGKEY1,
2833                         SPI_SETDOUBLECLKWIDTH_VALNAME, &double_click_width, &ret );
2834         return ret;
2835     case SM_CYDOUBLECLK:
2836         get_uint_param( SPI_SETDOUBLECLKHEIGHT_IDX, SPI_SETDOUBLECLKHEIGHT_REGKEY1,
2837                         SPI_SETDOUBLECLKHEIGHT_VALNAME, &double_click_height, &ret );
2838         return ret;
2839     case SM_CXICONSPACING:
2840         SystemParametersInfoW( SPI_ICONHORIZONTALSPACING, 0, &ret, 0 );
2841         return ret;
2842     case SM_CYICONSPACING:
2843         SystemParametersInfoW( SPI_ICONVERTICALSPACING, 0, &ret, 0 );
2844         return ret;
2845     case SM_MENUDROPALIGNMENT:
2846         SystemParametersInfoW( SPI_GETMENUDROPALIGNMENT, 0, &ret, 0 );
2847         return ret;
2848     case SM_PENWINDOWS:
2849         return 0;
2850     case SM_DBCSENABLED:
2851     {
2852         CPINFO cpinfo;
2853         GetCPInfo( CP_ACP, &cpinfo );
2854         return (cpinfo.MaxCharSize > 1);
2855     }
2856     case SM_CMOUSEBUTTONS:
2857         return 3;
2858     case SM_SECURE:
2859         return 0;
2860     case SM_CXEDGE:
2861         return GetSystemMetrics(SM_CXBORDER) + 1;
2862     case SM_CYEDGE:
2863         return GetSystemMetrics(SM_CYBORDER) + 1;
2864     case SM_CXMINSPACING:
2865         if( spi_loaded[SPI_MINIMIZEDMETRICS_IDX]) load_minimized_metrics();
2866         return GetSystemMetrics(SM_CXMINIMIZED) + minimized_metrics.iHorzGap;
2867     case SM_CYMINSPACING:
2868         if( spi_loaded[SPI_MINIMIZEDMETRICS_IDX]) load_minimized_metrics();
2869         return GetSystemMetrics(SM_CYMINIMIZED) + minimized_metrics.iVertGap;
2870     case SM_CXSMICON:
2871     case SM_CYSMICON:
2872         return 16;
2873     case SM_CYSMCAPTION:
2874         return GetSystemMetrics(SM_CYSMSIZE) + 1;
2875     case SM_CXSMSIZE:
2876         if (!spi_loaded[SPI_NONCLIENTMETRICS_IDX]) load_nonclient_metrics();
2877         return nonclient_metrics.iSmCaptionWidth;
2878     case SM_CYSMSIZE:
2879         if (!spi_loaded[SPI_NONCLIENTMETRICS_IDX]) load_nonclient_metrics();
2880         return nonclient_metrics.iSmCaptionHeight;
2881     case SM_CXMENUSIZE:
2882         if (!spi_loaded[SPI_NONCLIENTMETRICS_IDX]) load_nonclient_metrics();
2883         return nonclient_metrics.iMenuWidth;
2884     case SM_CYMENUSIZE:
2885         if (!spi_loaded[SPI_NONCLIENTMETRICS_IDX]) load_nonclient_metrics();
2886         return nonclient_metrics.iMenuHeight;
2887     case SM_ARRANGE:
2888         if( spi_loaded[SPI_MINIMIZEDMETRICS_IDX]) load_minimized_metrics();
2889         return minimized_metrics.iArrange;
2890     case SM_CXMINIMIZED:
2891         if( spi_loaded[SPI_MINIMIZEDMETRICS_IDX]) load_minimized_metrics();
2892         return minimized_metrics.iWidth + 6;
2893     case SM_CYMINIMIZED:
2894         if (!spi_loaded[SPI_NONCLIENTMETRICS_IDX]) load_nonclient_metrics();
2895         return nonclient_metrics.iCaptionHeight + 6;
2896     case SM_CXMAXTRACK:
2897         return GetSystemMetrics(SM_CXVIRTUALSCREEN) + 4 + 2 * GetSystemMetrics(SM_CXFRAME);
2898     case SM_CYMAXTRACK:
2899         return GetSystemMetrics(SM_CYVIRTUALSCREEN) + 4 + 2 * GetSystemMetrics(SM_CYFRAME);
2900     case SM_CXMAXIMIZED:
2901         /* FIXME: subtract the width of any vertical application toolbars*/
2902         return GetSystemMetrics(SM_CXSCREEN) + 2 * GetSystemMetrics(SM_CXFRAME);
2903     case SM_CYMAXIMIZED:
2904         /* FIXME: subtract the width of any horizontal application toolbars*/
2905         return GetSystemMetrics(SM_CYSCREEN) + 2 * GetSystemMetrics(SM_CYCAPTION);
2906     case SM_NETWORK:
2907         return 3;  /* FIXME */
2908     case SM_CLEANBOOT:
2909         return 0; /* 0 = ok, 1 = failsafe, 2 = failsafe + network */
2910     case SM_CXDRAG:
2911     case SM_CYDRAG:
2912         return 4;
2913     case SM_SHOWSOUNDS:
2914         SystemParametersInfoW( SPI_GETSHOWSOUNDS, 0, &ret, 0 );
2915         return ret;
2916     case SM_CXMENUCHECK:
2917     case SM_CYMENUCHECK:
2918         if (!spi_loaded[SPI_NONCLIENTMETRICS_IDX]) load_nonclient_metrics();
2919         return tmMenuFont.tmHeight <= 0 ? 13 :
2920         ((tmMenuFont.tmHeight + tmMenuFont.tmExternalLeading + 1) / 2) * 2 - 1;
2921     case SM_SLOWMACHINE:
2922         return 0;  /* Never true */
2923     case SM_MIDEASTENABLED:
2924         return 0;  /* FIXME */
2925     case SM_MOUSEWHEELPRESENT:
2926         return 1;
2927     case SM_XVIRTUALSCREEN:
2928     {
2929         struct monitor_info info;
2930         get_monitors_info( &info );
2931         return info.virtual_rect.left;
2932     }
2933     case SM_YVIRTUALSCREEN:
2934     {
2935         struct monitor_info info;
2936         get_monitors_info( &info );
2937         return info.virtual_rect.top;
2938     }
2939     case SM_CXVIRTUALSCREEN:
2940     {
2941         struct monitor_info info;
2942         get_monitors_info( &info );
2943         return info.virtual_rect.right - info.virtual_rect.left;
2944     }
2945     case SM_CYVIRTUALSCREEN:
2946     {
2947         struct monitor_info info;
2948         get_monitors_info( &info );
2949         return info.virtual_rect.bottom - info.virtual_rect.top;
2950     }
2951     case SM_CMONITORS:
2952     {
2953         struct monitor_info info;
2954         get_monitors_info( &info );
2955         return info.count;
2956     }
2957     case SM_SAMEDISPLAYFORMAT:
2958         return 1;
2959     case SM_IMMENABLED:
2960         return 0;  /* FIXME */
2961     case SM_CXFOCUSBORDER:
2962     case SM_CYFOCUSBORDER:
2963         return 1;
2964     case SM_TABLETPC:
2965     case SM_MEDIACENTER:
2966         return 0;
2967     case SM_CMETRICS:
2968         return SM_CMETRICS;
2969     default:
2970         return 0;
2971     }
2972 }
2973
2974
2975 /***********************************************************************
2976  *              SwapMouseButton (USER32.@)
2977  *  Reverse or restore the meaning of the left and right mouse buttons
2978  *  fSwap  [I ] TRUE - reverse, FALSE - original
2979  * RETURN
2980  *   previous state 
2981  */
2982 BOOL WINAPI SwapMouseButton( BOOL fSwap )
2983 {
2984     BOOL prev = GetSystemMetrics(SM_SWAPBUTTON);
2985     SystemParametersInfoW(SPI_SETMOUSEBUTTONSWAP, fSwap, 0, 0);
2986     return prev;
2987 }
2988
2989
2990 /**********************************************************************
2991  *              SetDoubleClickTime (USER32.@)
2992  */
2993 BOOL WINAPI SetDoubleClickTime( UINT interval )
2994 {
2995     return SystemParametersInfoW(SPI_SETDOUBLECLICKTIME, interval, 0, 0);
2996 }
2997
2998
2999 /**********************************************************************
3000  *              GetDoubleClickTime (USER32.@)
3001  */
3002 UINT WINAPI GetDoubleClickTime(void)
3003 {
3004     UINT time = 0;
3005
3006     get_uint_param( SPI_SETDOUBLECLICKTIME_IDX,
3007                     SPI_SETDOUBLECLICKTIME_REGKEY,
3008                     SPI_SETDOUBLECLICKTIME_VALNAME,
3009                     &double_click_time, &time );
3010     if (!time) time = 500;
3011     return time;
3012 }
3013
3014
3015 /*************************************************************************
3016  *              GetSysColor (USER32.@)
3017  */
3018 COLORREF WINAPI GetSysColor( INT nIndex )
3019 {
3020     if (nIndex >= 0 && nIndex < NUM_SYS_COLORS)
3021         return SysColors[nIndex];
3022     else
3023         return 0;
3024 }
3025
3026
3027 /*************************************************************************
3028  *              SetSysColors (USER32.@)
3029  */
3030 BOOL WINAPI SetSysColors( INT nChanges, const INT *lpSysColor,
3031                               const COLORREF *lpColorValues )
3032 {
3033     int i;
3034
3035     for (i = 0; i < nChanges; i++) SYSPARAMS_SetSysColor( lpSysColor[i], lpColorValues[i] );
3036
3037     /* Send WM_SYSCOLORCHANGE message to all windows */
3038
3039     SendMessageTimeoutW( HWND_BROADCAST, WM_SYSCOLORCHANGE, 0, 0, SMTO_ABORTIFHUNG, 2000, NULL );
3040
3041     /* Repaint affected portions of all visible windows */
3042
3043     RedrawWindow( GetDesktopWindow(), NULL, 0,
3044                 RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_ALLCHILDREN );
3045     return TRUE;
3046 }
3047
3048
3049 /*************************************************************************
3050  *              SetSysColorsTemp (USER32.@)
3051  *
3052  * UNDOCUMENTED !!
3053  *
3054  * Called by W98SE desk.cpl Control Panel Applet:
3055  * handle = SetSysColorsTemp(ptr, ptr, nCount);     ("set" call)
3056  * result = SetSysColorsTemp(NULL, NULL, handle);   ("restore" call)
3057  *
3058  * pPens is an array of COLORREF values, which seems to be used
3059  * to indicate the color values to create new pens with.
3060  *
3061  * pBrushes is an array of solid brush handles (returned by a previous
3062  * CreateSolidBrush), which seems to contain the brush handles to set
3063  * for the system colors.
3064  *
3065  * n seems to be used for
3066  *   a) indicating the number of entries to operate on (length of pPens,
3067  *      pBrushes)
3068  *   b) passing the handle that points to the previously used color settings.
3069  *      I couldn't figure out in hell what kind of handle this is on
3070  *      Windows. I just use a heap handle instead. Shouldn't matter anyway.
3071  *
3072  * RETURNS
3073  *     heap handle of our own copy of the current syscolors in case of
3074  *                 "set" call, i.e. pPens, pBrushes != NULL.
3075  *     TRUE (unconditionally !) in case of "restore" call,
3076  *          i.e. pPens, pBrushes == NULL.
3077  *     FALSE in case of either pPens != NULL and pBrushes == NULL
3078  *          or pPens == NULL and pBrushes != NULL.
3079  *
3080  * I'm not sure whether this implementation is 100% correct. [AM]
3081  */
3082 DWORD WINAPI SetSysColorsTemp( const COLORREF *pPens, const HBRUSH *pBrushes, DWORD n)
3083 {
3084     DWORD i;
3085
3086     if (pPens && pBrushes) /* "set" call */
3087     {
3088         /* allocate our structure to remember old colors */
3089         LPVOID pOldCol = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD)+n*sizeof(HPEN)+n*sizeof(HBRUSH));
3090         LPVOID p = pOldCol;
3091         *(DWORD *)p = n; p = (char*)p + sizeof(DWORD);
3092         memcpy(p, SysColorPens, n*sizeof(HPEN)); p = (char*)p + n*sizeof(HPEN);
3093         memcpy(p, SysColorBrushes, n*sizeof(HBRUSH)); p = (char*)p + n*sizeof(HBRUSH);
3094
3095         for (i=0; i < n; i++)
3096         {
3097             SysColorPens[i] = CreatePen( PS_SOLID, 1, pPens[i] );
3098             SysColorBrushes[i] = pBrushes[i];
3099         }
3100
3101         return (DWORD)pOldCol; /* FIXME: pointer truncation */
3102     }
3103     if (!pPens && !pBrushes) /* "restore" call */
3104     {
3105         LPVOID pOldCol = (LPVOID)n; /* FIXME: not 64-bit safe */
3106         LPVOID p = pOldCol;
3107         DWORD nCount = *(DWORD *)p;
3108         p = (char*)p + sizeof(DWORD);
3109
3110         for (i=0; i < nCount; i++)
3111         {
3112             DeleteObject(SysColorPens[i]);
3113             SysColorPens[i] = *(HPEN *)p; p = (char*)p + sizeof(HPEN);
3114         }
3115         for (i=0; i < nCount; i++)
3116         {
3117             SysColorBrushes[i] = *(HBRUSH *)p; p = (char*)p + sizeof(HBRUSH);
3118         }
3119         /* get rid of storage structure */
3120         HeapFree(GetProcessHeap(), 0, pOldCol);
3121
3122         return TRUE;
3123     }
3124     return FALSE;
3125 }
3126
3127
3128 /***********************************************************************
3129  *              GetSysColorBrush (USER32.@)
3130  */
3131 HBRUSH WINAPI GetSysColorBrush( INT index )
3132 {
3133     if (0 <= index && index < NUM_SYS_COLORS) return SysColorBrushes[index];
3134     WARN("Unknown index(%d)\n", index );
3135     return GetStockObject(LTGRAY_BRUSH);
3136 }
3137
3138
3139 /***********************************************************************
3140  *              SYSCOLOR_GetPen
3141  */
3142 HPEN SYSCOLOR_GetPen( INT index )
3143 {
3144     /* We can assert here, because this function is internal to Wine */
3145     assert (0 <= index && index < NUM_SYS_COLORS);
3146     return SysColorPens[index];
3147 }
3148
3149
3150 /***********************************************************************
3151  *              ChangeDisplaySettingsA (USER32.@)
3152  */
3153 LONG WINAPI ChangeDisplaySettingsA( LPDEVMODEA devmode, DWORD flags )
3154 {
3155     if (devmode) devmode->dmDriverExtra = 0;
3156
3157     return ChangeDisplaySettingsExA(NULL,devmode,NULL,flags,NULL);
3158 }
3159
3160
3161 /***********************************************************************
3162  *              ChangeDisplaySettingsW (USER32.@)
3163  */
3164 LONG WINAPI ChangeDisplaySettingsW( LPDEVMODEW devmode, DWORD flags )
3165 {
3166     if (devmode) devmode->dmDriverExtra = 0;
3167
3168     return ChangeDisplaySettingsExW(NULL,devmode,NULL,flags,NULL);
3169 }
3170
3171
3172 /***********************************************************************
3173  *              ChangeDisplaySettingsExA (USER32.@)
3174  */
3175 LONG WINAPI ChangeDisplaySettingsExA( LPCSTR devname, LPDEVMODEA devmode, HWND hwnd,
3176                                       DWORD flags, LPVOID lparam )
3177 {
3178     LONG ret;
3179     UNICODE_STRING nameW;
3180
3181     if (devname) RtlCreateUnicodeStringFromAsciiz(&nameW, devname);
3182     else nameW.Buffer = NULL;
3183
3184     if (devmode)
3185     {
3186         DEVMODEW *devmodeW;
3187
3188         devmodeW = GdiConvertToDevmodeW(devmode);
3189         if (devmodeW)
3190         {
3191             ret = ChangeDisplaySettingsExW(nameW.Buffer, devmodeW, hwnd, flags, lparam);
3192             HeapFree(GetProcessHeap(), 0, devmodeW);
3193         }
3194         else
3195             ret = DISP_CHANGE_SUCCESSFUL;
3196     }
3197     else
3198     {
3199         ret = ChangeDisplaySettingsExW(nameW.Buffer, NULL, hwnd, flags, lparam);
3200     }
3201
3202     if (devname) RtlFreeUnicodeString(&nameW);
3203     return ret;
3204 }
3205
3206
3207 /***********************************************************************
3208  *              ChangeDisplaySettingsExW (USER32.@)
3209  */
3210 LONG WINAPI ChangeDisplaySettingsExW( LPCWSTR devname, LPDEVMODEW devmode, HWND hwnd,
3211                                       DWORD flags, LPVOID lparam )
3212 {
3213     /* make sure the desktop window is created before mode changing */
3214     GetDesktopWindow();
3215
3216     return USER_Driver->pChangeDisplaySettingsEx( devname, devmode, hwnd, flags, lparam );
3217 }
3218
3219
3220 /***********************************************************************
3221  *              EnumDisplaySettingsW (USER32.@)
3222  *
3223  * RETURNS
3224  *      TRUE if nth setting exists found (described in the LPDEVMODEW struct)
3225  *      FALSE if we do not have the nth setting
3226  */
3227 BOOL WINAPI EnumDisplaySettingsW( LPCWSTR name, DWORD n, LPDEVMODEW devmode )
3228 {
3229     return EnumDisplaySettingsExW(name, n, devmode, 0);
3230 }
3231
3232
3233 /***********************************************************************
3234  *              EnumDisplaySettingsA (USER32.@)
3235  */
3236 BOOL WINAPI EnumDisplaySettingsA(LPCSTR name,DWORD n,LPDEVMODEA devmode)
3237 {
3238     return EnumDisplaySettingsExA(name, n, devmode, 0);
3239 }
3240
3241
3242 /***********************************************************************
3243  *              EnumDisplaySettingsExA (USER32.@)
3244  */
3245 BOOL WINAPI EnumDisplaySettingsExA(LPCSTR lpszDeviceName, DWORD iModeNum,
3246                                    LPDEVMODEA lpDevMode, DWORD dwFlags)
3247 {
3248     DEVMODEW devmodeW;
3249     BOOL ret;
3250     UNICODE_STRING nameW;
3251
3252     if (lpszDeviceName) RtlCreateUnicodeStringFromAsciiz(&nameW, lpszDeviceName);
3253     else nameW.Buffer = NULL;
3254
3255     ret = EnumDisplaySettingsExW(nameW.Buffer,iModeNum,&devmodeW,dwFlags);
3256     if (ret)
3257     {
3258         lpDevMode->dmSize = FIELD_OFFSET(DEVMODEA, dmICMMethod);
3259         lpDevMode->dmSpecVersion = devmodeW.dmSpecVersion;
3260         lpDevMode->dmDriverVersion = devmodeW.dmDriverVersion;
3261         WideCharToMultiByte(CP_ACP, 0, devmodeW.dmDeviceName, -1,
3262                             (LPSTR)lpDevMode->dmDeviceName, CCHDEVICENAME, NULL, NULL);
3263         lpDevMode->dmDriverExtra      = 0; /* FIXME */
3264         lpDevMode->dmBitsPerPel       = devmodeW.dmBitsPerPel;
3265         lpDevMode->dmPelsHeight       = devmodeW.dmPelsHeight;
3266         lpDevMode->dmPelsWidth        = devmodeW.dmPelsWidth;
3267         lpDevMode->u2.dmDisplayFlags  = devmodeW.u2.dmDisplayFlags;
3268         lpDevMode->dmDisplayFrequency = devmodeW.dmDisplayFrequency;
3269         lpDevMode->dmFields           = devmodeW.dmFields;
3270
3271         lpDevMode->u1.s2.dmPosition.x = devmodeW.u1.s2.dmPosition.x;
3272         lpDevMode->u1.s2.dmPosition.y = devmodeW.u1.s2.dmPosition.y;
3273         lpDevMode->u1.s2.dmDisplayOrientation = devmodeW.u1.s2.dmDisplayOrientation;
3274         lpDevMode->u1.s2.dmDisplayFixedOutput = devmodeW.u1.s2.dmDisplayFixedOutput;
3275     }
3276     if (lpszDeviceName) RtlFreeUnicodeString(&nameW);
3277     return ret;
3278 }
3279
3280
3281 /***********************************************************************
3282  *              EnumDisplaySettingsExW (USER32.@)
3283  */
3284 BOOL WINAPI EnumDisplaySettingsExW(LPCWSTR lpszDeviceName, DWORD iModeNum,
3285                                    LPDEVMODEW lpDevMode, DWORD dwFlags)
3286 {
3287     /* make sure the desktop window is created before mode enumeration */
3288     GetDesktopWindow();
3289
3290     return USER_Driver->pEnumDisplaySettingsEx(lpszDeviceName, iModeNum, lpDevMode, dwFlags);
3291 }
3292
3293 /***********************************************************************
3294  *              SetProcessDPIAware   (USER32.@)
3295  */
3296 BOOL WINAPI SetProcessDPIAware( VOID )
3297 {
3298     FIXME( "stub!\n");
3299
3300     return TRUE;
3301 }