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