找回密码
 加入
搜索
查看: 2746|回复: 2

[AU3基础] 代码重启后失效

[复制链接]
发表于 2011-9-20 10:46:07 | 显示全部楼层 |阅读模式
写的一个换桌面背景的工具,原来以为只本机的精简系统不行,后来发现所有机子都一样,重启后桌面背景会变成纯兰色的而非关机前设置的桌面壁纸
http://www.autoitx.com/thread-27559-1-1.html

#include <GDIPlus.au3>
#include <Array.au3>

Local $arry[1]
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:07:34 | 显示全部楼层
本帖最后由 大叔 于 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这句也要.重起没问题
 楼主| 发表于 2011-9-26 21:45:28 | 显示全部楼层

你太强大了.能解释下这个为什么要在这两句中加设路径吗?

_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)


因为就算不设路径,图片也已经是存在了的吧
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-12-22 15:09 , Processed in 0.089476 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表