c++ - Is there a way I can load a cursor without restarting or logging out?
问题描述
I want to load a cursor without restart of log off from the computer.
I have tried to use LoadCursorFromFile
function but it not working.
Is there other ways to load a cursor ?
EDIT: I have also tried to use SetCursor
function but it still not working.
Here is my current code:
#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;
}
Thanks!
解决方案
我已经完成了我的项目,它现在正在运行,特别感谢@enhzflep
我已将SetCursor
功能更改为SetSystemCursor
.
*注意 - 对于使用任何 OCR_ 常量的应用程序,您必须#define OEMRESOURCE
在包含Windows.h
库之前!
#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;
}
推荐阅读
- python - Tensorboard TypeError:__init__() 得到了一个意外的关键字参数“文件”
- r - 计数非空变量并通过分组放入新列
- c - #include 与 GLSL/C 的自定义 IO?
- c# - 如何更新 ASP.NET 样板 Web 应用程序框架
- javascript - 脚本仅适用于控制台
- xamarin.forms - Xamarin.Forms Mac AuthenticationContinuationHelper
- hyperledger-composer - 在 composer-rest-server 的 Passport 中插入基本身份验证而不是 OAuth?
- r - 在 R 中转换日期以进行聚类
- c# - 模型状态错误 c# mvc5
- android - 无法在写入事务领域 Android 之外修改托管对象