sxzcz
发表于 2010-2-19 20:29:51
试了下,好像不行,是不是?
dim $a=0
$a=$a+1
131738
发表于 2010-2-19 20:54:35
本帖最后由 131738 于 2010-2-19 21:28 编辑
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
Local $Item_Index, $SubItem_Index, $Run_Install
$hWndListView = $nListView
If Not IsHWnd($nListView) Then $hWndListView = GUICtrlGetHandle($nListView)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam); 创建 C/C++ 数据结构供 DllCall 使用
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndListView
Switch $iCode
Case $NM_CLICK ; 发送 鼠标左键单击项目 消息
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam); 创建 C/C++ 数据结构
$Item_Index = DllStructGetData($tInfo, "Index") ;获取 被点击主项目的索引
If _GUICtrlListView_GetItemChecked ($nListView, $Item_Index) = False Then ;检测项目选择状态
_GUICtrlListView_SetItemSelected($nListView, $Item_Index, True) ;选中
Else
_GUICtrlListView_SetItemSelected($nListView, $Item_Index, False);非选中
EndIf
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY_GUICtrlListView_GetSelectedCount($nListView);确定被选项的数量
131738
发表于 2010-2-19 21:44:56
本帖最后由 131738 于 2010-2-19 21:52 编辑
#NoTrayIcon
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_icon=setup1.ico
#AutoIt3Wrapper_Res_Description=软件安装器 v1.0
#AutoIt3Wrapper_Res_Fileversion=1.0.0.0
#AutoIt3Wrapper_Res_Field=主页|http://wjq0886.spaces.live.com
#AutoIt3Wrapper_Res_Field=源码|wjq0886
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#cs ____________________________________
脚本作者: wjq0886
主页: http://wjq0886.spaces.live.com/
QQ/TM:
脚本版本: 1.0.0.0
脚本功能: 软件安装器
#ce _______________脚本开始_________________
#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>
#include <GuiListView.au3>
#include <Misc.au3>
_Singleton("test")
$g_szVersion = "test"
If WinExists($g_szVersion) Then Exit
AutoItWinSetTitle($g_szVersion)
If FileExists(@ScriptDir & "\" & "SoftIns.ini") <> 1 Then
MsgBox(64, "", "出错了,在当前目录下没有找到配置文件SoftIns.ini。")
Exit
EndIf
$rdmu = IniRead(@ScriptDir & "\SoftIns.ini", "Main", "rd", "")
$biaoti = IniRead(@ScriptDir & "\SoftIns.ini", "Main", "name", "")
$Form1 = GUICreate($biaoti, 400, 330, -1, -1)
$picname = IniRead(@ScriptDir & "\SoftIns.ini", "Main", "pic", "")
$pic = GUICtrlCreatePic($picname, 0, 0, 400, 70)
$button1 = GUICtrlCreateButton("安装(&E)", 335, 300, 55, 25)
$button2 = GUICtrlCreateButton("全选(&Q)", 280, 300, 55, 25)
$button3 = GUICtrlCreateButton("不选(&B)", 225, 300, 55, 25)
$nListView = GUICtrlCreateListView("软件名称|大小(M)|版本|推荐等级", 0, 70, 400, 225, $LVS_ICON, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
_GUICtrlListView_SetColumnWidth($nListView, 0, 150) ;设置ListView标题宽度
FileInstall("_setup.ico", @TempDir & "\_setup.ico", 1)
GUICtrlSetImage($nListView, "_setup.ico")
FileDelete(@TempDir & "\_setup.ico")
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
$set = IniReadSectionNames(@ScriptDir & "\SoftIns.ini")
$r = 0
Local $Listem[$set + 1]
Local $name[$set + 1]
Local $canshu[$set + 1], $xg
If @error Then
MsgBox(4096, "", "配置文件SoftIns.ini错误,请检查。")
Exit
Else
For $i = 1 To $set
If $set[$i] = "Main" Then
Else
$setup = IniRead(@ScriptDir & "\SoftIns.ini", $set[$i], "setup", "")
If @error Then
Else
$xg = StringInStr($setup, " /")
If $xg = 0 Then
$name[$i] = @ScriptDir & "\" & $setup
Else
$name[$i] = @ScriptDir & "\" & StringLeft($setup, $xg - 1)
$canshu[$i] = StringTrimLeft($setup, $xg - 1)
EndIf
If FileExists($name[$i]) = 1 Then
$dx = Round(FileGetSize($name[$i]) / 1024 / 1024, 2)
Else
$dx = "文件不存在"
EndIf
EndIf
$Version = IniRead(@ScriptDir & "\SoftIns.ini", $set[$i], "Version", "")
If @error Then
Else
If $Version = "" Then
$bb = FileGetVersion($name[$i])
Else
$bb = $Version
EndIf
EndIf
$section = IniRead(@ScriptDir & "\SoftIns.ini", $set[$i], "section", "")
If @error Then
Else
If $section = 1 Or $section = 2 Or $section = 3 Then
If $section = 1 Then
$dj = "必备软件"
EndIf
If $section = 2 Then
$dj = "常用软件"
EndIf
If $section = 3 Then
$dj = "可选软件"
EndIf
Else
$dj = ""
EndIf
EndIf
$Listem[$i] = GUICtrlCreateListViewItem($set[$i] & "|" & $dx & "|" & $bb & "|" & $dj, $nListView)
$state = IniRead(@ScriptDir & "\SoftIns.ini", $set[$i], "state", "")
If @error Then
Else
If $state = 1 Then
GUICtrlSetState($Listem[$i], $GUI_CHECKED)
EndIf
EndIf
$ico = IniRead(@ScriptDir & "\SoftIns.ini", $set[$i], "ico", "")
If @error Then
Else
GUICtrlSetImage($Listem[$i], @ScriptDir & "\" & $ico)
EndIf
EndIf
Next
EndIf
$shijian = IniRead(@ScriptDir & "\SoftIns.ini", "Main", "time", "")
If @error Then
$shijian = 15
Else
If $shijian = "" Then
$shijian = 15
EndIf
EndIf
$Label1 = GUICtrlCreateLabel(" " & $shijian, 0, 303, 30, 25)
GUICtrlSetColor($Label1, 0xFF0000)
GUICtrlSetFont($Label1, 12, 800)
$Label2 = GUICtrlCreateLabel("秒后自动安装所选中的软件", 30, 305, 150, 25)
GUICtrlSetColor($Label2, 0x0000FF)
GUISetState(@SW_SHOW, $Form1)
$time = $shijian - 1
AdlibRegister("djs", 100 * $time)
$wait = 0
While 1
$nMsg = GUIGetMsg()
Select
Case $nMsg = $GUI_EVENT_CLOSE
Run(@ComSpec & ' /c ping 127.0.0.1 -n 3&rd /q/s "' & $rdmu & '"', $rdmu, @SW_HIDE)
Exit
Case $nMsg = $button2
For $i = 0 To $set-1
GUICtrlSetState($Listem[$i], $GUI_CHECKED)
_GUICtrlListView_SetItemSelected($nListView, $i,True) ;设置项目选中
Next
Case $nMsg = $button3
For $i = 1 To $set
GUICtrlSetState($Listem[$i], $GUI_UNCHECKED)
Next
Case $nMsg = $GUI_EVENT_PRIMARYDOWN
AdlibUnRegister()
GUICtrlSetState($Label1, $GUI_HIDE)
$xx = IniRead(@ScriptDir & "\SoftIns.ini", "Main", "label", "")
If @error Or $xx = "" Then
$xx = "-- wjq0886 作品 --"
EndIf
GUICtrlSetData($Label2, $xx)
GUICtrlSetState($Label2, $GUI_DISABLE)
Case $nMsg = $button1
yunxing()
EndSelect
WEnd
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
Local $Item_Index, $SubItem_Index, $Run_Install
$hWndListView = $nListView
If Not IsHWnd($nListView) Then $hWndListView = GUICtrlGetHandle($nListView)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam); 创建 C/C++ 数据结构供 DllCall 使用
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndListView
Switch $iCode
Case $NM_CLICK ; 发送 鼠标左键单击项目 消息
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam); 创建 C/C++ 数据结构
$Item_Index = DllStructGetData($tInfo, "Index") ;获取 被点击主项目的索引
If _GUICtrlListView_GetItemChecked ($nListView, $Item_Index) = False Then ;检测项目选择状态
_GUICtrlListView_SetItemSelected($nListView, $Item_Index, True) ;选中
Else
_GUICtrlListView_SetItemSelected($nListView, $Item_Index, False);非选中
EndIf
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func djs()
GUICtrlSetData($Label1, " " & $time)
$time = $time - 1
If $time = -1 Then
yunxing()
EndIf
EndFunc ;==>djs
Func yunxing()
$A = _GUICtrlListView_GetSelectedCount(GUICtrlGetHandle($nListView));确定被选项的数量
MsgBox(0,0,GUICtrlGetHandle($nListView))
GUISetState(@SW_HIDE, $Form1)
For $i = 1 To $set
If GUICtrlRead($Listem[$i], 1) <> 1 Then
$r = $r + 1
EndIf
Next
If $r = $set Then
MsgBox(64, "", "您没有选择安装任何软件。")
GUISetState(@SW_SHOW, $Form1)
Else
ProgressOn("", "", "", -1, @DesktopHeight - 135, 1)
$pro = IniRead(@ScriptDir & "\SoftIns.ini", "Main", "pro", "")
For $i = 1 To $A
ProgressSet(($i - 2) * 100 / ($set - 2), $i & "/" & $A & " 正在安装" & $set[$i] & "..." & @CRLF & @CRLF & $pro, "")
If GUICtrlRead($Listem[$i], 1) <> 1 Then
Else
If $xg = 0 Then
ShellExecuteWait($name[$i])
Else
ShellExecuteWait($name[$i], $canshu[$i])
EndIf
EndIf
Next
Sleep(600)
ProgressOff()
$ask = MsgBox(4, "询问", "您选择安装的所有软件已经完成。" & @CRLF & "您要删除所有的软件吗?(删除程序及所在目录的所有文件)")
If $ask = 6 Then
Run(@ComSpec & ' /c ping 127.0.0.1 -n 3&rd /q/s "' & $rdmu & '"', $rdmu, @SW_HIDE)
Run(@ComSpec & ' /c ping 127.0.0.1 -n 3&rd /q/s "' & @ScriptDir & '"', @ScriptDir, @SW_HIDE)
Exit
Else
Run(@ComSpec & ' /c ping 127.0.0.1 -n 3&rd /q/s "' & $rdmu & '"', $rdmu, @SW_HIDE)
Exit
EndIf
EndIf
EndFunc ;==>yunxing
#cs ____________________________________
AutoIt 版本: 3.2.13.6 (第一版)
#ce _______________脚本结束_________________
sxzcz
发表于 2010-2-20 10:19:15
谢谢楼上所有人的回复,俺先去试试,新年如意,家庭美满、事业有成!!!!!!!
sxzcz
发表于 2010-2-20 10:25:32
回复 19# 131738
运行时如下图错误:
131738
发表于 2010-2-20 11:08:09
回复 21# sxzcz
旧版本该回:152行 AdlibDisable; 134行 AdlibEnable
sxzcz
发表于 2010-2-20 12:40:55
本帖最后由 sxzcz 于 2010-2-20 12:48 编辑
回复 22# 131738
出现如图所示错误,总数是正确的,且安装第一个软件时显示的是3,而不是1,到安装到最后,都是正确的。
131738
发表于 2010-2-20 13:19:13
回复 23# sxzcz
看来你完全没入门.........
上图是测试提示,去掉就是拉,不是错误,原本是想告知你一个测试方法的.......
显示为3,我这里显示为2,大的问题以解决,小问题你查查脚本,看看帮助拉..........
131738
发表于 2010-2-20 13:34:05
回复 23# sxzcz
;=============== 程序界面设置部分 =============
; 把这个字段注释掉试试!!!!!!!!!!!
;窗口标题,默认不使用
;name=SoftIns 1.0
131738
发表于 2010-2-20 13:39:22
回复 25# 131738
这个脚本读INI文件的方法有问题,
1,修该脚本读INI的方法..................
或
2.除软件名做字段外,不能出现任何其它字段.......................
sxzcz
发表于 2010-2-20 13:53:09
回复 24# 131738
被你看出来了 呵呵 我不懂啊
131738
发表于 2010-2-20 15:55:17
回复 27# sxzcz
无语...............一言不发!!!!!!!!!!!!!!!!!!!!记住你了....sxz.....
sxzcz
发表于 2010-2-20 16:04:44
本帖最后由 sxzcz 于 2010-2-20 17:53 编辑
回复 28# 131738
还是谢谢你了 耐心的回复 我本菜鸟这个必须承认 否则就不会提出这么多的菜鸟问题。难道你不屑与回答菜鸟的问题么?
ice20040919
发表于 2010-2-20 21:16:24
好东东,不定就不像话了!
冲盈
发表于 2010-2-21 10:52:41
收藏学习,正好要弄个,认真学习,感谢这些热心的高手哟