Solved

Set Desktop Wallpaper via a MSVC++ Program

Posted on 2000-03-24
11
226 Views
Last Modified: 2010-04-02
I would like to be able to write a program or batch file that sets my desktop wall paper to a preset bitmap.  Anyone have a function call that allows this?  I'm hoping there's a MS API call to do so.  If I need to edit the registry, it's not worth the trouble.
0
Comment
Question by:cbeattie
  • 6
  • 5
11 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 200 total points
ID: 2654376
Forget the batch file.  You can easily do it from a windows program though.  You just use the SystemParametersInfo() fucntion with an index of SPI_SETDESKPATERN.

Example follows.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2654407
This program console program can be called from a batch file.  It will set the wallpaper to the bitmap whose file name and path are specified in the 1st parameter to the program.  

#include <windows.h>
#include <iostream>
using namespace std;

int main(int argc,char *argv[],char *envp[])
{
   if (argc < 2)
   {
        cout <<"Error: bitmap file name must be specifed in the parametes.";
        return -1;
   }
   SystemParametersInfo(SPI_SETDESKWALLPAPER,0,argv[1],SPIF_SENDCHANGE);
   return 0;
}
0
 
LVL 1

Author Comment

by:cbeattie
ID: 2654485
nietod,

I compiled your code and called from a dos prompt as the following:

SetWallpaper C:\Winnt\Cloud.bmp

but, alas, nothing happend.  any other ideas?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:cbeattie
ID: 2654503
nietod,

I compiled your code and called from a dos prompt as the following:

SetWallpaper C:\Winnt\Cloud.bmp

but, alas, nothing happend.  any other ideas?
0
 
LVL 1

Author Comment

by:cbeattie
ID: 2654561
BTW, if I use the SPIF_UPDATEINIFILE parameter, when I right click on the desktop and choose properties, the new wallpaper is selected, but it does not appear on the desktop unless I click on it and hit apply.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2654601
That probably means that the change won't take affect until you reboot.  You can try specifying SPIF_UPDATEINIFILE, in the last parameter, but that probably won't help.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2654618
Several examples I've seen all seem to be using SPIF_UPDATEINIFILE | SPIF_SENDCHANGE as the last parameter.  Althoguh the docs's don't indicate that this parameter is a bit flag type parameter.  Try that.
0
 
LVL 1

Author Comment

by:cbeattie
ID: 2654652
Bingo, just had to OR them together.  Be nice if the documentation told you that the parameter was a bit flag type.

Thanks!
0
 
LVL 22

Expert Comment

by:nietod
ID: 2654658
MS likes to make things hard for programers.  We don't complain because then we get paid more.  So be quite, or you'll cost us money.  :-)
0
 
LVL 1

Author Comment

by:cbeattie
ID: 2654667
As a matter of fact, the damn docs say "This parameter can be zero or can be one of the following values".  ONE OF THE FOLLOWING VALUES.  Bastards.  But you're right.  If anyone could figure this out, we wouldn't get paid what we do.

Thanks :-)
0
 
LVL 22

Expert Comment

by:nietod
ID: 2654858
yeah, that's what threw me too.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question