Version 0 of web2desktop

Updated 2002-10-28 15:32:13

# This script sets the daily User Friendly strip as my desktop background.

 # I post it here because it may be useful to someone.
 # I should write a funny disclaimer about the quality of my code.
 # Have you seen all the cool stuff at the UF shop?

 package require http    ; # needed to download the image
 package require Img     ; # needed to convert gif -> bmp
 load ffidl05.dll              ; # needed to call Windows API
 set target_page "http://www.userfriendly.org" ; # the page to molest
 set gif_image_path "c:\\gif.gif"              ; # download the image here..
 set bmp_image_path "c:\\bmp.bmp"       ; # ... and feed Windows with this

 #Sugar is sweet ...
 proc between { start "and" end "in" text} {
    set string_start  [string first $start $text]
    set string_end    [string first $end $text $string_start]
    set start_removed [string replace [string range $text $string_start $string_end] 0 [expr [string length $start ]-1] ]
    return [string replace $start_removed end end ]

}

 #I'm behind a proxy here, I must configure it...
 http::config -proxyhost 172.29.153.41 -proxyport 8080
 #... now I can get the initial page
 set html [http::data [http::geturl $target_page]]
 #Image size parameters change, get the whole <IMG> first:
 set url [between "<IMG ALT=\"Latest Strip\"" and "</A>" in $html]
 #I only want the image url...
 set url [between "SRC=\"" and "\">" in $url]
 #...and write the image to a file:
 set gif_file [open $gif_image_path w+] 
 http::geturl $url -blocksize 1024 -channel $gif_file
 close $gif_file
 #I have to convert to BMP to be able to use the Windows API call
 set image [image create photo -file $gif_image_path]
 $image write $bmp_image_path -format bmp
 #this fiddles with user32.dll and refreshes the background immediately
 ffidl::callout dll_SystemParametersInfo {int int pointer-utf8 int} int       [ffidl::symbol user32.dll  SystemParametersInfoA]
 dll_SystemParametersInfo 20 0 $bmp_image_path 3
 exit

#keywords: Setting Windows Desktop backgroung #keywords: SystemParametersInfo , SPIF_SENDCHANGE , SPIF_UPDATEINIFILE , SPIF_SENDWININICHANGE