Solved

Set Desktop Wallpaper via a MSVC++ Program

Posted on 2000-03-24
11
228 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

636 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