Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Programatically change desktop image?

Programatically change desktop image?

Scheduled Pinned Locked Moved C / C++ / MFC
windows-adminquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    clintsinger
    wrote on last edited by
    #1

    How does one change the desktop image in code? I would like to write a program that makes a desktop image containing the ip address of my system. I have found what I think is the right value in the registry. I just need to be able to refresh the desktop to so the changes take effect. Cheers, Clint

    W G 2 Replies Last reply
    0
    • C clintsinger

      How does one change the desktop image in code? I would like to write a program that makes a desktop image containing the ip address of my system. I have found what I think is the right value in the registry. I just need to be able to refresh the desktop to so the changes take effect. Cheers, Clint

      W Offline
      W Offline
      will1383
      wrote on last edited by
      #2

      This code gets the key, checks for a certain bitmap, loads the correct one, and then tiles it. Hope this helps lResult = RegCreateKeyEx(HKEY_CURRENT_USER, "Control Panel\\Desktop", 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKeyResult, &dwDisposition); if (lResult != ERROR_SUCCESS){ printf("Houston we have a problem\n"); } lResult = RegQueryValueEx( hKeyResult, "Wallpaper", NULL, &Type, (unsigned char*)cTmpData, // address of data buffer &cbData ); // // If the background is NOT the correct one, then change the background // to the appropriate one // if (strstr(cTmpData, "mypic.bmp") == NULL) { //strcpy(cBuff,cXvision); if (getenv("SystemDrive") != NULL) sprintf(cBuff,"%s\\iux\\icons\\Amdatabg.bmp",getenv("SystemDrive")); else strcpy(cBuff,"C:\\icons\\mypic.bmp"); printf("background wallpaper is %s\n",cTmpData); printf("should be %s\n",cBuff); lResult = RegSetValueEx(hKeyResult, "Wallpaper", 0, REG_EXPAND_SZ, (unsigned char*)cBuff, lstrlen(cBuff)); if (lResult != ERROR_SUCCESS){ printf("Flordia we have a problem\n"); FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, lResult, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language cBuff, 255, NULL ); printf("error is %s\n",cBuff); } // // now tile the wallpaper // strcpy(cBuff,"1"); printf("now tileing the wallpaper\n"); lResult = RegSetValueEx(hKeyResult, "TileWallpaper", 0, REG_SZ, (unsigned char*)cBuff, lstrlen(cBuff)); if (lResult != ERROR_SUCCESS){ printf("Flordia we have a problem\n"); FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, lResult, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language cBuff, 255, NULL ); printf("error is %s\n",cBuff); } } Dan Willis

      C 1 Reply Last reply
      0
      • W will1383

        This code gets the key, checks for a certain bitmap, loads the correct one, and then tiles it. Hope this helps lResult = RegCreateKeyEx(HKEY_CURRENT_USER, "Control Panel\\Desktop", 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKeyResult, &dwDisposition); if (lResult != ERROR_SUCCESS){ printf("Houston we have a problem\n"); } lResult = RegQueryValueEx( hKeyResult, "Wallpaper", NULL, &Type, (unsigned char*)cTmpData, // address of data buffer &cbData ); // // If the background is NOT the correct one, then change the background // to the appropriate one // if (strstr(cTmpData, "mypic.bmp") == NULL) { //strcpy(cBuff,cXvision); if (getenv("SystemDrive") != NULL) sprintf(cBuff,"%s\\iux\\icons\\Amdatabg.bmp",getenv("SystemDrive")); else strcpy(cBuff,"C:\\icons\\mypic.bmp"); printf("background wallpaper is %s\n",cTmpData); printf("should be %s\n",cBuff); lResult = RegSetValueEx(hKeyResult, "Wallpaper", 0, REG_EXPAND_SZ, (unsigned char*)cBuff, lstrlen(cBuff)); if (lResult != ERROR_SUCCESS){ printf("Flordia we have a problem\n"); FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, lResult, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language cBuff, 255, NULL ); printf("error is %s\n",cBuff); } // // now tile the wallpaper // strcpy(cBuff,"1"); printf("now tileing the wallpaper\n"); lResult = RegSetValueEx(hKeyResult, "TileWallpaper", 0, REG_SZ, (unsigned char*)cBuff, lstrlen(cBuff)); if (lResult != ERROR_SUCCESS){ printf("Flordia we have a problem\n"); FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, lResult, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language cBuff, 255, NULL ); printf("error is %s\n",cBuff); } } Dan Willis

        C Offline
        C Offline
        clintsinger
        wrote on last edited by
        #3

        Thanks, I haven't tried it out yet but will it automatically update the background or do I need to restart the system? I would also assume that I woulnd't set "TileWallpaper" if I didn't want that option, but rather just show the image centered. Cheers, Clint

        W 1 Reply Last reply
        0
        • C clintsinger

          Thanks, I haven't tried it out yet but will it automatically update the background or do I need to restart the system? I would also assume that I woulnd't set "TileWallpaper" if I didn't want that option, but rather just show the image centered. Cheers, Clint

          W Offline
          W Offline
          will1383
          wrote on last edited by
          #4

          I don't remember off hand. You'll have to check on that :) Dan Willis

          1 Reply Last reply
          0
          • C clintsinger

            How does one change the desktop image in code? I would like to write a program that makes a desktop image containing the ip address of my system. I have found what I think is the right value in the registry. I just need to be able to refresh the desktop to so the changes take effect. Cheers, Clint

            G Offline
            G Offline
            Gavin Taylor
            wrote on last edited by
            #5

            Off the top of my head (no copy of MSDN kicking about) i think u should be able to use the API SystemParametersInfo Should work something like: if( SystemParametersInfo( SPI_SETDESKWALLPAPER, 0, ( PVOID ) TEXT( "background.bmp" ), SPIF_SENDCHANGE | SPIF_UPDATEINIFILE ) == TRUE ) { // should have worked }

            Gavin Taylor w: http://www.gavintaylor.co.uk

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups