c-使用SPI_SETMOUSESPEED更改鼠标速度

为什么执行以下程序后鼠标速度没有变化?

是由于SPI_SETMOUSESPEED还是由于无法通过SPIF_UPDATEINIFILE,SPIF_SENDCHANGE和SPIF_SENDCHANGE参数更改winini文件?

编译器:g,操作系统: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;
}

解决方法:

您为SPI_SETMOUSESPEED传递了错误的pvParam值.从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.

将其与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.

因此,对于SPI_GETMOUSESPEED,您必须传递一个int *值作为pvParam,但是对于SPI_SETMOUSESPEED,您必须传递一个int值.在两种情况下,您都传递一个int *.您对SPI_SETMOUSESPED的致电应为:

SystemParametersInfo( SPI_SETMOUSESPEED ,
                          0 ,
                          (LPVOID)i,
                          SPIF_UPDATEINIFILE ||
                          SPIF_SENDCHANGE ||
                          SPIF_SENDWININICHANGE ) ;
上一篇:在C中的ifstream上设置超时?


下一篇:javascript – 如何通过鼠标停止垂直滚动