Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Change Desktop Wallpaper
QtWS25 Last Chance

Change Desktop Wallpaper

Scheduled Pinned Locked Moved General and Desktop
40 Posts 5 Posters 20.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • QT-static-prgmQ Offline
    QT-static-prgmQ Offline
    QT-static-prgm
    wrote on last edited by
    #2

    Ok i got a prgm working for setting wallpaper

    @#include <iostream>
    #include <windows.h>
    #include <QString>

    using namespace std;

    int main()
    {
    QString filepath = "C:\Path\to\Image\Image.jpg";
    char path[150];
    strcpy(path, filepath.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;
    }

    return 0;
    }@

    I also read that there's a problem with jpg and that only bmp works, but also if i take a bmp it doesn't work. maybe someone has an idea.

    a yes the problem is that the screen just becomes black

    1 Reply Last reply
    0
    • A Offline
      A Offline
      amahta
      wrote on last edited by
      #3

      You need to use Windows API interfaces (IDesktopWallpaper to be precise) to do this in newer versions of Windows such as 8 and 10.
      Checkout this post for more info.

      Thou shalt programme
      http://www.amin-ahmadi.com

      1 Reply Last reply
      0
      • QT-static-prgmQ Offline
        QT-static-prgmQ Offline
        QT-static-prgm
        wrote on last edited by
        #4

        I tried the code, but i get some errors. I hope you understand them. I fixed some of them by using NULL instead of nullptr.

        #include "shobjidl.h"
        #include <QDebug>
        
        int main(int argc, char *argv[])
        {
        
        	HRESULT hr = CoInitialize(NULL);
        	IDesktopWallpaper *pDesktopWallpaper = NULL;
        	hr = CoCreateInstance(__uuidof(DesktopWallpaper), NULL, CLSCTX_ALL, IID_PPV_ARGS(&pDesktopWallpaper));
        	if (FAILED(hr))
        	{
        		qDebug() << "error";
        	}
        	else
        	{
        		pDesktopWallpaper->SetWallpaper(NULL, QString("C:\\Users\\Amin\\Desktop\\test.jpg").toStdWString().c_str());
        	}
        
        	return 0;
        }
        
        QT += core
        QT -= gui
        
        TARGET = WallpaperChanger
        #CONFIG += console
        CONFIG -= app_bundle
        LIBS += -lOle32
        
        TEMPLATE = app
        
        SOURCES += main.cpp
        
        
        
        • D:\workspaces\Qt_default\WallpaperChanger\main.cpp:17: Fehler: invalid use of incomplete type 'IDesktopWallpaper {aka struct IDesktopWallpaper}'
          pDesktopWallpaper->SetWallpaper(NULL, QString("C:\Users\Amin\Desktop\test.jpg").toStdWString().c_str());
          ^

        • C:\Qt\Qt5.5.1\Tools\mingw492_32\i686-w64-mingw32\include\shobjidl.h:987: Fehler: forward declaration of 'IDesktopWallpaper {aka struct IDesktopWallpaper}'
          typedef interface IDesktopWallpaper IDesktopWallpaper;
          ^

        • C:\Qt\Qt5.5.1\Tools\mingw492_32\i686-w64-mingw32\include\combaseapi.h:79: Fehler: invalid static_cast from type 'IDesktopWallpaper*' to type 'IUnknown*'
          static_cast<IUnknown *> (*pp);
          ^

        1 Reply Last reply
        0
        • A Offline
          A Offline
          amahta
          wrote on last edited by
          #5

          First of all, please try the same thing with a Widgets application. And create it by selecting new project, the Widgets Application. Do NOT use console project to try it! (Your project does not seem to be even Console anyway!)
          Next, you seem to be using MingW compiler, not sure but you may be facing the problem because of that. The interface mentioned here belongs to recent SDKs of Windows and therefore it might not work correctly (link correctly) with a MingW compiler.
          I would suggest using a recent MSVC compiler.

          Thou shalt programme
          http://www.amin-ahmadi.com

          1 Reply Last reply
          0
          • QT-static-prgmQ Offline
            QT-static-prgmQ Offline
            QT-static-prgm
            wrote on last edited by
            #6

            OK, i changed it to widgets application. And yes i'm using MinGW.
            I tried to config MSVC for my Qt Creator, but i wasn't successfull:

            • :-1: Warnung: LNK4044: Nicht erkannte Option /lshell32; wird ignoriert.

            • :-1: Warnung: LNK4044: Nicht erkannte Option /LC:\Qt\Qt5.5.1\5.5\mingw492_32\lib; wird ignoriert.

            • :-1: Warnung: LNK4044: Nicht erkannte Option /lQt5Cored; wird ignoriert.

            • :-1: Fehler: LNK1104: Datei "C:\Qt\Qt5.5.1\5.5\mingw492_32\lib\qtmaind.lib" kann nicht geöffnet werden.

            I'm sure i need the libs for msvc, but i couldn't find them. Are there the libs pre compiled? Or do i need to take the qt-everywhere-opensource-src-5.5.1.zip and build the source with my compiler on my own??
            (I have Visual Studio Enterprise 2015 installed)

            1 Reply Last reply
            0
            • A Offline
              A Offline
              amahta
              wrote on last edited by
              #7

              Unfortunately pre-compiled Libs for Qt are not provided with the official release (not yet!) but you can try building from source yourself.
              I would suggest installing a lower version of MSVC compiler such as MSVC2013 (Community Edition is free btw) and using pre-compiled libraries if you are not comfortable with building sources yourself, or if you would prefer official builds.

              Thou shalt programme
              http://www.amin-ahmadi.com

              1 Reply Last reply
              0
              • QT-static-prgmQ Offline
                QT-static-prgmQ Offline
                QT-static-prgm
                wrote on last edited by
                #8

                Ok i'll try to build the source. I did it a while ago with MinGW for static linking. So i hope it will be similar to this.
                What's the difference between qt-everywhere-opensource-src-5.5.1 http://download.qt.io/archive/qt/5.5/5.5.1/single/ and qt5-opensource-src-5.5.1 http://download.qt.io/archive/qt/5.5/5.5.1/submodules/

                Why should i use a lower version of MSVC?? I recently updated from VS 2013 Ultimate to VS 2015. So i'd prefer the newer one. But if this is a problem I can install VS2013 again.

                A 1 Reply Last reply
                0
                • QT-static-prgmQ QT-static-prgm

                  Ok i'll try to build the source. I did it a while ago with MinGW for static linking. So i hope it will be similar to this.
                  What's the difference between qt-everywhere-opensource-src-5.5.1 http://download.qt.io/archive/qt/5.5/5.5.1/single/ and qt5-opensource-src-5.5.1 http://download.qt.io/archive/qt/5.5/5.5.1/submodules/

                  Why should i use a lower version of MSVC?? I recently updated from VS 2013 Ultimate to VS 2015. So i'd prefer the newer one. But if this is a problem I can install VS2013 again.

                  A Offline
                  A Offline
                  amahta
                  wrote on last edited by
                  #9

                  @QT-static-prgm
                  Single is like an All-In-One package of modules but submodules version offers all modules separately.
                  Most probably you need Single version.
                  I'll suggest taking a look at this page and also this post

                  You need to use the lower version if you want the official build. If not, you can build yourself.
                  Good luck

                  Thou shalt programme
                  http://www.amin-ahmadi.com

                  1 Reply Last reply
                  1
                  • QT-static-prgmQ Offline
                    QT-static-prgmQ Offline
                    QT-static-prgm
                    wrote on last edited by
                    #10

                    Thank you very much. Your tutorial is great. But i have some problems again:

                    + cd qtbase
                    + C:\Qt\5.5.1\qt-everywhere-opensource-src-5.5.1\qtbase\configure.bat -top-level -static -debug-and-release -prefix "C:\Qt\5.5.1\msvc2015_static" -platform win32-msvc2015 -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -opengl desktop -qt-sql-sqlite -qt-sql-odbc -no-openssl -opensource -confirm-license -make libs -nomake tools -nomake examples -nomake tests
                    
                    This is the Qt for Windows Open Source Edition.
                    
                    You have already accepted the terms of the license.
                    
                    Creating qmake...
                    execute: File or path is not found (nmake)
                    execute: File or path is not found (nmake)
                    Cleaning qmake failed, return code -1
                    

                    btw what are all these options good for??

                    did i take the wrong cmd?? I used "MSBuild Befehlszeile für VS2015". There some more in my Start->All Programms->Visual Studio list:
                    Developer-Eingabeaufforderung für VS2015,
                    VS2015 x64 ARM Cross Tools-Eingabeaufforderung,
                    VS2015 x64 Native Tools-Eingabeaufforderung,
                    VS2015 x64 x86 Cross Tools-Eingabeaufforderung,
                    VS2015 x86 ARM Cross Tools-Eingabeaufforderung,
                    VS2015 x86 Native Tools-Eingabeaufforderung,
                    VS2015 x86 x64 Cross Tools-Eingabeaufforderung

                    Which one is the right one??

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      amahta
                      wrote on last edited by
                      #11

                      You should have "Developer Command Prompt for VS2015"
                      You are using German version so "Developer-Eingabeaufforderung für VS2015" is correct!

                      Thou shalt programme
                      http://www.amin-ahmadi.com

                      1 Reply Last reply
                      0
                      • QT-static-prgmQ Offline
                        QT-static-prgmQ Offline
                        QT-static-prgm
                        wrote on last edited by
                        #12

                        It works :D Thank you very much.
                        ähm ok i just wanted to press send and checked my cmd output and it "finished". But it says:

                        jom: C:\Qt\5.5.1\qt-everywhere-opensource-src-5.5.1\qtdeclarative\src\qml\Makefile.Debug [.generated\debug\RegExpJitTables.h] Error 1
                        jom: C:\Qt\5.5.1\qt-everywhere-opensource-src-5.5.1\qtdeclarative\src\qml\Makefile [debug-all] Error 2
                        jom: C:\Qt\5.5.1\qt-everywhere-opensource-src-5.5.1\qtdeclarative\src\Makefile [sub-qml-make_first-ordered] Error 2
                        jom: C:\Qt\5.5.1\qt-everywhere-opensource-src-5.5.1\qtdeclarative\Makefile [sub-src-make_first] Error 2
                        jom: C:\Qt\5.5.1\qt-everywhere-opensource-src-5.5.1\Makefile [module-qtdeclarative-make_first] Error 2

                        A 1 Reply Last reply
                        0
                        • QT-static-prgmQ QT-static-prgm

                          It works :D Thank you very much.
                          ähm ok i just wanted to press send and checked my cmd output and it "finished". But it says:

                          jom: C:\Qt\5.5.1\qt-everywhere-opensource-src-5.5.1\qtdeclarative\src\qml\Makefile.Debug [.generated\debug\RegExpJitTables.h] Error 1
                          jom: C:\Qt\5.5.1\qt-everywhere-opensource-src-5.5.1\qtdeclarative\src\qml\Makefile [debug-all] Error 2
                          jom: C:\Qt\5.5.1\qt-everywhere-opensource-src-5.5.1\qtdeclarative\src\Makefile [sub-qml-make_first-ordered] Error 2
                          jom: C:\Qt\5.5.1\qt-everywhere-opensource-src-5.5.1\qtdeclarative\Makefile [sub-src-make_first] Error 2
                          jom: C:\Qt\5.5.1\qt-everywhere-opensource-src-5.5.1\Makefile [module-qtdeclarative-make_first] Error 2

                          A Offline
                          A Offline
                          amahta
                          wrote on last edited by
                          #13

                          @QT-static-prgm check your build folder. Most probably you already have most of the libraries built. Continue with "jom install" command.
                          But you can also check for dependencies and/or remove the module causing the problem, in this case it is qtdeclarative, and then rebuild.

                          Thou shalt programme
                          http://www.amin-ahmadi.com

                          1 Reply Last reply
                          0
                          • QT-static-prgmQ Offline
                            QT-static-prgmQ Offline
                            QT-static-prgm
                            wrote on last edited by
                            #14

                            -nomake qtdeclarative doesn't work :/

                            • cd qtbase
                            • C:\Qt\5.5.1\qt-everywhere-opensource-src-5.5.1\qtbase\configure.bat -top-level -static -debug-and-release -prefix "C:\Qt\5.5.1\msvc2015_static" -platform win32-msvc2015 -c++11 -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -opengl desktop -qt-sql-sqlite -qt-sql-odbc -no-openssl -opensource -confirm-license -make libs -nomake tools -nomake examples -nomake tests -nomake qtdeclarative
                              Unknown part qtdeclarative passed to -nomake.
                            A 1 Reply Last reply
                            0
                            • QT-static-prgmQ QT-static-prgm

                              -nomake qtdeclarative doesn't work :/

                              • cd qtbase
                              • C:\Qt\5.5.1\qt-everywhere-opensource-src-5.5.1\qtbase\configure.bat -top-level -static -debug-and-release -prefix "C:\Qt\5.5.1\msvc2015_static" -platform win32-msvc2015 -c++11 -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -opengl desktop -qt-sql-sqlite -qt-sql-odbc -no-openssl -opensource -confirm-license -make libs -nomake tools -nomake examples -nomake tests -nomake qtdeclarative
                                Unknown part qtdeclarative passed to -nomake.
                              A Offline
                              A Offline
                              amahta
                              wrote on last edited by
                              #15

                              @QT-static-prgm It won't. You have to carefully read configure options. I suggest taking a look at this old post of mine about configure options. If I am not mistaken, you need to use "skip" instead of "nomake"

                              Thou shalt programme
                              http://www.amin-ahmadi.com

                              1 Reply Last reply
                              0
                              • QT-static-prgmQ Offline
                                QT-static-prgmQ Offline
                                QT-static-prgm
                                wrote on last edited by
                                #16

                                And again, thank you so much. What is qtdeclarative good for??

                                A 1 Reply Last reply
                                0
                                • QT-static-prgmQ QT-static-prgm

                                  And again, thank you so much. What is qtdeclarative good for??

                                  A Offline
                                  A Offline
                                  amahta
                                  wrote on last edited by
                                  #17

                                  @QT-static-prgm it is related to QML. I usually can live without it :)

                                  Thou shalt programme
                                  http://www.amin-ahmadi.com

                                  1 Reply Last reply
                                  0
                                  • QT-static-prgmQ Offline
                                    QT-static-prgmQ Offline
                                    QT-static-prgm
                                    wrote on last edited by
                                    #18

                                    Next error:

                                    Error: dependent 'C:\Qt\5.5.1\qt-everywhere-opensource-src-5.5.1\qtdeclarative\lib\Qt5Qmld.lib' does not exist.
                                    jom: C:\Qt\5.5.1\qt-everywhere-opensource-src-5.5.1\qtwebchannel\src\webchannel\Makefile [debug-all] Error 2
                                    jom: C:\Qt\5.5.1\qt-everywhere-opensource-src-5.5.1\qtwebchannel\src\Makefile [sub-webchannel-make_first] Error 2
                                    jom: C:\Qt\5.5.1\qt-everywhere-opensource-src-5.5.1\qtwebchannel\Makefile [sub-src-make_first] Error 2
                                    jom: C:\Qt\5.5.1\qt-everywhere-opensource-src-5.5.1\Makefile [module-qtwebchannel-make_first] Error 2

                                    I think it's a kind of Windows 10 problem: https://forum.qt.io/topic/58056/compilation-failure-with-vs2015/3

                                    mrjjM 1 Reply Last reply
                                    0
                                    • QT-static-prgmQ QT-static-prgm

                                      Next error:

                                      Error: dependent 'C:\Qt\5.5.1\qt-everywhere-opensource-src-5.5.1\qtdeclarative\lib\Qt5Qmld.lib' does not exist.
                                      jom: C:\Qt\5.5.1\qt-everywhere-opensource-src-5.5.1\qtwebchannel\src\webchannel\Makefile [debug-all] Error 2
                                      jom: C:\Qt\5.5.1\qt-everywhere-opensource-src-5.5.1\qtwebchannel\src\Makefile [sub-webchannel-make_first] Error 2
                                      jom: C:\Qt\5.5.1\qt-everywhere-opensource-src-5.5.1\qtwebchannel\Makefile [sub-src-make_first] Error 2
                                      jom: C:\Qt\5.5.1\qt-everywhere-opensource-src-5.5.1\Makefile [module-qtwebchannel-make_first] Error 2

                                      I think it's a kind of Windows 10 problem: https://forum.qt.io/topic/58056/compilation-failure-with-vs2015/3

                                      mrjjM Offline
                                      mrjjM Offline
                                      mrjj
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #19

                                      @QT-static-prgm
                                      HI just a side note:
                                      I used this on Win 7 to change wallpaper.
                                      (with mingw compiler)
                                      Never tested on window 10, so might not work.

                                      #include "mainwindow.h"
                                      #include <QApplication>
                                      #include <qDebug>
                                      
                                      #include <Windows.h>
                                      int setwallpaper (QString filePath ) {
                                        bool ret = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (PVOID)filePath.utf16(), SPIF_SENDWININICHANGE | SPIF_UPDATEINIFILE);
                                        return ret;
                                      }
                                      
                                      int main(int argc, char* argv[]) {
                                        QApplication a(argc, argv);
                                        MainWindow w;
                                        w.show();
                                        setwallpaper("c:/test.jpg"); // adjust
                                        return a.exec();
                                      }
                                      
                                      
                                      1 Reply Last reply
                                      0
                                      • QT-static-prgmQ Offline
                                        QT-static-prgmQ Offline
                                        QT-static-prgm
                                        wrote on last edited by
                                        #20

                                        Your code looks easy. I'll try it. But for now my program shown above is working with the VS compiler.

                                        Thank you all :D

                                        Ok next i'll try to manipulate the image to show the date and clock in the lower right corner. (my university killed the windows clock. That's why i need this ;))

                                        mrjjM 1 Reply Last reply
                                        0
                                        • QT-static-prgmQ QT-static-prgm

                                          Your code looks easy. I'll try it. But for now my program shown above is working with the VS compiler.

                                          Thank you all :D

                                          Ok next i'll try to manipulate the image to show the date and clock in the lower right corner. (my university killed the windows clock. That's why i need this ;))

                                          mrjjM Offline
                                          mrjjM Offline
                                          mrjj
                                          Lifetime Qt Champion
                                          wrote on last edited by mrjj
                                          #21

                                          @QT-static-prgm
                                          hehe so you switch compiler and
                                          compiled all of Qt so you can change
                                          the wallpaper each minute and that way
                                          get a clock ???
                                          :))
                                          That is the spirit if I ever saw one :))

                                          but are you sure they allow to change the wallpaper?

                                          QT-static-prgmQ 1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved