问题
Why mouse speed is not changing after execution of the following program ?
Is it due to SPI_SETMOUSESPEED or due to unable to change the winini file by SPIF_UPDATEINIFILE , SPIF_SENDCHANGE and SPIF_SENDCHANGE parameters ?
Compiler : g++ , OS : Windows 8 .
#include <iostream>
#include <windows.h>
#include<winuser.h>
#pragma comment(lib, "user32.lib")
using namespace std ;
int main()
{
int i = 0 , *MouseSpeed = &i ;
bool x ;
// Retrieving the mouse speed .
x = SystemParametersInfo( SPI_GETMOUSESPEED , 0 , MouseSpeed , 0 ) ;
cout<<"\n\nPrevious Mouse Speed was : " << *MouseSpeed ;
cout<<"\n\nSystemParametersInfo return status for SPI_GETMOUSESPEED : " << x ;
if( x )
{
i = 20 ;
MouseSpeed = &i ;
// Changing the mouse speed .
SystemParametersInfo( SPI_SETMOUSESPEED ,
0 ,
MouseSpeed ,
SPIF_UPDATEINIFILE ||
SPIF_SENDCHANGE ||
SPIF_SENDWININICHANGE ) ;
cout<<"\n\nCurrent Mouse Speed is : " << *MouseSpeed ;
cout<<"\n\nSystemParametersInfo return status for SPI_SETMOUSESPEED : " << x << "\n\n" ;
}
if( !x )
cout<< "Error Status : " << GetLastError() << "\n\n";
return 0;
}
回答1:
You are passing the wrong value as pvParam
for SPI_SETMOUSESPEED
. From the documentation:
Sets the current mouse speed. The pvParam parameter is an integer between 1 (slowest) and 20 (fastest). A value of 10 is the default. This value is typically set using the mouse control panel application.
Compare that to the documentation for SPI_GETMOUSESPEED
Retrieves the current mouse speed. The mouse speed determines how far the pointer will move based on the distance the mouse moves. The pvParam parameter must point to an integer that receives a value which ranges between 1 (slowest) and 20 (fastest). A value of 10 is the default. The value can be set by an end-user using the mouse control panel application or by an application using SPI_SETMOUSESPEED.
So for SPI_GETMOUSESPEED
you must pass an int*
value as pvParam
, but for SPI_SETMOUSESPEED
you must pass in int
value. You are passing an int*
in both cases. Your call for SPI_SETMOUSESPED
should be:
SystemParametersInfo(
SPI_SETMOUSESPEED,
0,
(LPVOID) newMouseSpeed,
SPIF_UPDATEINIFILE | SPIF_SENDCHANGE | SPIF_SENDWININICHANGE
);
来源:https://stackoverflow.com/questions/16813653/mouse-speed-not-changing-by-using-spi-setmousespeed