Background changer for VM's
Posted: Tue Sep 08, 2009 12:07 am
Here's a little bit of (ugly
) code that changes your wallpaper temporary. I wrote it whilst playing with VM's. Added to the startup sequence it helps you identify different VM's at a glance.
Run it from the prompt and it will give you all options.

Run it from the prompt and it will give you all options.
Code: Select all
; wallx v0.03x
; pb4.40b1
;
#program_name = "WallX"
#program_version = "v0.04x"
#program_copyright = "c2009 EJN"
;
InitNetwork()
UseJPEGImageDecoder()
wall_filename.s = "c:\wallx.bmp"
fontname.s = "Arial"
fontsize.i = 64
;
If CountProgramParameters() = 0
;
OpenConsole()
PrintN("")
PrintN("wallx "+#program_version+" "+#program_copyright+":")
PrintN(" replace wallpaper with a generated image / text")
PrintN("")
PrintN("command line parameters (interpreted from left to right):")
PrintN(" red - red background")
PrintN(" blue - blue background")
PrintN(" green - green background")
PrintN(" black - black background")
PrintN(" white - white background")
PrintN(" grey - grey background")
PrintN(" base - diagonal yellow / black stripes")
PrintN(" traffic - diagonal red / white stripes")
PrintN(" fade - fade to black, top to bottom")
PrintN(" dots - superimpose black dots (25%)")
PrintN(" font <name> <size> - specify font name And size")
PrintN(" big <text> - large white text")
PrintN(" text <text|text> - draw one or more text lines")
PrintN("")
PrintN("embedded text elements:")
PrintN(" ~ip~ - ip number")
PrintN(" ~host~ - host name")
PrintN("")
PrintN("all commands in lowercase, enclose spaces in doublequotes")
PrintN("")
PrintN("examples:")
PrintN(" wallx red big 1")
PrintN(" wallx base text "+#DQUOTE$+"WINDOWS XP UK SP3 | BASE IMAGE - DO NOT MODIFY"+#DQUOTE$)
PrintN(" wallx blue big "+#DQUOTE$+".21"+#DQUOTE$+" dots text "+#DQUOTE$+"~host~ ~ip~"+#DQUOTE$+" fade")
PrintN(" wallx traffic fade big 1 dots text "+#DQUOTE$+"MYSQL SERVER | 192.168.0.1"+#DQUOTE$)
PrintN(" wallx blue fade font Arial 100 text "+#DQUOTE$+"CLIENT ONE | ~host~ - ~ip~"+#DQUOTE$)
PrintN("")
CloseConsole()
;
Else
;
ExamineDesktops()
width = DesktopWidth(0)
height = DesktopHeight(0)
;
CreateImage(1,width,height,32)
Repeat
command.s = ProgramParameter()
Select command
Case "red"
;
; 50% red
;
StartDrawing(ImageOutput(1))
DrawingMode(#PB_2DDrawing_Default)
Box(0,0,width,height,RGB($7F,$00,$00))
StopDrawing()
;
Case "green"
;
; 50% green
;
StartDrawing(ImageOutput(1))
DrawingMode(#PB_2DDrawing_Default)
Box(0,0,width,height,RGB($00,$7F,$00))
StopDrawing()
;
Case "blue"
;
; 50% blue
;
StartDrawing(ImageOutput(1))
DrawingMode(#PB_2DDrawing_Default)
Box(0,0,width,height,RGB($00,$00,$7F))
StopDrawing()
;
Case "black"
;
; full black
;
StartDrawing(ImageOutput(1))
DrawingMode(#PB_2DDrawing_Default)
Box(0,0,width,height,0)
StopDrawing()
;
Case "white"
;
; 100% white
;
StartDrawing(ImageOutput(1))
DrawingMode(#PB_2DDrawing_Default)
Box(0,0,width,height,$FFFFFF)
StopDrawing()
;
Case "grey"
;
; 25% grey
;
StartDrawing(ImageOutput(1))
DrawingMode(#PB_2DDrawing_Default)
Box(0,0,width,height,$3F3F3F)
StopDrawing()
;
Case "base"
;
; yellow diagonals on black background
;
StartDrawing(ImageOutput(1))
DrawingMode(#PB_2DDrawing_Default)
Box(0,0,width,height,0)
x = 0-width
Repeat
x = x+width/10
For xx=x To x+width/21
LineXY(xx,0,xx+width,width,RGB($FF,$FF,$00))
Next xx
Until x > width
StopDrawing()
;
Case "traffic"
;
; red diagonals on a white background
;
StartDrawing(ImageOutput(1))
DrawingMode(#PB_2DDrawing_Default)
Box(0,0,width,height,$FFFFFF)
x = 0-width
Repeat
x = x+width/10
For xx=x To x+width/20
LineXY(xx,0,xx+width,width,$0000FF)
Next xx
Until x > width
StopDrawing()
;
Case "dots"
;
; small pattern of black dots (25%)
;
StartDrawing(ImageOutput(1))
DrawingMode(#PB_2DDrawing_Default)
x = 0
While x < width
x = x+4
y = 0
While y < height
Box(x,y,2,2,0)
y = y+4
Wend
Wend
StopDrawing()
;
Case "fade"
;
; fade to black top to bottom
;
StartDrawing(ImageOutput(1))
DrawingMode(#PB_2DDrawing_AlphaBlend)
For y = 0 To height-1
LineXY(0,y,width,y,y*255/height*$1000000)
Next y
StopDrawing()
;
Case "font"
;
; select font to use
;
fontname = ProgramParameter()
fontsize = Val(ProgramParameter())
;
Case "big"
;
; big background text in white
; font name as specified by 'font <fontname> <fontsize>'
; font size hardcoded
; use for other fontsizes the option 'text'
;
t.s = ProgramParameter()
ExamineIPAddresses()
t = ReplaceString(t,"~ip~",StringField(IPString(NextIPAddress()),4,"."))
;
LoadFont(1,fontname,height-384,#PB_Font_Bold|#PB_Font_HighQuality)
StartDrawing(ImageOutput(1))
DrawingMode(#PB_2DDrawing_Transparent)
DrawingFont(FontID(1))
DrawText(width/2-TextWidth(t)/2,height/2-TextHeight(t)/2,t,$FFFFFF)
StopDrawing()
FreeFont(1)
;
Case "text"
;
; foreground text in 100% with black shadow
; font name and size specified by 'font <fontname> <fontsize>'
;
; add embedded elements
;
t.s = ProgramParameter()
ExamineIPAddresses()
t = ReplaceString(t,"~ip~",IPString(NextIPAddress()))
t = ReplaceString(t,"~host~",Hostname())
;
; display
;
LoadFont(2,fontname,fontsize,#PB_Font_Bold|#PB_Font_HighQuality)
LoadFont(3,fontname,fontsize/2,#PB_Font_Bold|#PB_Font_HighQuality)
StartDrawing(ImageOutput(1))
DrawingMode(#PB_2DDrawing_Transparent)
n = 1
Repeat
tt.s = Trim(StringField(t,n,"|"))
If tt.s = ""
ElseIf n = 1
DrawingFont(FontID(2))
DrawText(width/2-TextWidth(tt)/2+2,height/2-fontsize/2+2,tt,$000000)
DrawText(width/2-TextWidth(tt)/2,height/2-fontsize/2,tt,$FFFFFF)
Else
DrawingFont(FontID(3))
DrawText(width/2-TextWidth(tt)/2+2,height/2-fontsize*0.4+fontsize*0.8*n+2,tt,$000000)
DrawText(width/2-TextWidth(tt)/2,height/2-fontsize*0.4+fontsize*0.8*n,tt,$FFFFFF)
EndIf
n = n+1
Until tt.s = ""
StopDrawing()
FreeFont(2)
FreeFont(3)
;
EndSelect
Until command = ""
;
SaveImage(1,wall_filename)
SystemParametersInfo_(#SPI_SETDESKWALLPAPER,0,@wall_filename,#SPIF_SENDWININICHANGE)
;
FreeImage(1)
EndIf