Solved

Set Desktop Wallpaper via a MSVC++ Program

Posted on 2000-03-24
11
224 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

803 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