PDA

Click to See Complete Forum and Search --> : Change wallpeper in vc++ (Newbie)


o0Jon0o
Jan 23rd, 2002, 07:09 AM
I'm really new to win32 programming, and for one of my first projects I thought I would make a program to randomly changes the desktop wallpaper.

I found this function: SystemParametersInfo()
and tried to use it in a console app with MFC support like this:

int ver1;
ver1 = SystemParametersInfo(SPI_SETDESKWALLPAPER ,0,"c:/10.bmp",SPIF_SENDCHANGE);
cout << ver1 << "\n";

Strangely but not surprisingly it returned 0 and the wallpaper didn't change. I have tried including winuser.h and windows.h to no avail.
The
guide that I was following (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/sysinfo_4p67.asp) said I needed to include User32.lib so my question is:

how do I include User32.lib and if I do will my program work?

Thanks for you time

Jon

P.S I've just found another msdn guide (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wceui40/htm/cerefSystemParametersInfo.asp) that says exactly the sane thing apart from I need to include Coredll.lib??? any idears?

nabeels786
Jan 23rd, 2002, 07:52 AM
,"c:/10.bmp",

try using a backslash, but im not sure if that matters.

to include the user32.lib, open your project workspace, goto project -> settings. then click on the link tab.

in the "library/object modules", add-in User32.lib, but it should already be there.

nabeels786
Jan 23rd, 2002, 07:55 AM
try this code:



SystemParametersInfo(SPI_SETDESKWALLPAPER, long(0), "C:\\\\paper.bmp", SPIF_UPDATEINIFILE + SPIF_SENDWININICHANGE);

you need two \\ in there so it doesnt warn you about an "unrecognized character escape sequence"

the '+' sign might not work, im not sure, but you need to include both of those vars.

hope that helps

o0Jon0o
Jan 23rd, 2002, 09:19 AM
Thanks for the help but i've tried every variation of the code you gave me but nothing seems to work.

I reckon these got to be some way of initialising the function or including a certain type of mfc support :rolleyes:

If anyone’s interested here's what I’ve done:

Started MS VC++ and made a form based project with MFC appwizard
Drew a button and added a function to it
In the function put the following code:

SystemParametersInfo(SPI_SETDESKWALLPAPER, long(0), "C:\\10.bmp", SPIF_UPDATEINIFILE + SPIF_SENDWININICHANGE);
AfxMessageBox("Function has been run");

CornedBee
Jan 23rd, 2002, 01:39 PM
Use the | operator to join flags:

SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, "C:\\10.bmp", SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);


If it still does not work, do this directly after the funciton call:

LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL );
// Process any inserts in lpMsgBuf.
// ...
// Display the string.
MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION );
// Free the buffer.
LocalFree( lpMsgBuf );

o0Jon0o
Jan 23rd, 2002, 03:32 PM
Thanks for the help guys.

GetLastError() gave me error code 120: Function not supported on this system.
So I agve it ago on my win2k box and it worked fine :D despite the help saying it supported win98.

That’s the first windows function I've ever called and M$ manage to screw it up! :mad:

Think I’ll have to get me linux :D