Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Set Desktop Wallpaper via a MSVC++ Program

Posted on 2000-03-24
11
Medium Priority
?
231 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 800 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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 learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

721 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