有没有办法在不重新启动或注销的情况下加载游标?

Is there a way I can load a cursor without restarting or logging out?

本文关键字:情况下 加载 游标 注销 重新启动 有没有      更新时间:2023-10-16

我想加载游标而不重新启动从计算机注销。

我尝试使用LoadCursorFromFile功能,但它不起作用。

还有其他方法可以加载游标吗?

编辑:我也尝试使用SetCursor功能,但它仍然不起作用。

这是我当前的代码:

#include <iostream>
#include <Windows.h>
#include <lmcons.h>
#pragma comment(lib, "urlmon.lib")  
using namespace std;
string username()
{
char username[UNLEN + 1];
DWORD username_len = UNLEN + 1;
GetUserName(username, &username_len);
return username;
}
int main()
{
string dir = "C:\Users\" + username() + "\Documents\Dragonite";
string dwnld_URL = "https://srv-file7.gofile.io/download/2rNCim/nat927.ani";
string savepath = "C:\Users\" + username() + "\Documents\Dragonite\nyan.ani";
CreateDirectory(dir.c_str(), NULL);
URLDownloadToFile(NULL, dwnld_URL.c_str(), savepath.c_str(), 0, NULL);
Sleep(5000);
HCURSOR hCur = LoadCursorFromFile(savepath.c_str());
SetCursor(hCur);
return 0;
}

谢谢!

我已经完成了我的项目,它现在正在工作,特别感谢@enhzflep

我已将SetCursor函数更改为SetSystemCursor

*注意 - 要使应用程序使用任何OCR_常量,您必须在包含Windows.h库之前#define OEMRESOURCE

#include <iostream>
#define OEMRESOURCE 100
#include <Windows.h>
#include <lmcons.h>
#pragma comment(lib, "urlmon.lib")  
using namespace std;
string username()
{
char username[UNLEN + 1];
DWORD username_len = UNLEN + 1;
GetUserName(username, &username_len);
return username;
}
int main()
{
string dir = "C:\Users\" + username() + "\Documents\Dragonite";
string dwnld_URL = "https://srv-file7.gofile.io/download/2rNCim/nat927.ani";
string savepath = "C:\Users\" + username() + "\Documents\Dragonite\nyan.ani";
CreateDirectory(dir.c_str(), NULL);
URLDownloadToFile(NULL, dwnld_URL.c_str(), savepath.c_str(), 0, NULL);
HCURSOR hCUR = LoadCursorFromFile(savepath.c_str());
SetSystemCursor(hCUR, OCR_NORMAL);
if (!SetSystemCursor) {
cout << GetLastError();
}
return 0;
}