|
楼主 |
发表于 2009-8-18 16:49:31
|
显示全部楼层
最终如下:
AutoIt Version: 3.2.12.1
Author: Zhangzq
Script Function:
Set Desktop Wallpaper Randomly.
#ce
; Script Start - Add your code below here
AutoItSetOption("MustDeclareVars", 1)
#include<GDIPlus.au3>
#include<File.au3>
#include<Misc.au3>
Const $AppTitle = "Wallpaper Randomly"
_Singleton($AppTitle)
Dim $strPathToLoad, $strPathToSave
Dim $strOption, $i
Dim $strName, $strWallpaper
If $CmdLine[0] = 0 Then
$strPathToLoad = ".\"
Else
$strPathToLoad = $CmdLine[1]
$strOption = StringLower($strPathToLoad)
If $strOption = "-h" Or $strOption = "/h" Then
$strName = @ScriptName
If StringRight(StringLower($strName), 4) = ".au3" Then $strName = "autoit3.exe " & $strName
MsgBox(64, $AppTitle, _
"Usage: " & $strName & " [Folder1] [Folder2] ... [FolderN]" & @CRLF & @CRLF & _
"Set Desktop Wallpaper randomly with Pictures in Folder(s)" & @CRLF & _
"Or My Pictures if no Folder Specified")
Exit
Else
For $i = 2 to $CmdLine[0]
$strPathToLoad = $strPathToLoad & "|" & $CmdLine[$i]
Next
EndIf
EndIf
$strPathToSave = @UserProfileDir & "\Local Settings\Application Data\Microsoft\"
If _GetRandomPicture($strPathToLoad, $strName) Then Exit
If StringLower(StringRight($strName, 4)) = ".jpg" Then
$strWallpaper = _TempFile(@TempDir, "~wpr_", ".bmp")
_JpgToBmp($strName, $strWallpaper)
FileMove($strWallpaper, $strPathToSave & "Wallpaper1.bmp", 1)
$strWallpaper = $strPathToSave & "Wallpaper1.bmp"
Else
$strWallpaper = $strPathToSave & "Wallpaper1.bmp"
FileCopy($strName, $strWallpaper, 1)
EndIf
DllCall("user32","int","SystemParametersInfo","int",20,"int",0,"str",$strWallpaper,"int",0)
RegWrite("HKEY_CURRENT_USER\Control Panel\Desktop", "ConvertedWallpaper", "REG_SZ", $strName)
RegWrite("HKEY_CURRENT_USER\Control Panel\Desktop", "Wallpaper", "REG_SZ", $strWallpaper)
Func _GetRandomPicture($strWhere, ByRef $strGot)
Local $arrayWhere, $search, $arrayName, $strPath, $strFind, $strTemp, $i
$strGot = ""
$strTemp = ""
$arrayWhere = StringSplit($strWhere, "|")
For $i = 1 To $arrayWhere[0]
$strPath = $arrayWhere[$i]
If StringRight($strPath, 1) <> "\" Then $strPath = $strPath & "\"
$search = FileFindFirstFile($strPath & "*.*")
If $search <> -1 Then
While 1
$strFind = FileFindNextFile($search)
If @error Then ExitLoop
If StringInStr($strFind, ".jpg", 2) Or StringInStr($strFind, ".bmp", 2) Then
$strTemp = $strTemp & "|" & $strPath & $strFind
EndIf
WEnd
EndIf
Next
If $strTemp = "" Then Return -1
$strTemp = StringTrimLeft($strTemp, 1)
$arrayName = StringSplit($strTemp, "|")
If $arrayName[0] > 1 Then
$i = Random(1, $arrayName[0], 1)
$strTemp = $arrayName[$i]
EndIf
$strGot = $strTemp
Return 0
EndFunc
Func _JpgToBmp($Jpg,$Bmp)
Local $hImage, $CLSID
_GDIPlus_StartUp()
$hImage = _GDIPlus_ImageLoadFromFile($Jpg)
$CLSID = _GDIPlus_EncodersGetCLSID("BMP")
_GDIPlus_ImageSaveToFileEx($hImage,$Bmp, $CLSID)
_GDIPlus_ShutDown()
EndFunc |
|