Click here to Skip to main content
15,903,752 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is the program to change the wallpaper..

But the wallpaper is not set



C++
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#include <string.h>
#include <iostream.h>
int main(int argc, char* argv[])
{

     LPWSTR  test = L"C:\\WINDOWS\\Web\\wallpaper\\Bliss.bmp";

     //C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures
char a[1024];

     sprintf(a,"%s","C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Blue hills.jpg");


    int result;

    result = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, a, SPIF_SENDCHANGE);

//    result = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, test, SPIF_UPDATEINIFILE);

    if (result)
    {
        cout << "Wallpaper set";
    }
    else
    {
        cout << "Wallpaper not set"<<endl;
        cout << "SPI returned" << result<<endl;;
    }

    return 0;
}
Posted
Updated 1-Nov-11 22:39pm
v2

1 solution

"Note When the SPI_SETDESKWALLPAPER flag is used, SystemParametersInfo always returns TRUE." from MSDN[^].
There is a note about the SPI_GETDESKWALLPAPER function at the bottom of that page by Razeen2008. It basically says that the data type is WCHAR, not char.

(I have not tried this code)
C++
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#include <string.h>
#include <iostream.h>
int main(int argc, char* argv[]) {
    WCHAR a[1024] = L"C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Blue hills.jpg"; //This has changed to WCHAR
    SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, a, SPIF_SENDCHANGE);
    //No point checking return value, it is always TRUE.
    return 0;
}
 
Share this answer
 
v2
Comments
@BangIndia 2-Nov-11 5:32am    
No sir..
it not changing for the windows xp os

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900