Programatically change desktop image?
-
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
-
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
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
-
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
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
-
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
-
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
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