Blu*_*ers 7 c++ winapi qt desktop-wallpaper wallpaper
我一直在尝试使用Qt和mingw32编写一个应用程序来下载图像并将它们设置为背景壁纸.我已经在线阅读了几篇关于如何在VB和C#中执行此操作的文章,并且在某种程度上如何在c ++中执行此操作.我目前正在调用SystemParametersInfo
看似所有正确的参数(没有编译器错误)并且它失败了.没有镲片的大崩溃,只是0
返回.GetLastError()
同样具有启发性0
.
下面是我正在使用的代码(稍微修改一下,因此您不必查看对象内部).
#include <windows.h>
#include <iostream>
#include <QString>
void setWall()
{
QString filepath = "C:\\Documents and Settings\\Owner\\My Documents\\Wallpapers\\wallpaper.png";
char path[150];
strcpy(path, currentFilePath.toStdString().c_str());
char *pathp;
pathp = path;
cout << path;
int result;
result = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, pathp, SPIF_UPDATEINIFILE);
if (result)
{
cout << "Wallpaper set";
}
else
{
cout << "Wallpaper not set";
cout << "SPI returned" << result;
}
}
Run Code Online (Sandbox Code Playgroud)
可能SystemParametersInfo
是期待LPWSTR
(指向wchar_t
).
试试这个:
LPWSTR test = L"C:\\Documents and Settings\\Owner\\My Documents\\Wallpapers\\wallpaper.png";
result = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, test, SPIF_UPDATEINIFILE);
Run Code Online (Sandbox Code Playgroud)
如果这样可行(尝试使用几个不同的文件来确保),您需要将您转换char *
为LPWSTR
.我不确定Qt是否提供这些服务,但一个可能有用的功能是MultiByteToWideChar
.
归档时间: |
|
查看次数: |
17091 次 |
最近记录: |