WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

System UDFs

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Change Desktop Background Color

 Keywords: change desktop background color rgb SetSysColors SetSysBackgroundColor

This code can be used to change the systems desktop background color with out a reboot.
; Note: Additional error handling needed

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Changes red-green-blue color specification
; to Win32 COLORREF.
;
; Parameters: nRed - amount of red (0 to 255)
;             nGreen - amount of green (0 to 255)
;             nBlue - abount of blue (0 to 255)
;
; Return: Win32 COLOREF integer
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#DefineFunction RGB(nRed, nGreen, nBlue)
   Return nRed|(nGreen<<8)|(nBlue<<16)
#EndFunction

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Changes system default background color.
;
; Paramener: nRGB - Win32 COLORREF
;
; Return: @True on success otherwise @False
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#DefineFunction SetSysBackgroundColor( nRGB )

   lpaElements  = BinaryAlloc(4)
   lpaRgbValues = BinaryAlloc(4)

   cElements = 1
   BinaryPoke4(lpaElements, 0, 1)   ; 1 means desktop background color.
   BinaryPoke4(lpaRgbValues, 0, nRGB)

   bReturn = DllCall(DirWindows(1):"user32.dll",long:"SetSysColors",long:cElements,lpbinary:lpaElements,lpbinary:lpaRgbValues)

   BinaryFree(lpaElements)
   BinaryFree(lpaRgbValues)
   Return bReturn
#EndFunction

; Set windows background to grey
nRGB = RGB(208, 208, 208)
SetSysBackgroundColor( nRGB )

Display( 5, "Windows Color Change", "Going to white in 5 seconds")

; Set windows background to white
nRGB = RGB(255, 255, 255)
SetSysBackgroundColor( nRGB )

Article ID:   W18398
Filename:   Change Desktop Background Color.txt
File Created: 2009:12:11:10:24:26
Last Updated: 2009:12:11:10:24:26