Thread: Setting desktop background color

  1. #1
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212

    Setting desktop background color

    How can I get at the desktop background settings programatically? Are they stored as a registry entry?

  2. #2
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273
    What sort of background?

    If it's just the wallpaper you want to change, and Active Desktop is disabled, then:-
    Code:
    HKEY hKey;
    
    RegOpenKeyEx(HKEY_CURRENT_USER, "Control Panel\\Desktop", 0, KEY_SET_VALUE, &hKey);
    RegSetValueEx(hKey, "Wallpaper", 0, REG_SZ, "Image.bmp", 10);
    RegCloseKey(hKey);
    SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, NULL, SPIF_SENDCHANGE);
    Otherwise I dunno how to change the Active Desktop settings.

  3. #3
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Never tried this myself, but a search on MSDN turned this up.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  4. #4
    Registered User
    Join Date
    Jul 2005
    Posts
    69
    I'll give a brief example but I think this is going to be more informative and include more detail: Set Desktop Color In short:
    Code:
        int aiElements[1] = {COLOR_BACKGROUND};
        DWORD aColors[1] = {RGB(0, 255, 0)}; //Green
        SetSysColors(1, aiElements, aColors);
    Regards,
    Brian

  5. #5
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    Wow, another Brian (bmf is a Brian too amongst others, this should be called brianprogramming.com). Thanks Brian.

  6. #6
    Banal internet user
    Join Date
    Aug 2002
    Posts
    1,380
    Quote Originally Posted by Brian
    Wow, another Brian (bmf is a Brian too amongst others, this should be called brianprogramming.com). Thanks Brian.
    Don't forget me!

  7. #7
    Registered User
    Join Date
    Mar 2009
    Location
    Bozen
    Posts
    95
    Hello,
    I need to change the desktop background programming.

    The execution of the below .vbs doesn't do anything. What is wrong? Thank you


    Code:
    dim wshShell
    dim sUserName
    
    Set wshShell = WScript.CreateObject("WScript.Shell")
    sUserName = wshShell.ExpandEnvironmentStrings("%USERNAME%")
    
    Set oShell = CreateObject("WScript.Shell")
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    
    sWinDir = oFSO.GetSpecialFolder(0)
    sWallPaper = "C:\Documents and Settings\Simpatico\My Documents\Woerter Speichern Files\lastvocab.png"
    
    ' update in registry
    oShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", sWallPaper
    
    ' let the system know about the change
    oShell.Run "%windir%\System32\RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters", 1, True

  8. #8
    Registered User
    Join Date
    Mar 2009
    Location
    Bozen
    Posts
    95
    any help on this?

  9. #9
    Registered User
    Join Date
    Apr 2004
    Posts
    210
    If you only want to change the wallpaper then there is absolutely no need to go through the registry for it.

    Code:
    SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, filename, SPIF_UPDATEINIFILE);
    Just specify a filename instead of NULL as third parameter. Windows versions prior to Vista will only accept .BMP files, so you'll have to convert them first unless you programm only needs to run on vista/7.

  10. #10
    Registered User
    Join Date
    Mar 2009
    Location
    Bozen
    Posts
    95
    I need a complete script example.

    I've found this on microsoft's website, but nothing happens when I execute the script and log out.
    (I've placed the file also in the system32 folder, let alone changing the path.

    Code:
    Const HKEY_CURRENT_USER = &H80000001
    
    strComputer = "."
    
    Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
    
    intLowNumber = 1
    intHighNumber = 6
    
    Randomize
    
    intNumber = Int((intHighNumber - intLowNumber + 1) * Rnd + intLowNumber)
    
    Select Case intNumber
        Case 1
            strValue = "C:\WINDOWS\System32\Wallpaper1.bmp"
        Case 2
            strValue = "C:\WINDOWS\System32\Wallpaper2.bmp"
        Case 3
            strValue = "C:\WINDOWS\System32\Wallpaper3.bmp"
        Case 4
            strValue = "C:\WINDOWS\System32\Wallpaper4.bmp"
        Case 5
            strValue = "C:\WINDOWS\System32\Wallpaper5.bmp"
        Case 6
            strValue = "C:\WINDOWS\System32\Wallpaper6.bmp"
    End Select
    
    strKeyPath = "Control Panel\Desktop"
    ValueName = "Wallpaper"
    
    objReg.SetStringValue HKEY_USERS, strKeyPath, ValueName, strValue

  11. #11
    Registered User
    Join Date
    Apr 2007
    Posts
    137
    Quote Originally Posted by Nyda View Post
    Windows versions prior to Vista will only accept .BMP files, so you'll have to convert them first unless you programm only needs to run on vista/7.
    You can set JPG, GIF or any format for wallpaper on XP, but with COM

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Critique my lighting model.
    By psychopath in forum Game Programming
    Replies: 4
    Last Post: 08-12-2006, 06:23 PM
  2. Windows background color
    By Exile in forum Windows Programming
    Replies: 2
    Last Post: 01-23-2005, 07:55 AM
  3. Setting the background color of my main window
    By Garfield in forum Windows Programming
    Replies: 5
    Last Post: 07-06-2002, 11:25 PM
  4. Text and background Color
    By Goof Program in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 03-29-2002, 06:59 PM
  5. Just one Question?
    By Irish-Slasher in forum C++ Programming
    Replies: 6
    Last Post: 02-12-2002, 10:19 AM