梦想吧技术论坛's Archiver

似水年华 发表于 2007-4-22 06:30 PM

AU3-自动更换壁纸

#NoTrayIcon
#include <GUIConstants.au3>

Dim $inifile_path=@ScriptDir&"\List.ini"
Dim $bmp
Dim $sTmpFile
Dim $List_I[1]
Dim $Item[1]
Dim $New_ID
Global $sFilename = @ScriptFullPath

If Not FileExists( $inifile_path ) Then
MsgBox(16,"错误!","找不到"&$inifile_path&"程序无法继续!!")
Exit
EndIf

If $CmdLine[0]<=0 Then
setup()
Else
set_b_pic()
EndIf

Func setup()
  Local $L
$Form1 = GUICreate("墙纸列表", 491, 320, 192, 125)
$Input1 = GUICtrlCreateInput("", 40, 8, 273, 21, -1, $WS_EX_CLIENTEDGE)
$Button1 = GUICtrlCreateButton("...", 320, 7, 30, 25)
$Button2 = GUICtrlCreateButton("添加", 355, 7, 38, 25)
$Button3 = GUICtrlCreateButton("修改", 400, 7, 38, 25)
$Button4 = GUICtrlCreateButton("删除", 445, 7, 38, 25)
$ListView1 = GuiCtrlCreateListView("编号|键名|路径", 8, 40, 474, 270)
GUICtrlCreateLabel("路径:", 8, 13, 31, 17)
GUISetState(@SW_SHOW)
Local $List = IniReadSection ($inifile_path,"main")
  If @error Then
  MsgBox(16,"错误!","读取"&$inifile_path&"失败,程序无法继续!!")
  Exit
EndIf
  
For $i=1 To $List[0][0]
  $New_ID=UBound($Item)+1
  ReDim $Item[$New_ID]
  $L=$i
  $Item[$New_ID-1]=GUICtrlCreateListViewItem($i&"|"&$List[$i][0]&"|"&$List[$i][1],$ListView1)
Next

While 1
  $msg = GuiGetMsg()
  
  $sCurFilename = GUICtrlRead($Input1)
  If $sCurFilename <> $sFilename Then
   $iStartIndex = 0
   $sFilename = $sCurFilename
  Endif
  
  Select
   Case $msg = $GUI_EVENT_CLOSE
    ExitLoop
   Case $msg=$Button1
   $sTmpFile = FileOpenDialog("选择图片:", $sFilename, "文件: (*.bmp)")
            If @error Then ContinueLoop
            GUICtrlSetData($Input1, $sTmpFile)
  Case $msg=$Button2
   If $sFilename="" Then
    MsgBox(48,"傻了!!","傻了,你没有输入文件名怎么添加呀?")
   Else
    $New_ID=UBound($Item)+1
    ReDim $Item[$New_ID]
    IniWrite ( $inifile_path, "main",$List[$List[0][0]][0]+1,$sFilename)
    If @error Then
     Exit
    EndIf
    $List = IniReadSection ($inifile_path,"main")
    $L=$L+1
    $Item[$New_ID-1]=GUICtrlCreateListViewItem($New_ID-1&"|"&$List[$List[0][0]][0]&"|"&$List[$List[0][0]][1],$ListView1)
   EndIf
  Case $msg=$Button3
   If $sFilename="" Then
    MsgBox(48,"傻了!!","傻了,你没有输入文件名怎么修改呀?")
   ElseIf GUICtrlRead($ListView1)=0 Then
    MsgBox(48,"傻B!!","傻B你不选择怎么修改?")
   Else
    Local $N=GUICtrlRead($Item[GUICtrlRead($ListView1)-9])
    Local $Temp_A=StringSplit($N,"|")
    IniWrite ( $inifile_path, "main", $Temp_A[2], $sFilename )
    $List = IniReadSection ($inifile_path,"main")
    GuiCtrlSetData($Item[$Temp_A[1]],$Temp_A[1]&"|"&$List[$Temp_A[1]][0]&"|"&$List[$Temp_A[1]][1])
   EndIf
  Case $msg=$Button4
   If GUICtrlRead($ListView1)=0 Then
    MsgBox(48,"傻B!!","傻B你不选择怎么删除呀?")
   Else
    Local $N=GUICtrlRead($Item[GUICtrlRead($ListView1)-9])
    Local $Temp_A=StringSplit($N,"|")
    $List = IniReadSection ($inifile_path,"main")
    If $List[0][0]=1 Then
     MsgBox(48,"警告!!","至少要保留一张墙纸!!")
    Else
     IniDelete($inifile_path,"main",$Temp_A[2])
     GUICtrlDelete($Item[$Temp_A[1]])
    EndIf
   EndIf
  Case Else
  EndSelect
WEnd
EndFunc

Func set_b_pic()
Local $List = IniReadSection ($inifile_path,"main")
  If @error Then
  MsgBox(16,"错误!","读取"&$inifile_path&"失败,程序无法继续!!")
  Exit
EndIf
Local $R = Round (Random ("1",$List[0][0]),0)
If $R=0 Then $R=1
Local $bmp = $List[$R][1]
If FileExists( $bmp ) Then
  dllcall("user32","int","SystemParametersInfo","int",20,"int",1,"str",$bmp,"int",1)
Else
  MsgBox(48,"警告!!","找不到"&$bmp)
EndIf
EndFunc

页: [1]

Powered by Discuz! Archiver 7.0.0  © 2001-2009 Comsenz Inc.