ReactOS  0.4.15-dev-2522-g9e0a3cd
SystemParametersInfo.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS API tests
3  * LICENSE: GPL - See COPYING in the top level directory
4  * PURPOSE: Test for SystemParametersInfo function family
5  * PROGRAMMERS: Giannis Adamopoulos
6  */
7 
8 #include "precomp.h"
9 
11 
14 
15 /* FIXME: test for HWND_TOP, etc...*/
16 static int get_iwnd(HWND hWnd)
17 {
18  if(hWnd == hWnd1) return 1;
19  else if(hWnd == hWnd2) return 2;
20  else return 0;
21 }
22 
24 {
25  int iwnd = get_iwnd(hWnd);
26 
27  if(message > WM_USER || !iwnd || IsDWmMsg(message) || IseKeyMsg(message))
29 
30  switch(message)
31  {
32  case WM_GETICON :
33  case WM_SETICON:
34  break;
37  {
38  WINDOWPOS* pwp = (WINDOWPOS*)lParam;
39  ok(wParam==0,"expected wParam=0\n");
41  break;
42  }
43  case WM_DISPLAYCHANGE:
45  {
48  }
49  break;
50  default:
51  RECORD_MESSAGE(iwnd, message, SENT, 0,0);
52  }
54 }
55 
56 static void FlushMessages()
57 {
58  MSG msg;
59 
60  while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
61  {
62  int iwnd = get_iwnd(msg.hwnd);
63  if(!(msg.message > WM_USER || !iwnd || IsDWmMsg(msg.message) || IseKeyMsg(msg.message)))
64  RECORD_MESSAGE(iwnd, msg.message, POST,0,0);
66  }
67 }
68 
71  {2,WM_GETMINMAXINFO},
72  {2,WM_NCCALCSIZE},
75  {1,WM_GETMINMAXINFO},
76  {1,WM_NCCALCSIZE},
78  {0,0}};
79 
82  {2,WM_GETMINMAXINFO},
83  {2,WM_NCCALCSIZE},
86  {1,WM_GETMINMAXINFO},
87  {1,WM_NCCALCSIZE},
89  {2,WM_SETTINGCHANGE},
90  {1,WM_SETTINGCHANGE},
91  {0,0}};
92 
95  {2,WM_GETMINMAXINFO},
96  {2,WM_NCCALCSIZE},
98  {2,WM_MOVE},
100  {1,WM_GETMINMAXINFO},
101  {1,WM_NCCALCSIZE},
103  {1,WM_MOVE},
104  {0,0}};
105 
107 {
108  NONCLIENTMETRICS NonClientMetrics;
109 
110  /* WARNING: this test requires themes and dwm to be disabled */
111 
112  SetCursorPos(0,0);
113 
114  /* Retrieve th non client metrics */
115  NonClientMetrics.cbSize = sizeof(NONCLIENTMETRICS);
116  SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &NonClientMetrics, 0);
117  FlushMessages();
119 
120  /* Set the non client metric without making any change */
121  SystemParametersInfo(SPI_SETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &NonClientMetrics, 0);
122  FlushMessages();
124 
125  /* Set the same metrics again with the SPIF_SENDCHANGE param */
126  SystemParametersInfo(SPI_SETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &NonClientMetrics, SPIF_SENDCHANGE|SPIF_UPDATEINIFILE );
127  FlushMessages();
129 
130  /* Slightly change the caption height */
131  NonClientMetrics.iCaptionHeight += 1;
132  SystemParametersInfo(SPI_SETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &NonClientMetrics, 0);
133  FlushMessages();
135 
136  /* Restore the original caption height */
137  NonClientMetrics.iCaptionHeight -= 1;
138  SystemParametersInfo(SPI_SETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &NonClientMetrics, 0);
139  FlushMessages();
141 }
142 
143 static void Test_MouseSpeed()
144 {
145  ULONG ulMouseSpeed, temp;
146  BOOL ret;
147 
148  ret = SystemParametersInfo(SPI_GETMOUSESPEED, 0, &ulMouseSpeed, 0);
149  ok(ret, "SystemParametersInfo failed\n");
150  ok(ulMouseSpeed >= 1 && ulMouseSpeed <=20, "Wrong mouse speed (%d)\n", (int)ulMouseSpeed);
151 
152  temp = 1;
154  ok(ret, "SystemParametersInfo failed\n");
155  ret = SystemParametersInfo(SPI_GETMOUSESPEED, 0, &temp, 0);
156  ok(ret, "SystemParametersInfo failed\n");
157  ok(temp == 1, "SPI_GETMOUSESPEED did not get value set by SPI_SETMOUSESPEED (%d instead of 1)\n", (int)temp);
158 
159  temp = 20;
161  ok(ret, "SystemParametersInfo failed\n");
162  ret = SystemParametersInfo(SPI_GETMOUSESPEED, 0, &temp, 0);
163  ok(ret, "SystemParametersInfo failed\n");
164  ok(temp == 20, "SPI_GETMOUSESPEED did not get value set by SPI_SETMOUSESPEED (%d instead of 20)\n", (int)temp);
165 
166  temp = 21;
168  ok(!ret, "expected SystemParametersInfo to fail\n");
169  ret = SystemParametersInfo(SPI_GETMOUSESPEED, 0, &temp, 0);
170  ok(ret, "SystemParametersInfo failed\n");
171  ok(temp == 20, "SPI_GETMOUSESPEED got unexpected value (%d instead of 20)\n", (int)temp);
172 
173  temp = 0;
175  ok(!ret, "expected SystemParametersInfo to fail\n");
176  ret = SystemParametersInfo(SPI_GETMOUSESPEED, 0, &temp, 0);
177  ok(ret, "SystemParametersInfo failed\n");
178  ok(temp == 20, "SPI_GETMOUSESPEED got unexpected value (%d instead of 20)\n", (int)temp);
179 
180  ret = SystemParametersInfo(SPI_SETMOUSESPEED, 0, UlongToPtr(ulMouseSpeed), SPIF_SENDCHANGE | SPIF_UPDATEINIFILE);
181  ok(ret, "SystemParametersInfo failed\n");
182 }
183 
184 static void Test_GradientCaptions(void)
185 {
186  BOOL ret;
187  LONG lResult;
188  DWORD dwResult;
189  BOOL bGradientCaptions, bModeFound;
190  DEVMODEW OldDevMode, NewDevMode;
191  INT iMode;
192 
193  ret = SystemParametersInfo(SPI_GETGRADIENTCAPTIONS, 0, &bGradientCaptions, 0);
194  ok(ret, "SystemParametersInfo failed\n");
195  if (bGradientCaptions == FALSE)
196  {
197  skip("GRADIENTCAPTIONS value has changed from its original state\n");
198  return;
199  }
200 
201  /* Try to find a graphics mode with 16 or 256 colors */
202  iMode = 0;
203  bModeFound = FALSE;
204  while (EnumDisplaySettingsW(NULL, iMode, &NewDevMode))
205  {
206  if ((NewDevMode.dmBitsPerPel == 4) ||
207  (NewDevMode.dmBitsPerPel == 8))
208  {
209  bModeFound = TRUE;
210  break;
211  }
212 
213  ++iMode;
214  }
215  if (!bModeFound)
216  {
217  skip("4bpp/8bpp graphics mode is not supported\n");
218  return;
219  }
220 
221  /* Save the current graphics mode */
223  ok(ret, "EnumDisplaySettingsW failed\n");
224 
226 
227  /* Switch to the new graphics mode */
229  lResult = ChangeDisplaySettingsExW(NULL, &NewDevMode, NULL, 0, NULL);
230  if (lResult == DISP_CHANGE_SUCCESSFUL)
231  {
232  dwResult = WaitForSingleObject(g_hSemDisplayChange, 10000);
233  ok(dwResult == WAIT_OBJECT_0, "Waiting for the WM_DISPLAYCHANGE message timed out\n");
234  }
236  ok(lResult == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsExW returned %ld\n", lResult);
237 
238  /* SPI_GETGRADIENTCAPTIONS will now always return FALSE */
239  ret = SystemParametersInfo(SPI_GETGRADIENTCAPTIONS, 0, &bGradientCaptions, 0);
240  ok(ret, "SystemParametersInfo failed\n");
241  ok(bGradientCaptions == FALSE, "SPI_GETGRADIENTCAPTIONS got unexpected value (%d instead of 0)\n", bGradientCaptions);
242 
243  /* Enable gradient captions */
244  bGradientCaptions = TRUE;
245  SystemParametersInfo(SPI_SETGRADIENTCAPTIONS, 0, UlongToPtr(bGradientCaptions), 0);
246 
247  /* Still FALSE */
248  ret = SystemParametersInfo(SPI_GETGRADIENTCAPTIONS, 0, &bGradientCaptions, 0);
249  ok(ret, "SystemParametersInfo failed\n");
250  ok(bGradientCaptions == FALSE, "SPI_GETGRADIENTCAPTIONS got unexpected value (%d instead of 0)\n", bGradientCaptions);
251 
252  /* Restore the previous graphics mode */
254  lResult = ChangeDisplaySettingsExW(NULL, &OldDevMode, NULL, 0, NULL);
255  if (lResult == DISP_CHANGE_SUCCESSFUL)
256  {
257  dwResult = WaitForSingleObject(g_hSemDisplayChange, 10000);
258  ok(dwResult == WAIT_OBJECT_0, "Waiting for the WM_DISPLAYCHANGE message timed out\n");
259  }
261  ok(lResult == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsExW returned %ld\n", lResult);
262 
263  /* The original value should be restored */
264  ret = SystemParametersInfo(SPI_GETGRADIENTCAPTIONS, 0, &bGradientCaptions, 0);
265  ok(ret, "SystemParametersInfo failed\n");
266  ok(bGradientCaptions == TRUE, "SPI_GETGRADIENTCAPTIONS got unexpected value (%d instead of 1)\n", bGradientCaptions);
267 
269 }
270 
272 {
273  RegisterSimpleClass(SysParamsTestProc, L"sysparamstest");
274  hWnd1 = CreateWindowW(L"sysparamstest", L"sysparamstest", WS_OVERLAPPEDWINDOW,
275  20, 20, 300, 300, NULL, NULL, 0, NULL);
276 
277  hWnd2 = CreateWindowW(L"sysparamstest", L"sysparamstest", WS_OVERLAPPEDWINDOW,
278  200, 200, 300, 300, NULL, NULL, 0, NULL);
279 
281  Test_MouseSpeed();
283 
286  UnregisterClassW(L"sysparamstest", 0);
287 }
LRESULT WINAPI DispatchMessageA(_In_ const MSG *)
Definition: tftpd.h:59
#define PeekMessage
Definition: winuser.h:5805
#define CloseHandle
Definition: compat.h:598
MSG_ENTRY CaptionHeight_chain[]
_In_ ULONG iMode
Definition: winddi.h:3520
BOOL WINAPI UnregisterClassW(_In_ LPCWSTR, HINSTANCE)
HANDLE WINAPI DECLSPEC_HOTPATCH CreateSemaphoreW(IN LPSECURITY_ATTRIBUTES lpSemaphoreAttributes OPTIONAL, IN LONG lInitialCount, IN LONG lMaximumCount, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:444
Definition: msgtrace.h:14
#define TRUE
Definition: types.h:120
HWND hWnd1
#define WM_NCCALCSIZE
Definition: winuser.h:1667
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
#define CALLBACK
Definition: compat.h:35
MSG_ENTRY NcMetricsChange1_chain[]
HWND hWnd
Definition: settings.c:17
#define SystemParametersInfo
Definition: winuser.h:5833
HWND hwndInsertAfter
Definition: winuser.h:3564
#define WM_MOVE
Definition: winuser.h:1592
UINT_PTR WPARAM
Definition: windef.h:207
#define SWP_NOZORDER
Definition: winuser.h:1232
DWORD dmBitsPerPel
Definition: wingdi.h:1646
BOOL WINAPI DestroyWindow(_In_ HWND)
#define CreateWindowW(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4291
int32_t INT
Definition: typedefs.h:58
WPARAM wParam
Definition: combotst.c:138
#define ENUM_CURRENT_SETTINGS
Definition: winuser.h:179
#define WM_SETTINGCHANGE
Definition: winuser.h:1611
HWND hWnd2
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define SWP_NOCOPYBITS
Definition: winuser.h:1228
LONG WINAPI ChangeDisplaySettingsExW(LPCWSTR lpszDeviceName, LPDEVMODEW lpDevMode, HWND hwnd, DWORD dwflags, LPVOID lParam)
Definition: display.c:585
static BOOL IseKeyMsg(UINT msg)
Definition: msgtrace.h:52
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
LONG_PTR LPARAM
Definition: windef.h:208
static void FlushMessages()
BOOL WINAPI EnumDisplaySettingsW(LPCWSTR lpszDeviceName, DWORD iModeNum, LPDEVMODEW lpDevMode)
Definition: display.c:408
UINT flags
Definition: winuser.h:3569
#define UlongToPtr(u)
Definition: config.h:106
#define DefWindowProc
Definition: ros2win.h:31
static __inline ATOM RegisterSimpleClass(WNDPROC lpfnWndProc, LPCWSTR lpszClassName)
#define WAIT_OBJECT_0
Definition: winbase.h:403
static void Test_MouseSpeed()
#define COMPARE_CACHE(msg_chain)
Definition: msgtrace.h:57
#define SWP_NOACTIVATE
Definition: winuser.h:1227
#define WM_WINDOWPOSCHANGING
Definition: winuser.h:1643
#define DISP_CHANGE_SUCCESSFUL
Definition: winuser.h:190
BOOL WINAPI SetCursorPos(_In_ int, _In_ int)
Definition: cursoricon.c:2627
unsigned long DWORD
Definition: ntddk_ex.h:95
static BOOL g_bReadyForDisplayChange
static void Test_GradientCaptions(void)
int ret
Definition: msgtrace.h:7
static const WCHAR L[]
Definition: oid.c:1250
#define SWP_FRAMECHANGED
Definition: winuser.h:1225
#define WM_USER
Definition: winuser.h:1877
START_TEST(SystemParametersInfo)
static void Test_NonClientMetrics()
#define SWP_NOSIZE
Definition: winuser.h:1230
static BOOL IsDWmMsg(UINT msg)
Definition: msgtrace.h:39
#define SPIF_UPDATEINIFILE
Definition: winuser.h:1553
static HANDLE g_hSemDisplayChange
static calc_node_t temp
Definition: rpn_ieee.c:38
MSG_ENTRY NcMetricsChange_chain[]
#define ok(value,...)
Definition: atltest.h:57
LRESULT CALLBACK SysParamsTestProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
#define SPIF_SENDCHANGE
Definition: winuser.h:1554
#define SWP_NOREDRAW
Definition: winuser.h:1231
static int get_iwnd(HWND hWnd)
Definition: msgtrace.h:6
BOOL WINAPI DECLSPEC_HOTPATCH ReleaseSemaphore(IN HANDLE hSemaphore, IN LONG lReleaseCount, IN LPLONG lpPreviousCount)
Definition: synch.c:542
#define skip(...)
Definition: atltest.h:64
#define WM_WINDOWPOSCHANGED
Definition: winuser.h:1644
#define msg(x)
Definition: auth_time.c:54
#define RECORD_MESSAGE(...)
Definition: msgtrace.h:60
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
unsigned int ULONG
Definition: retypes.h:1
#define SWP_NOCLIENTMOVE
Definition: msg.h:30
#define SWP_NOMOVE
Definition: winuser.h:1229
#define PM_REMOVE
Definition: winuser.h:1182
LONG_PTR LRESULT
Definition: windef.h:209
#define SWP_NOCLIENTSIZE
Definition: msg.h:29
MSG_ENTRY empty_chain[]
Definition: msgtrace.c:20
LPARAM lParam
Definition: combotst.c:139
#define WM_GETMINMAXINFO
Definition: winuser.h:1622