I've googled around a bit to try to find out how to set the desktop background in windows. The following is code that looks like it should work, but for some reason it won't.
#include "wallpapr.h"
#include <QSettings>
#include <QVariant>
#ifdef WIN32
#include <windows.h>
Wallpapr
::Wallpapr(QWidget *parent
){
//ui.setupUi(this);
// String *path = "C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Sunset.bmp";
QString *path
= new QString("C:\\Documents and Settings\\Marius\\Local Settings\\Application Data\\Microsoft\\Wallpaper1.bmp");
//C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Sunset.bmp");
//ui.oldWallpaper->setText(settings->value("Wallpaper").toString());
settings
->setValue
("Wallpaper",
QVariant(*path
));
//"C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Sunset.bmp"); //settings->setValue("ConvertedWallpaper", QVariant(*path));//"C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Sunset.bmp");
//settings->setValue("OriginalWallpaper", QVariant(*path));//"C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Sunset.bmp");
//ui.tempWallpaper->setText(settings->value("Wallpaper").toString());
SystemParametersInfo(SPI_SETDESKWALLPAPER, 1, path, SPIF_SENDWININICHANGE);
//ui.newWallpaper->setText(settings->value("Wallpaper").toString());
}
Wallpapr::~Wallpapr()
{
}
#endif
#include "wallpapr.h"
#include <QSettings>
#include <QVariant>
#ifdef WIN32
#include <windows.h>
Wallpapr::Wallpapr(QWidget *parent)
: QDialog(parent)
{
//ui.setupUi(this);
// String *path = "C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Sunset.bmp";
QString *path = new QString("C:\\Documents and Settings\\Marius\\Local Settings\\Application Data\\Microsoft\\Wallpaper1.bmp");
//C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Sunset.bmp");
QSettings *settings = new QSettings("HKEY_CURRENT_USER\\Control Panel\\Desktop",
QSettings::NativeFormat);
//ui.oldWallpaper->setText(settings->value("Wallpaper").toString());
settings->setValue("Wallpaper", QVariant(*path));//"C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Sunset.bmp");
//settings->setValue("ConvertedWallpaper", QVariant(*path));//"C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Sunset.bmp");
//settings->setValue("OriginalWallpaper", QVariant(*path));//"C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Sunset.bmp");
//ui.tempWallpaper->setText(settings->value("Wallpaper").toString());
SystemParametersInfo(SPI_SETDESKWALLPAPER, 1, path, SPIF_SENDWININICHANGE);
//ui.newWallpaper->setText(settings->value("Wallpaper").toString());
}
Wallpapr::~Wallpapr()
{
}
#endif
To copy to clipboard, switch view to plain text mode
It changes the registry values, but only removes the current wallpaper. The desktop is a clear color after running the program.
Anyone know how I could make it work?
Bookmarks