9

What is the best way to go about creating a program that would change the desktop wallpaper periodically? I would also like to create a GUI around the program. I am a Computer Science student, and as such I know basic programming in Java, and C++ among others. This will be done on Windows 7 OS.

What would be the best language to use for a project like this?

Ideally I would like to use the system clock to trigger the change. Is this possible?

Am I in over my head?

Any answers will be very much appreciated. Thank you.

Cᴏʀʏ
  • 105,112
  • 20
  • 162
  • 194
Shane Quiroz
  • 93
  • 1
  • 1
  • 3
  • What's the result of your due diligence for this project? What have your current active investigations revealed to you? – Hovercraft Full Of Eels Aug 31 '12 at 00:52
  • 1
    You certainly wouldn't to be able to do that in java without a JNI call, but C++ maybe – Alex Fischer Aug 31 '12 at 00:53
  • I have seen a lot of solutions to similar projects using a wide range of languages. I have looked into SystemParametersInfo and it seems that has to be incorporated. I have seen nothing regarding the use of system clock or use of a GUI. – Shane Quiroz Aug 31 '12 at 01:01
  • Windows has the ability to schedule programs to run at specific times. Just make your program change the wallpaper using `SystemParametersInfo` and schedule it. – chris Aug 31 '12 at 01:03

2 Answers2

17

In Java :

import java.util.*;

public class changer
{
    public static native int SystemParametersInfo(int uiAction,int uiParam,String pvParam,int fWinIni);

    static
    {
        System.loadLibrary("user32");
    }

    public int Change(String path)
    {
       return SystemParametersInfo(20, 0, path, 0);
    }

    public static void main(String args[])
    {
        String wallpaper_file = "c:\\wallpaper.jpg";
        changer mychanger = new changer();
        mychanger.Change(wallpaper_file);
    }

}

In Win32 C++, You can use SetTimer to trigger a change.

#define STRICT 1 
#include <windows.h>
#include <iostream.h>

VOID CALLBACK TimerProc(HWND hWnd, UINT nMsg, UINT nIDEvent, DWORD dwTime) 
{

  LPWSTR wallpaper_file = L"C:\\Wallpapers\\wallpaper.png";
  int return_value = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, wallpaper_file, SPIF_UPDATEINIFILE);


  cout << "Programmatically change the desktop wallpaper periodically: " << dwTime << '\n';
  cout.flush();
}

int main(int argc, char *argv[], char *envp[]) 
{
    int Counter=0;
    MSG Msg;

    UINT TimerId = SetTimer(NULL, 0, 2000, &TimerProc); //2000 milliseconds

    cout << "TimerId: " << TimerId << '\n';
   if (!TimerId)
    return 16;

   while (GetMessage(&Msg, NULL, 0, 0)) 
   {
        ++Counter;
        if (Msg.message == WM_TIMER)
        cout << "Counter: " << Counter << "; timer message\n";
        else
        cout << "Counter: " << Counter << "; message: " << Msg.message << '\n';
        DispatchMessage(&Msg);
    }

   KillTimer(NULL, TimerId);
return 0;
}
Software_Designer
  • 8,490
  • 3
  • 24
  • 28
10

This is a reasonably straightforward project, and can be done easily with any language that can call Win32 API functions (C++, for example). The non-obvious function to change the wallpaper is SystemParametersInfo with the SPI_SETDESKWALLPAPER flag. You give it a file name of a new image, and the wallpaper changes.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
  • 1
    Ok, all the confidence that this is a fairly straightforward project is really helpful and gives me the confidence to start this project. It seems all my questions were answered, and I will now get started. Thank you everybody. – Shane Quiroz Aug 31 '12 at 01:10
  • You're welcome. If you have any more questions, feel free to ask (remember, Stack Overflow works best with specific questions). – Greg Hewgill Aug 31 '12 at 01:22