找回密码
 加入
搜索
查看: 4126|回复: 9

[AU3基础] 求一款可以保存和恢复桌面图标顺序的源码或软件--(内有事例)

  [复制链接]
发表于 2010-7-29 12:58:42 | 显示全部楼层 |阅读模式
本帖最后由 qq8955333 于 2010-7-30 11:29 编辑
求一款可以保存和恢复桌面图标顺序的源码或软件

下面提供一个AU3的源码,可以保存和还原图标的顺序,但是有一点不好,就是还原的时候没法静默,必须得点一下否,然后导入配置文件才行,我在网吧工作,这样的步骤可以说很是无用,求大家帮忙给改改

改成: 请求方案一:    第一次运行软件后进行图标位置的保存,生成配置文件,如果配置文件存在,那么下次执行该软件后会自动还原桌面图标位置。

       请求方案二:    也可以现有的功能不变,加一个参数可以实现自动恢复图标的位置

下面是代码:


#NoTrayIcon 
#AutoIt3Wrapper_icon=D:\autoit3\Aut2Exe\Icons\FOLDER.ico 
#AutoIt3Wrapper_Compression=4 
#AutoIt3Wrapper_UseAnsi=y 
#AutoIt3Wrapper_Res_Comment=2008-04-19, 23:31 
#AutoIt3Wrapper_Res_Description=桌面图标同步程序 
#AutoIt3Wrapper_Res_Fileversion=1.0.0.1 
#AutoIt3Wrapper_Res_LegalCopyright=Amu 

#include <GuiListView.au3> 
Opt("MustDeclareVars", 1) 
Global $hWndManager = WinGetHandle("Program Manager") 
Global $hWndDesktop = ControlGetHandle("Program Manager","",1) 
If Not IsDeclared("GWL_STYLE") Then Global Const $GWL_STYLE = -16 
Global $LVS_Style = _WinAPI_GetWindowLong($hWndDesktop, $GWL_STYLE) 
Global $inifile, $iSet, $iRefresh, $SNAPTOGRID 

If $CmdLine[0] Then 
     For $i = 1 To $CmdLine[0] 
         Select 
             Case StringRegExp($CmdLine[$i], '^[/-](?i)load[=:].+$|^[/-](?i)l[=:].+$') And Not $inifile         
                 $iSet = 1 
                 $inifile = StringRegExpReplace($CmdLine[$i], '^[/-](?i)load[=:]?|^[/-](?i)l[=:]?', "") 
                 
             Case StringRegExp($CmdLine[$i], '^[/-](?i)save[=:].+$|^[/-](?i)s[=:].+$') And Not $inifile 
                 $iSet = 0 
                 $inifile = StringRegExpReplace($CmdLine[$i], '^[/-](?i)save[=:]?|^[/-](?i)s[=:]?', "") 
                 
             Case StringRegExp($CmdLine[$i], '^[/-](?i)SnapToGrid[=:]\d+$|^[/-](?i)g[=:]\d+$') And $inifile         
                 $SNAPTOGRID = Number (StringRegExpReplace($CmdLine[$i], '^[/-](?i)SnapToGrid[=:]?|^[/-](?i)g[=:]?', "") ) 
                 
             Case StringRegExp($CmdLine[$i], '^[/-](?i)Refresh$|^[/-](?i)r$') 
                 $iRefresh = 1 
                 
             Case StringRegExp($CmdLine[$i], '^[/-](?i)Help$|^[/-](?i)[?h]$') 
                 MsgBox(64,"参数帮助!","AutoIcon.exe [</load|/save>=<file>] [/G=<0|1>] [/R]" & @CRLF & "" & @CRLF & _ 
                     "/load=file 要加载的配置文件。" & @CRLF & "/save=file 要保存的配置文件。" & @CRLF & _ 
                         "/G=<0|1>   为“0”取消图标对齐到网格,为“1”图标对齐到网格,默认不作更改。" & @CRLF & "/R         相当于桌面右键“刷新”") 
                 Exit 
             Case Not $inifile 
                 $inifile = $CmdLine[$i] 
                 If FileExists($inifile) Then $iSet = 1 
         EndSelect     
     Next 
Else 
     If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer 
     $iMsgBoxAnswer = MsgBox(547,"注意!","" & @CRLF & "选“是”保存桌面图标位置信息到文件" & @CRLF & "" & @CRLF & "选“否”从文件读取并排列桌面图标。") 
     Select 
         Case $iMsgBoxAnswer = 6 ;Yes 
             $inifile = FileSaveDialog( "输入一个文件名。", @ScriptDir, "配置文件(*.ini)", 2) 
             If @error Or Not $inifile Then Exit 
             $iSet = 0 
             If Not StringRegExp($inifile, "\.ini$") Then $inifile &= ".ini" 
         Case $iMsgBoxAnswer = 7 ;No 
             $inifile = FileOpenDialog( "选择一个文件。", @ScriptDir, "配置文件(*.ini)", 1) 
             If @error Or Not $inifile Then Exit 
             $iSet = 1 
         Case $iMsgBoxAnswer = 2 ;Cancel 
             Exit 
     EndSelect     
EndIf 

If $iSet Then 
     If $SNAPTOGRID Then $SNAPTOGRID = $LVS_EX_SNAPTOGRID 
     If IsNumber ($SNAPTOGRID) Then _SendMessage($hWndDesktop, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_SNAPTOGRID, $SNAPTOGRID) 
     If BitAND($LVS_Style, $LVS_AUTOARRANGE) Then _WinAPI_SetWindowLong($hWndDesktop, $GWL_STYLE, $LVS_Style - $LVS_AUTOARRANGE );取消自动排列 
     
     If $iRefresh Then DllCall("shell32.dll", "none", "SHChangeNotify", "long", 0x8000000, "int", 0, "ptr", 0, "ptr", 0);刷新图标 
     _SaveAndLoadIconPos($inifile, 1) 
     ;Run("RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters");刷新桌面(通过复制文件的方式替换壁纸文件适用) 
Else 
     _SaveAndLoadIconPos($inifile) 
EndIf 

Func _SaveAndLoadIconPos($iFile, $iLoad = 0) 
     Local $iCount, $iIndex, $sName, $xy     
     If Not IsHWnd($hWndManager) Then $hWndManager = WinGetHandle("Program Manager") 
     If Not IsHWnd($hWndDesktop) Then $hWndDesktop = ControlGetHandle("Program Manager","",1) 
     $iCount = ControlListView($hWndManager, "", $hWndDesktop, "GetItemCount") 
     If @error Then 
         SetError(1) 
         Return 0 
     EndIf 
     If Not $iLoad And FileExists($iFile) Then IniDelete($iFile, "图标位置") 
     For $iIndex = 0 to $iCount - 1 
         $sName = ControlListView($hWndManager, "", $hWndDesktop,"GetText", $iIndex) 
         If $iLoad Then 
             $xy = StringSplit (IniRead ($iFile, "图标位置", $sName, ""), ",") 
             If $xy[0] = 2 Then _ 
             _SendMessage($hWndDesktop, $LVM_SETITEMPOSITION, $iIndex, BitOR(BitShift($xy[2], -16), BitAND($xy[1], 0xffff) ) ) 
         Else;保存图标信息 
             $xy = _GUICtrlListView_GetItemPosition($hWndDesktop, $iIndex) 
             IniWrite($iFile, "图标位置", $sName, $xy[0] & "," & $xy[1] ) 
         EndIf     
     Next 
     Return 1 
EndFunc

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2010-7-29 22:29:17 | 显示全部楼层
顶起一下,为什么没人回答啊
 楼主| 发表于 2010-7-30 11:29:48 | 显示全部楼层
顶一下,不信没有人会
发表于 2010-7-31 00:49:19 | 显示全部楼层
现在在用别人的电脑,没法测试你的。
你知道吗?你这个标题可不太好,一看,感觉跟AU3无关,故,进来看的人少!我觉得
 楼主| 发表于 2010-7-31 09:51:02 | 显示全部楼层
有人看的,但是米人回复啊
发表于 2010-7-31 12:26:02 | 显示全部楼层
这程序是有帮助的
发表于 2010-7-31 12:28:59 | 显示全部楼层
启用外部参数自然就没有窗口弹出,下面是帮助

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2010-7-31 16:37:28 | 显示全部楼层
怎么我保存不了配置信息……
发表于 2010-7-31 17:21:54 | 显示全部楼层
本帖最后由 C.L 于 2010-7-31 17:31 编辑

帮你改了一下,功能改为:
1、第一次运行,会自动按图标生成配置文件“icoSpace.ini",第二次运行,如果检测到有”icoSpace.ini"文件存在,则自动还原桌面图标位置
2、运行程序加参数:xxx.exe /load=icoSpace.ini 会自动读取icoSpace.ini还原桌面图标位置,如果ini文件不存在,则自动创建icoSpace.ini
  运行程序加参数:xxx.exe /save=icoSpace.ini 生成图标位置配置文件icoSpace.ini

代码:
#NoTrayIcon 
#AutoIt3Wrapper_icon=D:\autoit3\Aut2Exe\Icons\FOLDER.ico 
;~ #AutoIt3Wrapper_Compression=4 
#AutoIt3Wrapper_UseAnsi=y 
#AutoIt3Wrapper_Res_Comment=2008-04-19, 23:31 
#AutoIt3Wrapper_Res_Description=桌面图标同步程序 
#AutoIt3Wrapper_Res_Fileversion=1.0.0.1 
#AutoIt3Wrapper_Res_LegalCopyright=Amu 

#include <GuiListView.au3> 
Opt("MustDeclareVars", 1) 
Global $hWndManager = WinGetHandle("Program Manager") 
Global $hWndDesktop = ControlGetHandle("Program Manager","",1) 
If Not IsDeclared("GWL_STYLE") Then Global Const $GWL_STYLE = -16 
Global $LVS_Style = _WinAPI_GetWindowLong($hWndDesktop, $GWL_STYLE) 
Global $inifile, $iSet, $iRefresh, $SNAPTOGRID 

If $CmdLine[0] Then 
     For $i = 1 To $CmdLine[0] 
         Select 
             Case StringRegExp($CmdLine[$i], '^[/-](?i)load[=:].+$|^[/-](?i)l[=:].+$') And Not $inifile         
                 $iSet = 1 
                 $inifile = StringRegExpReplace($CmdLine[$i], '^[/-](?i)load[=:]?|^[/-](?i)l[=:]?', "") 
                 
             Case StringRegExp($CmdLine[$i], '^[/-](?i)save[=:].+$|^[/-](?i)s[=:].+$') And Not $inifile 
                 $iSet = 0 
                 $inifile = StringRegExpReplace($CmdLine[$i], '^[/-](?i)save[=:]?|^[/-](?i)s[=:]?', "") 
                 
             Case StringRegExp($CmdLine[$i], '^[/-](?i)SnapToGrid[=:]\d+$|^[/-](?i)g[=:]\d+$') And $inifile         
                 $SNAPTOGRID = Number (StringRegExpReplace($CmdLine[$i], '^[/-](?i)SnapToGrid[=:]?|^[/-](?i)g[=:]?', "") ) 
                 
             Case StringRegExp($CmdLine[$i], '^[/-](?i)Refresh$|^[/-](?i)r$') 
                 $iRefresh = 1 
                 
             Case StringRegExp($CmdLine[$i], '^[/-](?i)Help$|^[/-](?i)[?h]$') 
                 MsgBox(64,"参数帮助!","AutoIcon.exe [</load|/save>=<file>] [/G=<0|1>] [/R]" & @CRLF & "" & @CRLF & _ 
                     "/load=file 要加载的配置文件。" & @CRLF & "/save=file 要保存的配置文件。" & @CRLF & _ 
                         "/G=<0|1>   为“0”取消图标对齐到网格,为“1”图标对齐到网格,默认不作更改。" & @CRLF & "/R         相当于桌面右键“刷新”") 
                 Exit 
             Case Not $inifile 
                 $inifile = $CmdLine[$i] 
                 If FileExists($inifile) Then $iSet = 1 
         EndSelect     
     Next 
Else 
         $inifile = @ScriptDir &"\icoSpace.ini"
         If FileExists ($inifile) Then
                $iSet = 1 
        Else
                $iSet = 0 
        EndIf
EndIf 

If $iSet Then 
     If $SNAPTOGRID Then $SNAPTOGRID = $LVS_EX_SNAPTOGRID 
     If IsNumber ($SNAPTOGRID) Then _SendMessage($hWndDesktop, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_SNAPTOGRID, $SNAPTOGRID) 
     If BitAND($LVS_Style, $LVS_AUTOARRANGE) Then _WinAPI_SetWindowLong($hWndDesktop, $GWL_STYLE, $LVS_Style - $LVS_AUTOARRANGE );取消自动排列 
     
     If $iRefresh Then DllCall("shell32.dll", "none", "SHChangeNotify", "long", 0x8000000, "int", 0, "ptr", 0, "ptr", 0);刷新图标 
     _SaveAndLoadIconPos($inifile, 1) 
     ;Run("RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters");刷新桌面(通过复制文件的方式替换壁纸文件适用) 
Else 
     _SaveAndLoadIconPos($inifile) 
EndIf 

Func _SaveAndLoadIconPos($iFile, $iLoad = 0) 
     Local $iCount, $iIndex, $sName, $xy     
     If Not IsHWnd($hWndManager) Then $hWndManager = WinGetHandle("Program Manager") 
     If Not IsHWnd($hWndDesktop) Then $hWndDesktop = ControlGetHandle("Program Manager","",1) 
     $iCount = ControlListView($hWndManager, "", $hWndDesktop, "GetItemCount") 
     If @error Then 
         SetError(1) 
         Return 0 
     EndIf 
     If Not $iLoad And FileExists($iFile) Then IniDelete($iFile, "图标位置") 
     For $iIndex = 0 to $iCount - 1 
         $sName = ControlListView($hWndManager, "", $hWndDesktop,"GetText", $iIndex) 
         If $iLoad Then 
             $xy = StringSplit (IniRead ($iFile, "图标位置", $sName, ""), ",") 
             If $xy[0] = 2 Then _ 
             _SendMessage($hWndDesktop, $LVM_SETITEMPOSITION, $iIndex, BitOR(BitShift($xy[2], -16), BitAND($xy[1], 0xffff) ) ) 
         Else;保存图标信息 
             $xy = _GUICtrlListView_GetItemPosition($hWndDesktop, $iIndex) 
             IniWrite($iFile, "图标位置", $sName, $xy[0] & "," & $xy[1] ) 
         EndIf     
     Next 
     Return 1 
EndFunc

评分

参与人数 2威望 +2 金钱 +30 贡献 +10 收起 理由
tianya1631 + 10 + 10 厉害、佩服
afan + 2 + 20

查看全部评分

 楼主| 发表于 2010-8-1 10:16:12 | 显示全部楼层
非常感谢啊,终于等到了,呵呵,我不能加分,不然我一定给你加分,呵呵
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-22 00:59 , Processed in 0.085094 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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