#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;
}
用SystemParametersInfo()来设置鼠标移动速度似乎没有效果,不知道原因,求解!
- 写回答
- 好问题 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);
解决 无用评论 打赏 举报