|
-
Jan 23rd, 2002, 08:09 AM
#1
Change wallpeper in vc++ (Newbie)
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 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 that says exactly the sane thing apart from I need to include Coredll.lib??? any idears?
-
Jan 23rd, 2002, 08:52 AM
#2
Fanatic Member
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.
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Jan 23rd, 2002, 08:55 AM
#3
Fanatic Member
try this code:
PHP 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
Last edited by nabeels786; Jan 23rd, 2002 at 08:58 AM.
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Jan 23rd, 2002, 10:19 AM
#4
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
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");
-
Jan 23rd, 2002, 02:39 PM
#5
Use the | operator to join flags:
PHP Code:
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, "C:\\10.bmp", SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
If it still does not work, do this directly after the funciton call:
PHP Code:
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 );
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 23rd, 2002, 04:32 PM
#6
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|