We help IT Professionals succeed at work.

short c++ program

j4months
j4months asked
on
How come this program does not work?
-------------------------------------

#include <windows.h>
#include <stdio.h>
#include "stdafx.h"

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
   char bmpfile[]="K:\redapple2.bmp";
   int res=SystemParametersInfo(SPI_SETDESKWALLPAPER,0, bmpfile,1);
//   char buff[100];
//   sprintf(buff,"res= %d",res);
//   MessageBox(NULL,buff,NULL,MB_OK);
   return 0;
}
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2012
Commented:
Because

char bmpfile[]="K:\redapple2.bmp";

should read

char bmpfile[]="K:\\redapple2.bmp";

Author

Commented:
When I run the program, it adds "redapple2.bmp" to the list of files that I can choose for wallpaper from the Control Panel|Display. It, however, does not "Apply," and thus made no change to my wall paper..
Commented:
I beleive the problem you are having is that you are passing 1 rather than 3 to SystemParametersInfo for the fWinIni parameter.  You should probably actually use SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.