代码重启后失效
写的一个换桌面背景的工具,原来以为只本机的精简系统不行,后来发现所有机子都一样,重启后桌面背景会变成纯兰色的而非关机前设置的桌面壁纸http://www.autoitx.com/thread-27559-1-1.html
#include <GDIPlus.au3>
#include <Array.au3>
Local $arry
Local $count=0
Local $dest="C:\WINDOWS\WallPaper\"
;Global Const $SPI_SETDESKWALLPAPER = 0x0014
;Global Const $SPIF_UPDATEINIFILE = 0x01
;Global Const $SPIF_SENDCHANGE = 0x01
$search=FileFindFirstFile("C:\WINDOWS\WallPaper\"&"*.*")
while 1
$file=FileFindNextFile($search)
if @error then ExitLoop
_ArrayAdd($arry,$file)
$count=$count+1
WEnd ;循环目录中的所有文件
$rnd=Random(1,$count,1) ; 产生随机数
$wpaper=$arry[$rnd] ;随机图片
_GDIPlus_Startup ()
;初始化gdi
$hImage = _GDIPlus_ImageLoadFromFile ($dest&$wpaper)
;选择文件,保存句柄到$hImage
$sCLSID = _GDIPlus_EncodersGetCLSID ("BMP")
;理解成要保存的格式??
$tData = DllStructCreate("int Data")
;创建一个类似C++的数据结构
DllStructSetData($tData, "Data", $GDIP_EVTTRANSFORMROTATE90)
$tParams = _GDIPlus_ParamInit (1)
_GDIPlus_ParamAdd ($tParams, $GDIP_EPGTRANSFORMATION, 1, $GDIP_EPTLONG, DllStructGetPtr($tData, "Data"))
_GDIPlus_ImageSaveToFileEx ($hImage, "Wallpaper1.bmp", $sCLSID, DllStructGetPtr($tParams))
;保存文件,并命名为wallpaper1.bmp
_GDIPlus_ShutDown ()
;FileCopy("D:\Program Files\AutoIt3\work\Wallpaper1.bmp","C:\Documents and Settings\JOHn\Local Settings\Application Data\Microsoft\Wallpaper1.bmp",1)
dllcall("user32","int","SystemParametersInfo","int",20,"int",1,"str","Wallpaper1.bmp","int",1)
;dllcall("user32","int","SystemParametersInfo","int",$SPI_SETDESKWALLPAPER,"int",1,"str","Wallpaper1.bmp","int",BitOR($SPIF_UPDATEINIFILE,$SPIF_SENDCHANGE))
本帖最后由 大叔 于 2011-9-20 13:13 编辑
_GDIPlus_ImageSaveToFileEx ($hImage, "d:\Wallpaper1.bmp", $sCLSID, DllStructGetPtr($tParams))
;保存文件,并命名为wallpaper1.bmp
dllcall("user32","int","SystemParametersInfo","int",20,"int",1,"str","d:\Wallpaper1.bmp","int",1)
这样就OK了。就是保存文件的时候给文件加个路径。当然DLLCALL这句也要.重起没问题 {:face (88):}
你太强大了.能解释下这个为什么要在这两句中加设路径吗?
_GDIPlus_ImageSaveToFileEx ($hImage, "d:\Wallpaper1.bmp", $sCLSID, DllStructGetPtr($tParams))
;保存文件,并命名为wallpaper1.bmp
dllcall("user32","int","SystemParametersInfo","int",20,"int",1,"str","d:\Wallpaper1.bmp","int",1)
因为就算不设路径,图片也已经是存在了的吧
页:
[1]