我一直在尝试使用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;
}
}