关于水木子GUICtrlCreateList排序功能
本帖最后由 mo_shaojie 于 2010-12-5 10:25 编辑关于你回复的GUICtrlCreateList排序功能时作的代码:#include <GUIListBox.au3>
#include <GuiTreeView.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
$Path = @ScriptDir & '\SWInstall.ini'
$aRegFitem = StringRegExp(FileRead($Path), '\[\d+\]', 3)
$aRegSitem = StringRegExp(FileRead($Path), '\[\d+-\d+\]', 3)
Local $aFitem, $aSitem
Local $sItemText
Local $z = 1, $f = -1, $s = -1
$iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)
GUICreate("TreeView项目勾选操作", 600, 450)
$TreeView1 = GUICtrlCreateTreeView(5, 5, 290, 380, $iStyle, $WS_EX_CLIENTEDGE)
$List1 = GUICtrlCreateList('', 300, 5, 295, 380)
$But1 = GUICtrlCreateButton("读取被选项目", 100, 400, 100, 30, $WS_GROUP)
$But2 = GUICtrlCreateButton("开始模拟安装", 400, 400, 100, 30, $WS_GROUP)
$var = IniReadSectionNames($Path)
If Not @error Then
For $i = 1 To $var
If StringIsDigit($var[$i]) Then
$f += 1
$sFtext = IniRead($Path, $var[$i], 'ParentName', '')
$aFitem[$f] = GUICtrlCreateTreeViewItem($sFtext, $TreeView1)
$aFitem[$f] = $sFtext
Else
$s += 1
$sStext = IniRead($Path, $var[$i], 'ChildName', '')
$aSitem[$s] = GUICtrlCreateTreeViewItem($sStext, $aFitem[$f])
$aSitem[$s] = $sStext
EndIf
Next
EndIf
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case - 3
Exit
Case $aFitem To $aFitem ;父项目
If BitAND(GUICtrlRead($nMsg), $GUI_CHECKED) Then ;如果父项目勾选,其下所有子项目全选。
$iSitemNumber = Number(_GUICtrlTreeView_GetChildCount($TreeView1, $nMsg))
For $i = $nMsg To $nMsg + $iSitemNumber
GUICtrlSetState($i, $GUI_CHECKED)
Next
Else
$iSitemNumber = Number(_GUICtrlTreeView_GetChildCount($TreeView1, $nMsg))
For $i = $nMsg To $nMsg + $iSitemNumber
GUICtrlSetState($i, $GUI_UNCHECKED)
Next
EndIf
ContinueCase
Case $aSitem To $aSitem ;子项目
If BitAND(GUICtrlRead($nMsg), $GUI_CHECKED) Then ;如果子项目勾选,其父项目也跟着勾选。
$hFitemHandle = _GUICtrlTreeView_GetParentParam($TreeView1, $nMsg)
GUICtrlSetState($hFitemHandle, $GUI_CHECKED)
Else ;父项目下的所有子项目全部取消勾选,父项目也跟着取消勾选。
$hFitemHandle = _GUICtrlTreeView_GetParentParam($TreeView1, $nMsg)
$iSitemNumber = Number(_GUICtrlTreeView_GetChildCount($TreeView1, $hFitemHandle))
For $i = $hFitemHandle To $hFitemHandle + $iSitemNumber
If GUICtrlRead($i) = $GUI_CHECKED Then ExitLoop
If $i = $hFitemHandle + $iSitemNumber Then GUICtrlSetState($hFitemHandle, $GUI_UNCHECKED)
Next
EndIf
$x = 1
$sItemText = ''
GUICtrlSetData($List1, '') ;清空List内所有数据
For $i = 0 To UBound($aSitem) - 1
If _GUICtrlTreeView_GetChecked($TreeView1, $aSitem[$i]) Then
GUICtrlSetData($List1, StringFormat("[%02d]", $x) & $aSitem[$i]) ;如果项目被勾选则写入List
$sItemText &= $aSitem[$i] & '|'
$x += 1
EndIf
Next
Case $But1
$sText = ''
For $i = 0 To UBound($aSitem) - 1
If _GUICtrlTreeView_GetChecked($TreeView1, $aSitem[$i]) Then
$sText &= '被选项目句柄:' & $aSitem[$i] & ' ' & '项目文本:' & $aSitem[$i] & @CRLF
EndIf
Next
If $sText <> '' Then MsgBox(0, '获取被选项目句柄+项目文本', $sText)
Case $But2
begin()
EndSwitch
WEnd
Func begin()
$aLines = StringSplit($sItemText, '|', 2)
For $i = 0 To UBound($aLines) - 1
_GUICtrlListBox_ReplaceString($List1, $i, '[→]' & $aLines[$i])
_GUICtrlListBox_SetCurSel($List1, $i)
Sleep(800)
_GUICtrlListBox_ReplaceString($List1, $i, '' & $aLines[$i])
_GUICtrlListBox_SetCurSel($List1, $i)
Next
MsgBox(0, '', '安装完成!')
EndFunc ;==>begin将它换成GUICtrlCreateListView,要改变的代码怎么改了?多谢!
如:$List1 = GUICtrlCreateListView("序号|信息", 300, 5, 295, 380).
而不是$List1 = GUICtrlCreateList('', 300, 5, 295, 380)
上传配置文件了. 没有SWInstall.ini文件,没法帮你看了 没有SWInstall.ini文件,没法帮你看了
yhxhappy 发表于 2010-12-4 21:12 http://www.autoitx.com/images/common/back.gif
已经上传.多谢! 本帖最后由 yhxhappy 于 2010-12-4 22:51 编辑
大概改了一下,楼主改成ListView是明智的,看起来没那么挤,美观一些。如果要美化的话还可以把安装时的箭头换成图标#include <GUIListBox.au3>
#include <GuiTreeView.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
$Path = @ScriptDir & '\SWInstall.ini'
$aRegFitem = StringRegExp(FileRead($Path), '\[\d+\]', 3)
$aRegSitem = StringRegExp(FileRead($Path), '\[\d+-\d+\]', 3)
Local $aFitem, $aSitem
Local $sItemText
Local $z = 1, $f = -1, $s = -1
$iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)
GUICreate("TreeView项目勾选操作", 600, 450)
$TreeView1 = GUICtrlCreateTreeView(5, 5, 290, 380, $iStyle, $WS_EX_CLIENTEDGE)
$List1 = GUICtrlCreateListView("", 300, 5, 295, 380)
_GUICtrlListView_AddColumn($List1, "序号", 50)
_GUICtrlListView_AddColumn($List1, "信息", 230)
$But1 = GUICtrlCreateButton("读取被选项目", 100, 400, 100, 30, $WS_GROUP)
$But2 = GUICtrlCreateButton("开始模拟安装", 400, 400, 100, 30, $WS_GROUP)
$var = IniReadSectionNames($Path)
If Not @error Then
For $i = 1 To $var
If StringIsDigit($var[$i]) Then
$f += 1
$sFtext = IniRead($Path, $var[$i], 'ParentName', '')
$aFitem[$f] = GUICtrlCreateTreeViewItem($sFtext, $TreeView1)
$aFitem[$f] = $sFtext
Else
$s += 1
$sStext = IniRead($Path, $var[$i], 'ChildName', '')
$aSitem[$s] = GUICtrlCreateTreeViewItem($sStext, $aFitem[$f])
$aSitem[$s] = $sStext
EndIf
Next
EndIf
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case - 3
Exit
Case $aFitem To $aFitem ;父项目
If BitAND(GUICtrlRead($nMsg), $GUI_CHECKED) Then ;如果父项目勾选,其下所有子项目全选。
$iSitemNumber = Number(_GUICtrlTreeView_GetChildCount($TreeView1, $nMsg))
For $i = $nMsg To $nMsg + $iSitemNumber
GUICtrlSetState($i, $GUI_CHECKED)
Next
Else
$iSitemNumber = Number(_GUICtrlTreeView_GetChildCount($TreeView1, $nMsg))
For $i = $nMsg To $nMsg + $iSitemNumber
GUICtrlSetState($i, $GUI_UNCHECKED)
Next
EndIf
ContinueCase
Case $aSitem To $aSitem ;子项目
If BitAND(GUICtrlRead($nMsg), $GUI_CHECKED) Then ;如果子项目勾选,其父项目也跟着勾选。
$hFitemHandle = _GUICtrlTreeView_GetParentParam($TreeView1, $nMsg)
GUICtrlSetState($hFitemHandle, $GUI_CHECKED)
Else ;父项目下的所有子项目全部取消勾选,父项目也跟着取消勾选。
$hFitemHandle = _GUICtrlTreeView_GetParentParam($TreeView1, $nMsg)
$iSitemNumber = Number(_GUICtrlTreeView_GetChildCount($TreeView1, $hFitemHandle))
For $i = $hFitemHandle To $hFitemHandle + $iSitemNumber
If GUICtrlRead($i) = $GUI_CHECKED Then ExitLoop
If $i = $hFitemHandle + $iSitemNumber Then GUICtrlSetState($hFitemHandle, $GUI_UNCHECKED)
Next
EndIf
$x = 1
$sItemText = ''
_GUICtrlListView_DeleteAllItems($List1) ;清空List内所有数据
For $i = 0 To UBound($aSitem) - 1
If _GUICtrlTreeView_GetChecked($TreeView1, $aSitem[$i]) Then
GUICtrlCreateListViewItem(StringFormat("[%02d]", _GUICtrlListView_GetItemCount($List1)+1) & "|" & $aSitem[$i], $List1) ;如果项目被勾选则写入List
$sItemText &= $aSitem[$i] & '|'
$x += 1
EndIf
Next
Case $But1
$sText = ''
For $i = 0 To UBound($aSitem) - 1
If _GUICtrlTreeView_GetChecked($TreeView1, $aSitem[$i]) Then
$sText &= '被选项目句柄:' & $aSitem[$i] & ' ' & '项目文本:' & $aSitem[$i] & @CRLF
EndIf
Next
If $sText <> '' Then MsgBox(0, '获取被选项目句柄+项目文本', $sText)
Case $But2
begin()
EndSwitch
WEnd
Func begin()
$aLines = StringSplit($sItemText, '|', 2)
GUICtrlSetState ($List1, $GUI_FOCUS) ;此处要将焦点设置在 $List1 ,否则被选项的背景是灰的,不是蓝色
For $i = 0 To UBound($aLines) - 1
_GUICtrlListView_SetItemText($List1, $i, '[→]')
_GUICtrlListView_SetItemSelected($List1, $i)
Sleep(800)
_GUICtrlListView_SetItemText($List1, $i, '')
_GUICtrlListView_SetItemSelected($List1, $i, False)
Next
MsgBox(0, '', '安装完成!')
EndFunc ;==>begin 大概改了一下,楼主改成ListView是明智的,看起来没那么挤,美观一些。如果要美化的话还可以把安装时的箭头 ...
yhxhappy 发表于 2010-12-4 22:30 http://www.autoitx.com/images/common/back.gif
试下把勾去掉了,会是怎么回事呢?右边窗口显示的没去掉,反而却多两项了.就是重复了. 那个箭头换什么图标好看? 不好意思,弄错了.OK了 怎么不能自动勾选的? 自动勾选是什么意思?我试运行新旧两个,除了表不同,没感觉什么不同啊 自动勾选是什么意思?我试运行新旧两个,除了表不同,没感觉什么不同啊
yhxhappy 发表于 2010-12-4 23:51 http://www.autoitx.com/images/common/back.gif
自动勾选就是左则的有勾显示,现在的没有啊.
还有的就是如果读取ini文件=后面多双引号"",如:ParentName="压缩解压",怎么可以读取到呢? 自动勾选,你的意思就是代码一运行就默认把左侧的项全选中?
ParentName='"压缩解压"' 自动勾选,你的意思就是代码一运行就默认把左侧的项全选中?
ParentName='"压缩解压"'
yhxhappy 发表于 2010-12-5 00:17 http://www.autoitx.com/images/common/back.gif
是啊,一运行就选上.
那个ini文件有双引号怎么读取呢 ParentName=' "压缩解压" ',注意看哦,带了一个单引号#include <GUIListBox.au3>
#include <GuiTreeView.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
$Path = @ScriptDir & '\SWInstall.ini'
$aRegFitem = StringRegExp(FileRead($Path), '\[\d+\]', 3)
$aRegSitem = StringRegExp(FileRead($Path), '\[\d+-\d+\]', 3)
Local $aFitem, $aSitem
Local $sItemText
Local $z = 1, $f = -1, $s = -1
$iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)
GUICreate("TreeView项目勾选操作", 600, 450)
$TreeView1 = GUICtrlCreateTreeView(5, 5, 290, 380, $iStyle, $WS_EX_CLIENTEDGE)
$List1 = GUICtrlCreateListView("", 300, 5, 295, 380)
_GUICtrlListView_AddColumn($List1, "序号", 50)
_GUICtrlListView_AddColumn($List1, "信息", 230)
$But1 = GUICtrlCreateButton("读取被选项目", 100, 400, 100, 30, $WS_GROUP)
$But2 = GUICtrlCreateButton("开始模拟安装", 400, 400, 100, 30, $WS_GROUP)
$var = IniReadSectionNames($Path)
If Not @error Then
For $i = 1 To $var
If StringIsDigit($var[$i]) Then
$f += 1
$sFtext = IniRead($Path, $var[$i], 'ParentName', '')
$aFitem[$f] = GUICtrlCreateTreeViewItem($sFtext, $TreeView1)
GUICtrlSetState(-1, $GUI_CHECKED)
$aFitem[$f] = $sFtext
Else
$s += 1
$sStext = IniRead($Path, $var[$i], 'ChildName', '')
$aSitem[$s] = GUICtrlCreateTreeViewItem($sStext, $aFitem[$f])
GUICtrlSetState(-1, $GUI_CHECKED)
$aSitem[$s] = $sStext
EndIf
Next
EndIf
AddItem()
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case - 3
Exit
Case $aFitem To $aFitem ;父项目
If BitAND(GUICtrlRead($nMsg), $GUI_CHECKED) Then ;如果父项目勾选,其下所有子项目全选。
$iSitemNumber = Number(_GUICtrlTreeView_GetChildCount($TreeView1, $nMsg))
For $i = $nMsg To $nMsg + $iSitemNumber
GUICtrlSetState($i, $GUI_CHECKED)
Next
Else
$iSitemNumber = Number(_GUICtrlTreeView_GetChildCount($TreeView1, $nMsg))
For $i = $nMsg To $nMsg + $iSitemNumber
GUICtrlSetState($i, $GUI_UNCHECKED)
Next
EndIf
ContinueCase
Case $aSitem To $aSitem ;子项目
If BitAND(GUICtrlRead($nMsg), $GUI_CHECKED) Then ;如果子项目勾选,其父项目也跟着勾选。
$hFitemHandle = _GUICtrlTreeView_GetParentParam($TreeView1, $nMsg)
GUICtrlSetState($hFitemHandle, $GUI_CHECKED)
Else ;父项目下的所有子项目全部取消勾选,父项目也跟着取消勾选。
$hFitemHandle = _GUICtrlTreeView_GetParentParam($TreeView1, $nMsg)
$iSitemNumber = Number(_GUICtrlTreeView_GetChildCount($TreeView1, $hFitemHandle))
For $i = $hFitemHandle To $hFitemHandle + $iSitemNumber
If GUICtrlRead($i) = $GUI_CHECKED Then ExitLoop
If $i = $hFitemHandle + $iSitemNumber Then GUICtrlSetState($hFitemHandle, $GUI_UNCHECKED)
Next
EndIf
AddItem()
Case $But1
$sText = ''
For $i = 0 To UBound($aSitem) - 1
If _GUICtrlTreeView_GetChecked($TreeView1, $aSitem[$i]) Then
$sText &= '被选项目句柄:' & $aSitem[$i] & ' ' & '项目文本:' & $aSitem[$i] & @CRLF
EndIf
Next
If $sText <> '' Then MsgBox(0, '获取被选项目句柄+项目文本', $sText)
Case $But2
begin()
EndSwitch
WEnd
Func AddItem()
$x = 1
$sItemText = ''
_GUICtrlListView_DeleteAllItems($List1) ;清空List内所有数据
For $i = 0 To UBound($aSitem) - 1
If _GUICtrlTreeView_GetChecked($TreeView1, $aSitem[$i]) Then
GUICtrlCreateListViewItem(StringFormat("[%02d]", _GUICtrlListView_GetItemCount($List1)+1) & "|" & $aSitem[$i], $List1) ;如果项目被勾选则写入List
$sItemText &= $aSitem[$i] & '|'
$x += 1
EndIf
Next
EndFunc
Func begin()
$aLines = StringSplit($sItemText, '|', 2)
GUICtrlSetState ($List1, $GUI_FOCUS) ;此处要将焦点设置在 $List1 ,否则被选项的背景是灰的,不是蓝色
For $i = 0 To UBound($aLines) - 1
_GUICtrlListView_SetItemText($List1, $i, '[→]')
_GUICtrlListView_SetItemSelected($List1, $i)
Sleep(800)
_GUICtrlListView_SetItemText($List1, $i, '')
_GUICtrlListView_SetItemSelected($List1, $i, False)
Next
MsgBox(0, '', '安装完成!')
EndFunc ;==>begin 回复 13# yhxhappy
请不要回复标题违规的帖子。
论坛发帖规则:http://www.autoitx.com/thread-10945-1-1.html 刚刚没找到如何重新开启被关闭的帖子,终于找到了,已经将帖子重新开启了。