2 * System metrics functions
4 * Copyright 1994 Alexandre Julliard
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.
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.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 static int sysMetrics
[SM_CMETRICS
+1];
35 static HDC display_dc
;
38 /***********************************************************************
39 * RegistryTwips2Pixels
41 * Convert a a dimension value that was obtained from the registry. These are
42 * quoted as being "twips" values if negative and pixels if positive.
44 * MSDN Library - April 2001 -> Resource Kits ->
45 * Windows 2000 Resource Kit Reference ->
46 * Technical Reference to the Windows 2000 Registry ->
47 * HKEY_CURRENT_USER -> Control Panel -> Desktop -> WindowMetrics
49 * This is written as a function to prevent repeated evaluation of the
52 inline static int RegistryTwips2Pixels(int x
)
60 /***********************************************************************
61 * SYSMETRICS_GetRegistryMetric
63 * Get a registry entry from the already open key. This allows us to open the
64 * section once and read several values.
66 * Of course this function belongs somewhere more usable but here will do
69 static int SYSMETRICS_GetRegistryMetric (
70 HKEY hkey
, /* handle to the registry section */
71 const char *key
, /* value name in the section */
72 int default_value
) /* default to return */
74 int value
= default_value
;
78 DWORD type
, count
= sizeof(buffer
);
79 if(!RegQueryValueExA (hkey
, key
, 0, &type
, buffer
, &count
))
83 /* Are there any utilities for converting registry entries
86 /* FIXME_(reg)("We need reg format converter\n"); */
92 return RegistryTwips2Pixels(value
);
96 /***********************************************************************
99 * Initialisation of the system metrics array.
101 * Differences in return values between 3.1 and 95 apps under Win95 (FIXME ?):
102 * SM_CXVSCROLL x+1 x Fixed May 24, 1999 - Ronald B. Cemer
103 * SM_CYHSCROLL x+1 x Fixed May 24, 1999 - Ronald B. Cemer
104 * SM_CXDLGFRAME x-1 x Already fixed
105 * SM_CYDLGFRAME x-1 x Already fixed
106 * SM_CYCAPTION x+1 x Fixed May 24, 1999 - Ronald B. Cemer
107 * SM_CYMENU x-1 x Already fixed
108 * SM_CYFULLSCREEN x-1 x
109 * SM_CXFRAME Fixed July 6, 2001 - Bill Medland
111 * Starting at Win95 there are now a large number or Registry entries in the
112 * [WindowMetrics] section that are probably relevant here.
114 void SYSMETRICS_Init(void)
116 HKEY hkey
; /* key to the window metrics area of the registry */
119 display_dc
= CreateICA( "DISPLAY", NULL
, NULL
, NULL
);
120 assert( display_dc
);
122 if (RegOpenKeyExA (HKEY_CURRENT_USER
, "Control Panel\\desktop\\WindowMetrics",
123 0, KEY_QUERY_VALUE
, &hkey
) != ERROR_SUCCESS
) hkey
= 0;
125 sysMetrics
[SM_CXVSCROLL
] = SYSMETRICS_GetRegistryMetric( hkey
, "ScrollWidth", 16 );
126 sysMetrics
[SM_CYHSCROLL
] = sysMetrics
[SM_CXVSCROLL
];
128 /* The Win 2000 resource kit SAYS that this is governed by the ScrollHeight
129 * but on my computer that controls the CYV/CXH values. */
130 sysMetrics
[SM_CYCAPTION
] = SYSMETRICS_GetRegistryMetric(hkey
, "CaptionHeight", 18)
131 + 1; /* for the separator? */
133 sysMetrics
[SM_CYMENU
] = SYSMETRICS_GetRegistryMetric (hkey
, "MenuHeight", 18) + 1;
136 sysMetrics
[SM_CXDLGFRAME
] = 3;
137 sysMetrics
[SM_CYDLGFRAME
] = sysMetrics
[SM_CXDLGFRAME
];
139 /* force setting of SM_CXFRAME/SM_CYFRAME */
140 SystemParametersInfoA( SPI_GETBORDER
, 0, &dummy
, 0 );
142 sysMetrics
[SM_CXCURSOR
] = 32;
143 sysMetrics
[SM_CYCURSOR
] = 32;
144 sysMetrics
[SM_CXBORDER
] = 1;
145 sysMetrics
[SM_CYBORDER
] = sysMetrics
[SM_CXBORDER
];
146 sysMetrics
[SM_CYVTHUMB
] = sysMetrics
[SM_CXVSCROLL
];
147 sysMetrics
[SM_CXHTHUMB
] = sysMetrics
[SM_CYVTHUMB
];
148 sysMetrics
[SM_CXICON
] = 32;
149 sysMetrics
[SM_CYICON
] = 32;
150 sysMetrics
[SM_CYKANJIWINDOW
] = 0;
151 sysMetrics
[SM_MOUSEPRESENT
] = 1;
152 sysMetrics
[SM_CYVSCROLL
] = SYSMETRICS_GetRegistryMetric (hkey
, "ScrollHeight", sysMetrics
[SM_CXVSCROLL
]);
153 sysMetrics
[SM_CXHSCROLL
] = SYSMETRICS_GetRegistryMetric (hkey
, "ScrollHeight", sysMetrics
[SM_CYHSCROLL
]);
154 sysMetrics
[SM_DEBUG
] = 0;
156 sysMetrics
[SM_SWAPBUTTON
] = 0;
157 sysMetrics
[SM_SWAPBUTTON
] = SYSPARAMS_GetMouseButtonSwap();
159 sysMetrics
[SM_RESERVED1
] = 0;
160 sysMetrics
[SM_RESERVED2
] = 0;
161 sysMetrics
[SM_RESERVED3
] = 0;
162 sysMetrics
[SM_RESERVED4
] = 0;
164 /* FIXME: The following two are calculated, but how? */
165 sysMetrics
[SM_CXMIN
] = 112;
166 sysMetrics
[SM_CYMIN
] = 27;
168 sysMetrics
[SM_CXSIZE
] = SYSMETRICS_GetRegistryMetric (hkey
, "CaptionWidth", sysMetrics
[SM_CYCAPTION
] - 1);
169 sysMetrics
[SM_CYSIZE
] = sysMetrics
[SM_CYCAPTION
] - 1;
170 sysMetrics
[SM_CXMINTRACK
] = sysMetrics
[SM_CXMIN
];
171 sysMetrics
[SM_CYMINTRACK
] = sysMetrics
[SM_CYMIN
];
173 sysMetrics
[SM_CXDOUBLECLK
] = 4;
174 sysMetrics
[SM_CYDOUBLECLK
] = 4;
175 SYSPARAMS_GetDoubleClickSize( &sysMetrics
[SM_CXDOUBLECLK
], &sysMetrics
[SM_CYDOUBLECLK
] );
177 sysMetrics
[SM_CXICONSPACING
] = 75;
178 SystemParametersInfoA( SPI_ICONHORIZONTALSPACING
, 0,
179 &sysMetrics
[SM_CXICONSPACING
], 0 );
180 sysMetrics
[SM_CYICONSPACING
] = 75;
181 SystemParametersInfoA( SPI_ICONVERTICALSPACING
, 0,
182 &sysMetrics
[SM_CYICONSPACING
], 0 );
184 SystemParametersInfoA( SPI_GETMENUDROPALIGNMENT
, 0,
185 &sysMetrics
[SM_MENUDROPALIGNMENT
], 0 );
186 sysMetrics
[SM_PENWINDOWS
] = 0;
187 sysMetrics
[SM_DBCSENABLED
] = 0;
189 /* FIXME: Need to query X for the following */
190 sysMetrics
[SM_CMOUSEBUTTONS
] = 3;
192 sysMetrics
[SM_SECURE
] = 0;
193 sysMetrics
[SM_CXEDGE
] = sysMetrics
[SM_CXBORDER
] + 1;
194 sysMetrics
[SM_CYEDGE
] = sysMetrics
[SM_CXEDGE
];
195 sysMetrics
[SM_CXMINSPACING
] = 160;
196 sysMetrics
[SM_CYMINSPACING
] = 24;
197 sysMetrics
[SM_CXSMICON
] = 16;
198 sysMetrics
[SM_CYSMICON
] = 16;
199 sysMetrics
[SM_CYSMCAPTION
] = SYSMETRICS_GetRegistryMetric(hkey
, "SmCaptionHeight", 15) + 1;
200 sysMetrics
[SM_CXSMSIZE
] = SYSMETRICS_GetRegistryMetric(hkey
, "SmCaptionWidth", 13);
201 sysMetrics
[SM_CYSMSIZE
] = sysMetrics
[SM_CYSMCAPTION
] - 1;
202 sysMetrics
[SM_CXMENUSIZE
] = SYSMETRICS_GetRegistryMetric(hkey
, "MenuWidth", sysMetrics
[SM_CYMENU
] - 1);
203 sysMetrics
[SM_CYMENUSIZE
] = sysMetrics
[SM_CYMENU
] - 1;
205 /* FIXME: What do these mean? */
206 sysMetrics
[SM_ARRANGE
] = ARW_HIDE
;
207 sysMetrics
[SM_CXMINIMIZED
] = 160;
208 sysMetrics
[SM_CYMINIMIZED
] = 24;
210 /* FIXME: How do I calculate these? */
211 sysMetrics
[SM_NETWORK
] = 3;
213 /* For the following: 0 = ok, 1 = failsafe, 2 = failsafe + network */
214 sysMetrics
[SM_CLEANBOOT
] = 0;
216 sysMetrics
[SM_CXDRAG
] = 4;
217 sysMetrics
[SM_CYDRAG
] = 4;
218 sysMetrics
[SM_CXMENUCHECK
] = 13;
219 sysMetrics
[SM_CYMENUCHECK
] = 13;
221 /* FIXME: Should check the type of processor for the following */
222 sysMetrics
[SM_SLOWMACHINE
] = 0;
224 /* FIXME: Should perform a check */
225 sysMetrics
[SM_MIDEASTENABLED
] = 0;
227 sysMetrics
[SM_MOUSEWHEELPRESENT
] = 1;
229 sysMetrics
[SM_XVIRTUALSCREEN
] = 0;
230 sysMetrics
[SM_YVIRTUALSCREEN
] = 0;
231 sysMetrics
[SM_CMONITORS
] = 1;
232 sysMetrics
[SM_SAMEDISPLAYFORMAT
] = 1;
233 sysMetrics
[SM_CMETRICS
] = SM_CMETRICS
;
235 SystemParametersInfoA( SPI_GETSHOWSOUNDS
, 0, &sysMetrics
[SM_SHOWSOUNDS
], 0 );
237 if (hkey
) RegCloseKey (hkey
);
241 /***********************************************************************
244 * Sets system metrics.
246 INT
SYSMETRICS_Set( INT index
, INT value
)
248 if ((index
< 0) || (index
> SM_CMETRICS
)) return 0;
251 INT prev
= sysMetrics
[index
];
252 sysMetrics
[index
] = value
;
258 /***********************************************************************
259 * GetSystemMetrics (USER32.@)
261 INT WINAPI
GetSystemMetrics( INT index
)
263 /* some metrics are dynamic */
267 case SM_CXFULLSCREEN
:
268 case SM_CXVIRTUALSCREEN
:
269 return GetDeviceCaps( display_dc
, HORZRES
);
271 case SM_CYVIRTUALSCREEN
:
272 return GetDeviceCaps( display_dc
, VERTRES
);
273 case SM_CYFULLSCREEN
:
274 return GetDeviceCaps( display_dc
, VERTRES
) - sysMetrics
[SM_CYCAPTION
];
276 /* FIXME: How do I calculate these? */
278 return GetDeviceCaps( display_dc
, HORZRES
) + 4 + 2 * sysMetrics
[SM_CXFRAME
];
280 return GetDeviceCaps( display_dc
, VERTRES
) + 4 + 2 * sysMetrics
[SM_CYFRAME
];
282 return GetDeviceCaps( display_dc
, HORZRES
) + 2 * sysMetrics
[SM_CXFRAME
];
284 return GetDeviceCaps( display_dc
, VERTRES
) + 2 * sysMetrics
[SM_CYFRAME
];
287 if ((index
< 0) || (index
> SM_CMETRICS
)) return 0;
288 return sysMetrics
[index
];