russcript Posted December 23, 2010 Posted December 23, 2010 Hello, I am working on a app to download the picture from the bing search engine every day and apply it as a desktop wallpaper. the picture name changes daily so it works by downloading the source code, then using a StringRegExp to find the image name. for some reason the _INetGetSource data doesn't seem to work for the StringRegExp source, noting that if i save the source and then search that it works perfectly. So either I need to save the source code to a temporary text file and search that or figure out why it not working as is. thanks. expandcollapse popup#Include <string.au3> #include <INet.au3> #include <array.au3> #Include <GDIPlus.au3> $Source =_INetGetSource ( "http://www.bing.com/") ;gets page source code ;FileOpen("C:\source.txt",0) ; it works with saved source code but not with the above _INetGetSource ;$Source=FileRead("C:\source.txt") ; to try this you will need to save the current http://www.bing.com source to the source path here $nOffset = 1 While 1 $fName = StringRegExp($Source, '(?:hpk2/)(.*?)(?:.jpg)', 1, $nOffset) ;searches for image name in the source code If @error = 0 Then $nOffset = @extended Else ExitLoop EndIf for $i = 0 to UBound($fName) - 1 $Name = $fName[$i] Next WEnd $url="http://www.bing.com/fd/hpk2/" & $Name & ".jpg" ;compiles the url InetGet($url,@TempDir & "\WALL.jpg") ;downloads the picture _setwallpaper(@TempDir & "\WALL.jpg",2,1) ;sets the wallpaper ;=============================================================================== ; ; Description: Sets the desktop wallpaper picture ; Syntax: _setwallpaper($pic, $style = 0, $warn = 1) ; Parameter(s): $pic - Path and filename of the picture to set ( JPG or BITMAP ) ; $style - 0 = centered 1 = Tiled 2 = Stretched ( set to 0 ) ; $warn - 0 = false 1 = true ( set to 1 ) ; Requirement(s): none ; Return Value(s): On Success - Returns 0 ; On Failure - Returns -1 ; Author(s): ludocus ; Note(s): $warn may be anoying,.. Build in picture converter to bmp ; ;=============================================================================== Func _setwallpaper($pic, $style = 0, $warn = 1) if $warn = 1 then $m1 = @DesktopHeight/2 $m2 = @DeskTopWidth/2 EndIf If Not FileExists($pic) Then Return -1 $s = StringSplit ( $pic, '.', 1 ) if $s[2] = 'bmp' Then ;If Not $s[2] = \'bmp\' then.... didn\'t seem to be working, so that\'s why I did this.. $bmp = 'true' Else $bmp = 'false' EndIf If $bmp = 'false' then $text = StringReplace($pic, ".jpg", ".bmp") _GDIPlus_Startup () $hImage = _GDIPlus_ImageLoadFromFile($pic) $sCLSID = _GDIPlus_EncodersGetCLSID ("BMP") _GDIPlus_ImageSaveToFileEx($hImage, $text, $sCLSID) _GDIPlus_ShutDown() $pic = $text EndIf Local $SPI_SETDESKWALLPAPER = 20 Local $SPIF_UPDATEINIFILE = 1 Local $SPIF_SENDCHANGE = 2 Local $REG_DESKTOP= "HKEY_CURRENT_USER\Control Panel\Desktop\" if $style = 1 then RegWrite($REG_DESKTOP, "TileWallPaper", "REG_SZ", 1) RegWrite($REG_DESKTOP, "WallpaperStyle", "REG_SZ", 0) Else RegWrite($REG_DESKTOP, "TileWallPaper", "REG_SZ", 0) RegWrite($REG_DESKTOP, "WallpaperStyle", "REG_SZ", $style) EndIf DllCall("user32.dll", "int", "SystemParametersInfo", _ "int", $SPI_SETDESKWALLPAPER, _ "int", 0, _ "str", $pic, _ "int", BitOR($SPIF_UPDATEINIFILE, $SPIF_SENDCHANGE)) Return 0 if $warn = 1 then sleep ( 2000 ) EndIf EndFunc ;==>_setwallpaper
russcript Posted December 24, 2010 Author Posted December 24, 2010 how would that explain that it works with the saved source but not with data returned with _INetGetSource?
russcript Posted December 24, 2010 Author Posted December 24, 2010 how would that explain that it works with the saved source but not with data returned with _INetGetSource?Edit: I believe I resolved this by adding a small sleep after the INetGetSource to allow for download time
Thornhunt Posted December 27, 2010 Posted December 27, 2010 (edited) /removed Edited December 27, 2010 by Thornhunt Budweiser + room = warm beerwarm beer + fridge = too long!warm beer + CO2 fire extinguisher = Perfect![quote]Protect the easly offended ... BAN EVERYTHING[/quote]^^ hmm works for me :D
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now