Results 1 to 6 of 6

Thread: Change wallpeper in vc++ (Newbie)

  1. #1
    o0Jon0o
    Guest

    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?

  2. #2
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919
    ,"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.
    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

  3. #3
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919
    try this code:


    PHP Code:
    SystemParametersInfo(SPI_SETDESKWALLPAPERlong(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?

  4. #4
    o0Jon0o
    Guest
    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");

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Use the | operator to join flags:
    PHP Code:
    SystemParametersInfo(SPI_SETDESKWALLPAPER0"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_NEUTRALSUBLANG_DEFAULT), // Default language
        
    (LPTSTR) &lpMsgBuf,
        
    0,
        
    NULL );
    // Process any inserts in lpMsgBuf.
    // ...
    // Display the string.
    MessageBoxNULL, (LPCTSTR)lpMsgBuf"Error"MB_OK |  MB_ICONINFORMATION );
    // Free the buffer.
    LocalFreelpMsgBuf ); 
    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.

  6. #6
    o0Jon0o
    Guest
    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 despite the help saying it supported win98.

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

    Think I’ll have to get me linux

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width