ListView中checkbox的选择与执行其功能?
本帖最后由 pdp320921 于 2011-3-24 23:00 编辑问题如题目所示~~
http://autoitx.com/forum.php?mod=viewthread&tid=6161&extra=&highlight=%BF%D8%D6%C6%C3%E6%B0%E5&page=2#NoTrayIcon
#include <GuiListView.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
DIM $_REG,$_REG_DP="DisplayName",$_REG_DI="DisplayIcon",$_REG_US="UninstallString",$X=0
DIM $_REG_String="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
$GUI=GUICreate("添加删除程序",820,400,-1,-1)
$Label_01=GUICtrlCreateLabel("添加删除程序",10,20,800,40,0x01)
$Button_01=GUICtrlCreateButton("卸载",10,370,150,20)
$Button_02=GUICtrlCreateButton("退出",660,370,150,20)
$Lv=GUICtrlGetHandle(GUICtrlCreateListView("",10,50,800,315, BitOR($LVS_REPORT,$LVS_SHOWSELALWAYS),$WS_EX_CLIENTEDGE))
_GUICtrlListView_SetExtendedListViewStyle($Lv,BitOR($LVS_EX_GRIDLINES,$LVS_EX_FULLROWSELECT,$LVS_EX_SUBITEMIMAGES,$LVS_EX_CHECKBOXES))
_GUICtrlListView_AddColumn($Lv, "", 40)
_GUICtrlListView_AddColumn($Lv, "列表",400)
_GUICtrlListView_AddColumn($Lv, "路径",355)
GUICtrlSetBkColor($Label_01, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetOnEvent($Button_01,"_Uninstall")
GUICtrlSetOnEvent($Button_02,"_EXIT")
GUISetOnEvent($GUI_EVENT_CLOSE,"_EXIT")
GUISetOnEvent($GUI_EVENT_MINIMIZE,"_MINIMIZE")
GUISetOnEvent($GUI_EVENT_RESTORE,"_RESTORE")
GUISetState()
for $i=1 to 1000
$_REG=RegEnumKey($_REG_String,$i)
If @error <> 0 then ExitLoop
if RegRead($_REG_String&$_REG,$_REG_DP)="" OR StringLeft($_REG,1)="{" Then
Else
_GUICtrlListView_AddItem($Lv,$x+1,$x)
_GUICtrlListView_AddSubItem($Lv,$x,RegRead($_REG_String&$_REG,$_REG_DP),1)
_GUICtrlListView_AddSubItem($Lv,$x,RegRead($_REG_String&$_REG,$_REG_US),2)
$x=$x+1
EndIf
Next
While 1
sleep(10)
WEnd
func _EXIT()
Exit
EndFunc
func _MINIMIZE()
GUISetState(@SW_MINIMIZE)
EndFunc
func _RESTORE()
GUISetState(@SW_RESTORE)
EndFunc
func _Uninstall()
$s = 0
$log = _GUICtrlListView_GetItemCount($Lv)
For $i = 0 To $log
If _GUICtrlListView_GetItemChecked($Lv, $i) = True Then
$s += 1
;_Guictrllistview_setitemselected($Lv, $i)
MsgBox(0, '', '你选择了第' & $i + 1 & '个项目')
;Run (_GUICtrlListView_AddSubItem($Lv,$x,RegRead($_REG_String&$_REG,$_REG_US),2))
EndIf
Next
MsgBox(0, '', '你选择了' & $s & '个项目,' & $log - $s & '个项目没有选择')
EndFunc我想在源代码基础上添加checkbox栏,可以选择单个或同时选择多个checkbox,然后去卸载~,可是在 If _GUICtrlListView_GetItemChecked($Lv, $i) = True Then
Run()?这里Run()不知怎么提取Uninstall string的值了?请高手指点 把代码格式整理好告诉你 回复 2# netegg
大侠,我问题描述的应该还算清楚吧,代码也不是我自己写的,我只是在别人基础上添加checkbox,却不知如何当选中checkbox时,提取uninstall string而实现其功能~~
关键就在Run(),括号里的内容不知如何写~~ $text=_GUICtrlListView_GetItemTextArray ($Lv, $i)
run($text)
....
If _GUICtrlListView_GetItemChecked($Lv, $i) = True Then
_Guictrllistview_setitemselected($Lv, $i)
$s += 1
MsgBox(0, '', '你选择了第' & $i + 1 & '个项目')
Run (_GUICtrlListView_AddSubItem($Lv,$x,RegRead($_REG_String&$_REG,$_REG_US),2))
.....
自己解决了.
_Guictrllistview_setitemselected($Lv, $i)这句让checkbox的选择跟setitemselected关联起来了,使得只要选中checkbox就会选中该列item
可是问题又来了,我如何选中几个checkbox,可以一个接着一个去自动卸载呢?GUICtrlSetOnEvent($Button_01,"_Uninstall")
这个函数调用是当选中几个checkbox几乎是同时卸载,我想一个一个的去卸载,不知如何完成?? 哎,AU3语言太牛X,看不懂 一个一个卸载改成 Runwait就可以了。 回复 7# 小A
刚想到,回去试试~~~ 试了,好像还是不行,Run()和Runwait()运行的结果一样,只能去侦测到第一个被选中的checkbox,而不会去侦测到后面被选中的checkbox所执行的代码。
还有就是如果没有勾选checkbox,只是setitemselected,却依然能够执行所选中的items的代码,这又是为何??大侠们请帮忙赐教~~ 回复 4# netegg
谢谢前辈的指点,起初没仔细看,问题差不多解决了
谢谢~ 本帖最后由 netegg 于 2011-3-28 23:05 编辑
回复 9# pdp320921
for $i = 1 to totalnumber
if.....getchecked() thendo
next 回复 11# netegg #NoTrayIcon
#include <GuiListView.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
DIM $_REG,$_REG_DP="DisplayName",$_REG_DI="DisplayIcon",$_REG_US="UninstallString",$X=0
DIM $_REG_String="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
$GUI=GUICreate("添加删除程序",820,400,-1,-1)
$Label_01=GUICtrlCreateLabel("添加删除程序",10,20,800,40,0x01)
$Button_01=GUICtrlCreateButton("卸载",10,370,150,20)
$Button_02=GUICtrlCreateButton("退出",660,370,150,20)
$Lv=GUICtrlGetHandle(GUICtrlCreateListView("",10,50,800,315, BitOR($LVS_REPORT,$LVS_SHOWSELALWAYS),$WS_EX_CLIENTEDGE))
_GUICtrlListView_SetExtendedListViewStyle($Lv,BitOR($LVS_EX_GRIDLINES,$LVS_EX_FULLROWSELECT,$LVS_EX_SUBITEMIMAGES,$LVS_EX_CHECKBOXES))
_GUICtrlListView_AddColumn($Lv, "", 40)
_GUICtrlListView_AddColumn($Lv, "列表",400)
_GUICtrlListView_AddColumn($Lv, "路径",355)
_GUICtrlListView_AddColumn($Lv, "n", 20)
GUICtrlSetBkColor($Label_01, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetOnEvent($Button_01,"_Uninstall")
GUICtrlSetOnEvent($Button_02,"_EXIT")
GUISetOnEvent($GUI_EVENT_CLOSE,"_EXIT")
GUISetOnEvent($GUI_EVENT_MINIMIZE,"_MINIMIZE")
GUISetOnEvent($GUI_EVENT_RESTORE,"_RESTORE")
GUISetState()
GUISetState(@SW_SHOW)
for $i=1 to 1000
$_REG=RegEnumKey($_REG_String,$i)
If @error <> 0 then ExitLoop
if RegRead($_REG_String&$_REG,$_REG_DP)=""Then
Else
_GUICtrlListView_AddItem($Lv,$x+1,$x)
_GUICtrlListView_AddSubItem($Lv,$x,RegRead($_REG_String&$_REG,$_REG_DP),1)
_GUICtrlListView_AddSubItem($Lv,$x,RegRead($_REG_String&$_REG,$_REG_US),2)
$x=$x+1
EndIf
Next
While 1
sleep(10)
WEnd
func _EXIT()
Exit
EndFunc
func _MINIMIZE()
GUISetState(@SW_MINIMIZE)
EndFunc
func _RESTORE()
GUISetState(@SW_RESTORE)
EndFunc
func _Uninstall()
$log = _GUICtrlListView_GetItemCount($Lv)
For $i = 0 To $log
If _GUICtrlListView_GetItemChecked($Lv, $i) = True Then
_GUICtrlListView_SetItemSelected($Lv,$i,True,True)
Run(_GUICtrlListView_GetItemText($Lv,$i,2))
;choice()
Else
_GUICtrlListView_SetItemSelected($Lv,$i,False,False)
EndIf
Next
EndFunc整理下代码后,我想让程序能够自动去卸载,把所有需要卸载的程序监视了一遍,写成choice()但不知如何判断
不知如何实现,用Switch...Case...EndSwitch不知怎么用?大虾们帮下忙啊~~ 本帖最后由 netegg 于 2011-3-29 12:48 编辑
你到底是想自动运行还是要操作运行,为什么总是跟select(switch)过不去.如果死活想用,告诉你,代码长不长或者好不好调试自己去想
$i =1
while not ($i>_guictrllistview_getcount())
switch $i
case _guictrlllistview_getchecked()
run()
endswitch
$i +=1
wend 回复 13# netegg
其实我只是想:在选中相应的checkbox再点击卸载按钮后能够完成自动完成卸载~~,也不是非要select或什么的,只要能达到效果即可~恳请前辈指点! 本帖最后由 netegg 于 2011-3-29 13:35 编辑
回复 14# pdp320921
那就用上面那段好了,卸载按钮的操作
$i =1
while not ($i>_guictrllistview_getcount())
if _guictrlllistview_getchecked() thenrun()
$i +=1
wend
页:
[1]
2