I tried making a string from the char pointer. It doesn't change the current wallpaper, but it doesn't remove the previous one either. The function returns false. But if I set the second parameter to NULL it returns true. Nothing happens on the desktop though.

Qt Code:
  1. #include "wallpapr.h"
  2. #include <QSettings>
  3. #include <QVariant>
  4. #include <QDirModel>
  5. #include <QFileDialog>
  6. #include <QPixmap>
  7. #include <iostream>
  8. #include <stdio.h>
  9. #include <string>
  10. #ifdef WIN32
  11. //#include <winuser.h>
  12. #include <Windows.h>
  13.  
  14. using namespace std;
  15.  
  16. Wallpapr::Wallpapr(QWidget *parent)
  17. : QDialog(parent)
  18. {
  19. ui.setupUi(this);
  20. char *path = "C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Sunset.bmp";
  21. // QString *path = new QString("C:\\Documents and Settings\\Marius\\Local Settings\\Application Data\\Microsoft\\Wallpaper1.bmp");
  22. //C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Sunset.bmp");
  23. QSettings *settings = new QSettings(WALLPAPER, //"HKEY_CURRENT_USER\\Control Panel\\Desktop",
  24. QSettings::NativeFormat);
  25. //ui.oldWallpaper->setText(settings->value("Wallpaper").toString());
  26. settings->setValue("Wallpaper", QString(path));//"C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Sunset.bmp");
  27. settings->setValue("ConvertedWallpaper", QString(path));//"C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Sunset.bmp");
  28. settings->setValue("OriginalWallpaper", QString(path));//"C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Sunset.bmp");
  29. //ui.tempWallpaper->setText(settings->value("Wallpaper").toString());
  30. string *pathStr // = new string();
  31. = new string(path);
  32. //string *wp = new string();
  33. //SystemParametersInfo(SPI_GETDESKWALLPAPER, 100, wp, 0);
  34. //qdebug()<<wp;
  35. bool ret = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0,
  36. pathStr,
  37. //NULL,
  38. //0);
  39. //SPIF_SENDCHANGE);
  40. //SPIF_SENDWININICHANGE);
  41. SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
  42. ui.newWallpaper->setText(ret ? "true" : "false");
  43.  
  44.  
  45. }
  46.  
  47. Wallpapr::~Wallpapr()
  48. {
  49.  
  50. }
  51. #endif
To copy to clipboard, switch view to plain text mode