Change Wallpaper
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Change Wallpaper

  1. #1
    Join Date
    Aug 2007
    Posts
    28

    Change Wallpaper

    I am using SystemParametersInfo(SPI_SETDESKWALLPAPER,0,path,SPIF_SENDCHANGE);
    to change the desktop in C++.

    My question is how to set the wallpaper options Position(Stretched or Centered or Titled)
    Last edited by skpskpskp; January 10th, 2008 at 01:20 PM.

  2. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,060

    Re: Change Wallpaper

    One way:
    Code:
    USES_CONVERSION;  // First line in your function
    ...
    IActiveDesktop *pActiveDesktop = NULL;
    HRESULT hr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER,
          IID_IActiveDesktop, (void**)&pActiveDesktop);
    if (hr == S_OK)
    {
      WALLPAPEROPT wallpaperopt = {0};
      wallpaperopt.dwSize = sizeof(WALLPAPEROPT);
      wallpaperopt.dwStyle = WPSTYLE_TILE;
      pActiveDesktop->SetWallpaperOptions(&wallpaperopt, NULL);
      LPWSTR wstrImg = T2W(pszFile);
      pActiveDesktop->SetWallpaper(wstrImg, NULL);
      pActiveDesktop->ApplyChanges(AD_APPLY_ALL);
      pActiveDesktop->Release();
    }

  3. #3
    Join Date
    Aug 2007
    Posts
    28

    Re: Change Wallpaper

    Thanks,but because i have been learning WinAPI since last week and I understand 90% of your code and if you have time to explain every line and function i will be very grateful

    Can you give me some links with more informations about it to read
    Last edited by skpskpskp; January 10th, 2008 at 01:55 PM.

  4. #4
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,060

    Re: Change Wallpaper

    Well, the first line "USES_CONVERSION" is needed because I'm using T2W. See MSDN for the T2W explanation.

    Then I get a IActiveDesktop interface using CoCreateInstance. Again, see MSDN for more information on CoCreateInstance.

    Once you have your interface, we can start calling functions on it and one of its functions is SetWallpaperOptions which accepts a WALLPAPEROPT structure with information.

    Then I use the SetWallpaper function to set the actual wallpaper and use ApplyChanges to instruct Windows to apply the changes and refresh the desktop.

    When you're finished with an interface obtained through CoCreateInstance you should call Release on it.

  5. #5
    Join Date
    Feb 2008
    Posts
    4

    Re: Change Wallpaper

    i couldn't figure out, is including shlobj.h enough for that?

  6. #6
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,060

    Re: Change Wallpaper

    Yes, you have to include shlobj.h.
    Do you have any compilation errors?

  7. #7
    Join Date
    Feb 2008
    Posts
    4

    Re: Change Wallpaper

    yes i did have some, it said "error C2065: 'IActiveDesktop' : undeclared identifier" for example, but i figured out the problem about SystemParametersInfo, so everythings ok now.

    by the way, thank you for your interest in my problem, and your replies.

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center