慕容扬鞭 2021-04-06 18:02 采纳率: 0%
浏览 47

用SystemParametersInfo()来设置鼠标移动速度似乎没有效果,不知道原因,求解!

#include <stdio.h>
#include <windows.h>
#include <string.h>
//#pragma comment(lib, "user32.lib")
#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" ) // 设置入口地址


int main()
{
    BOOL fResult;
    int i,MouseSpeed;       
    LPTSTR szBuffer = new TCHAR[40];

    // Get the current mouse speed. 

    fResult = SystemParametersInfo(
        SPI_GETMOUSESPEED,   // get mouse information 
        0,              // not used 
        &MouseSpeed,    // holds mouse information
        0);             // not used 

    if (fResult)
    {
        wsprintf(szBuffer, "%d", MouseSpeed);
        MessageBox(NULL, szBuffer, "当前的鼠标速度", 0);
        

        for(i=10;i<110;i+=10)
        {
            MouseSpeed = i;  

            SystemParametersInfo(
                SPI_SETMOUSE,      // set mouse information
                0,                 // not used 
                (VOID*)MouseSpeed,        // mouse information 
                SPIF_SENDCHANGE|SPIF_UPDATEINIFILE);  // update win.ini

            wsprintf(szBuffer, "%d", MouseSpeed);
            MessageBox(NULL, szBuffer, "当前的鼠标速度", 0);
            
        }
         
    }
    return 0;
}
  • 写回答

1条回答 默认 最新

  • 虫鸣@蝶舞 2024-02-05 03:42
    关注

    首先你的SystemPatametersInfo的第一参数错了,不是SPI_GETMOUSESPEED,而是SPI_SETMOUSESPEED,其次第三参数要强制把int类型转换为PVIOD指针类型,最后的参数是SPIF_SENDCHANGE作用是通知系统上的所有程序立即更新设置,所有的例子如下gpt代码:

    int speed = 15; // 你想设置的鼠标速度
    SystemParametersInfo(SPI_SETMOUSESPEED, 0, reinterpret_cast<PVOID>(speed), SPIF_SENDCHANGE);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型