Results 1 to 20 of 20

Thread: Setting wallpaper on windows

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2007
    Posts
    39
    Thanks
    8

    Default Re: Setting wallpaper on windows

    Nope, not C:\Bliss.bmp or Bliss.bmp in the same folder. It could be that the functon expects something else than a char pointer.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Setting wallpaper on windows

    It might require a wchar pointer. I suggest using this function first to query for the existing wallpaper. This way you'll be able to see how the path is stored in the buffer you provide.

  3. #3
    Join Date
    Aug 2007
    Posts
    39
    Thanks
    8

    Default Re: Setting wallpaper on windows

    Qt Code:
    1. #include <iostream>
    2. #include <stdio.h>
    3. #include <string>
    4. #include <Windows.h>
    5. using namespace std;
    6.  
    7. int main () {
    8. char *path = "C:\\Bliss.bmp";
    9. bool ret = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0,
    10. path,
    11. //NULL,
    12. //0);
    13. //SPIF_SENDCHANGE);
    14. //SPIF_SENDWININICHANGE);
    15. SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
    16. cout<<"the function returned "<<(ret ? "true" : "false");
    17. char* str = NULL; // function allocates the mem with LocalAlloc(), used with LocalFree()
    18. int msg_ret = FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | // let the function alloc string mem
    19. FORMAT_MESSAGE_FROM_SYSTEM | // use system message and not a passed one
    20. FORMAT_MESSAGE_IGNORE_INSERTS, // ignore and "inserts"
    21. NULL,
    22. GetLastError(), // get the error
    23. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // default language
    24. (CHAR*)&str,
    25. 0,
    26. NULL);
    27. cout<<"\n"<<str;
    28. cout<<"\n"<<path;
    29. return 0;
    30. }
    To copy to clipboard, switch view to plain text mode 
    That code actually works! Great!

    But it does not work in QT.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Setting wallpaper on windows

    What do you mean "in Qt"? There is no "in Qt" The only problem that might arise is that some macro is included that influences the behaviour of something else, but this is not really a problem with Qt. Reordering includes might help in such situation.

  5. The following user says thank you to wysota for this useful post:

    ihoss (11th June 2008)

  6. #5
    Join Date
    Aug 2007
    Posts
    39
    Thanks
    8

    Default Re: Setting wallpaper on windows

    Well, it works in its own little cpp file, but when I try to include it in the QT project, it won't work. I have tried to rearrange the includes, but it has no effects. I've also set the namespace to std, but it does not seem to be required to make the little cpp compile.

    edit: There is one strange thing though. In the little cpp i have to use CHAR as the 5th argument in the FormatMessage function, but in the "qt" program i have to use WCHAR. That is kinda strange when I include the same files and compile it with the same compiler.
    Last edited by ihoss; 11th June 2008 at 00:57.

  7. #6
    Join Date
    Aug 2007
    Posts
    39
    Thanks
    8

    Default Re: Setting wallpaper on windows

    I tried to include the little cpp in the main project and just call the function from the application. It didn't work. I've also made sure both are compiled with mingw, and it only works when it is on its own.

  8. #7
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Setting wallpaper on windows

    Use SystemParametersInfoA or convert your QString properly to a WCHAR array with QString::utf16().

  9. The following 2 users say thank you to ChristianEhrlicher for this useful post:

    IGHOR (18th September 2009), ihoss (11th June 2008)

  10. #8
    Join Date
    Aug 2007
    Posts
    39
    Thanks
    8

    Default Re: Setting wallpaper on windows

    Wow, adding that A fixed the problem! Thanks a lot Christian. Thanks also to wysota for keeping dialog going

  11. #9
    Join Date
    Mar 2008
    Location
    Ukraine@online
    Posts
    8
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Setting wallpaper on windows

    Quote Originally Posted by ChristianEhrlicher View Post
    Use SystemParametersInfoA or convert your QString properly to a WCHAR array with QString::utf16().
    Thank's for this!
    IT work's:
    QString screenPath="C:\\screen.bmp";
    SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (PVOID)screenPath.utf16(), SPIF_SENDWININICHANGE | SPIF_UPDATEINIFILE)

Similar Threads

  1. Windows not appearing in XP.
    By beardybloke in forum Qt Programming
    Replies: 7
    Last Post: 24th October 2007, 17:32
  2. Setting default icon for all windows / dialogs
    By steg90 in forum Qt Programming
    Replies: 1
    Last Post: 5th July 2007, 10:04
  3. Windows change hardware acceleration setting
    By jakamph in forum Qt Programming
    Replies: 1
    Last Post: 15th November 2006, 07:10
  4. converting unix exe to windows binary
    By deekayt in forum General Programming
    Replies: 2
    Last Post: 17th September 2006, 01:00
  5. Qt and windows vista
    By munna in forum General Discussion
    Replies: 8
    Last Post: 11th January 2006, 22:33

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.