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