Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

c++ - Mouse speed not changing by using SPI_SETMOUSESPEED

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<<"

Previous Mouse Speed was : " << *MouseSpeed ;

    cout<<"

SystemParametersInfo 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<<"

Current Mouse Speed is : " << *MouseSpeed ;

        cout<<"

SystemParametersInfo return status for SPI_SETMOUSESPEED : " << x << "

" ;
    }

    if( !x )        
        cout<< "Error Status : " << GetLastError() << "

";

    return 0;
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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
);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...