(已解决)选择父选框时选择上对应下面的子选框问题之父选框都没有真正完全列举出来!
本帖最后由 yarsye 于 2011-1-4 13:05 编辑想法:把遍历到的文件夹和文件的句柄全部写到ini文件里,然后通过读取ini文件里的句柄去执行选择父选框同时让子选框也选上,现在打开ini文件发现里面文件夹都没有全部列举完,换成句柄肯定也不对,所以问题还是在这里 !找了半天 又陷入了沉思。。。#include <GuiConstantsEx.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <file.au3>
#include <array.au3>
Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)
Global $array1, $array2, $array3, $inipath, $inivalue, $readini
$inipath = @DesktopDir & '\test.ini'
$inivalue = ''
$GUI = GUICreate("(UDF Created) TreeView Create", 400, 640)
$hTreeView = GUICtrlCreateTreeView(2, 2, 396, 568, $iStyle, $WS_EX_CLIENTEDGE)
Recursion(@AppDataCommonDir', '')
GUISetState()
$readini = IniReadSection($inipath , 'section2');store folders
If @error Then
MsgBox(4096, "", "错误, 不是 INI 文静.")
Else
For $k = 1 To $readini
Dim $newarray
Next
EndIf
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case - 3
Exit
Case $readini To $readini ;父项目
If BitAND(GUICtrlRead($nMsg), $GUI_CHECKED) Then ;如果父项目勾选,其下所有子项目全选。
MsgBox(0,1,1)
;~ $iSitemNumber = Number(_GUICtrlTreeView_GetChildCount($item1, $nMsg))
;~ For $i = $nMsg To $nMsg + $iSitemNumber
;~ GUICtrlSetState($i, $GUI_CHECKED)
;~ Next
;~ Else
;~ $iSitemNumber = Number(_GUICtrlTreeView_GetChildCount($item1, $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 Recursion($current, $flag)
Local $i = 0, $j = 0
If Not FileExists($inipath) Then
IniWrite($inipath, 'section', 'key', 1)
$inivalue = IniRead($inipath, 'section', 'key', '')
Else
$inivalue = IniRead($inipath, 'section', 'key', '')
$inivalue += 1
IniWrite($inipath, 'section', 'key', $inivalue)
$inivalue = IniRead($inipath, 'section', 'key', '')
EndIf
If $flag = '' Then $item1 = GUICtrlCreateTreeViewItem($current, $hTreeView)
Local $search = FileFindFirstFile($current & "\*.*")
While 1
Dim $file = FileFindNextFile($search)
If @error Or StringLen($file) < 1 Then ExitLoop
If StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then
If $flag <> '' Then $item1 = $flag
$item2 = GUICtrlCreateTreeViewItem($file, $item1)
$i +=1
IniWrite($inipath, 'section2', 'key' & $i, $file );$item2 );$array2[$i]);store folders
Recursion($current & "\" & $file, $item2)
Else
If $flag <> '' Then $item1 = $flag
$item3 = GUICtrlCreateTreeViewItem($file, $item1)
$j += 1
IniWrite($inipath, 'section1', 'key' & $j, $file ) ;$item3 ) ;$array3[$j]);store files
EndIf
WEnd
Return
EndFunc ;==>Recursion 在点击的那个条件里加上子项循环设置(不)选中状态 自己写个点击后的判断 回复 3# 飘云
这样可以加吗?#include <GuiConstantsEx.au3>
#include <GuiTreeView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <file.au3>
#include <array.au3>
Global$iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)
;~ Global $item1 = ''
$GUI = GUICreate("(UDF Created) TreeView Create", 400, 640)
$hTreeView = _GUICtrlTreeView_Create($GUI, 2, 2, 396, 568,$iStyle, $WS_EX_CLIENTEDGE)
$hImage = _GUIImageList_Create(16, 16, 5, 3)
_GUIImageList_AddIcon($hImage, "shell32.dll", 4)
_GUICtrlTreeView_SetNormalImageList($hTreeView, $hImage)
_GUICtrlTreeView_BeginUpdate($hTreeView)
Recursion(@AppDataCommonDir,'')
_GUICtrlTreeView_EndUpdate($hTreeView)
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While 1
$msg = GUIGetMsg()
If $msg = -3 Then ExitLoop
;~ If $msg = _GUICtrlTreeView_GetChecked($hTreeView,$item1) Then MsgBox(0,1,1)
WEnd
;~ _GUICtrlTreeView_SetChecked($hTreeView,$item1)
;~ Do
;~ Until GUIGetMsg() = -3
Func Recursion($current,$flag)
If $flag = '' Then $item1 = _GUICtrlTreeView_Add($hTreeView,0,$current,$hImage,$hImage)
Local $search = FileFindFirstFile($current & "\*.*")
While 1
Dim $file = FileFindNextFile($search)
If @error Or StringLen($file) < 1 Then ExitLoop
If StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then
If $flag <> '' Then $item1 = $flag
$item2 = _GUICtrlTreeView_AddChild($hTreeView,$item1,$file);,$hImage,$hImage)
Recursion($current & "\" & $file,$item2)
Else
If $flag <> '' Then $item1 = $flag
$item3 = _GUICtrlTreeView_AddChild($hTreeView,$item1,$file,$hImage,$hImage)
EndIf
WEnd
Return
EndFunc ;==>Search
Func MY_WM($hWnd, $Msg, $wParam, $lParam)
Local $tNMHdr = DllStructCreate($tagNMHDR, $lParam), $tNM_TREEVIEW
Local $hWndFrom = DllStructGetData($tNMHdr, 'hWndFrom')
Local $iIDFrom= DllStructGetData($tNMHdr, 'IDFrom')
Local $iCode = DllStructGetData($tNMHdr, 'Code')
If $iIDFrom = $hTreeView Then
Switch $iCode
Case $TVN_SELCHANGEDA, $TVN_SELCHANGEDW
;~ If GUICtrlRead($hTreeView) > 0 Then _
MsgBox(0, 0, 'ID: ' & GUICtrlRead($hTreeView) & @CRLF & 'Text: ' & GUICtrlRead($hTreeView, 1))
EndSwitch
EndIf
Return $GUI_RUNDEFMSG
EndFunc ;==>_OnNotify
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview
$hWndTreeview = $hTreeView
If Not IsHWnd($hTreeView) Then $hWndTreeview = GUICtrlGetHandle($hTreeView)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndTreeview
Switch $iCode
Case $NM_CLICK ; 控件失去输入焦点
;~ MsgBox(0,1, 1);_GUICtrlTreeView_GetChecked($hTreeView,$item1))
;~ memowrite("$NM_CLICK" & @LF)
;~ memowrite("-->hWndFrom:" & @TAB & $hWndFrom & @LF)
;~ memowrite("-->IDFrom:" & @TAB & $iIDFrom & @LF)
;~ memowrite("-->Code:" & @TAB & $iCode)
; 无返回值
;~ Return 1 ; 非0为不允许默认操作
Return 0 ; 0 为允许默认操作
Case $NM_DBLCLK ; 用户在控件内双击鼠标左键
;~ memowrite("$NM_DBLCLK" & @LF)
;~ memowrite("-->hWndFrom:" & @TAB & $hWndFrom & @LF)
;~ memowrite("-->IDFrom:" & @TAB & $iIDFrom & @LF)
;~ memowrite("-->Code:" & @TAB & $iCode)
;~ Return 1 ; 非0为不允许默认操作
Return 0 ; 0 为允许默认操作
Case $NM_RCLICK ; 用户在控件内点击鼠标右键
;~ memowrite("$NM_RCLICK" & @LF)
;~ memowrite("-->hWndFrom:" & @TAB & $hWndFrom & @LF)
;~ memowrite("-->IDFrom:" & @TAB & $iIDFrom & @LF)
;~ memowrite("-->Code:" & @TAB & $iCode)
;~ Return 1 ; 非0为不允许默认操作
Return 0 ; 0 为允许默认操作
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func memowrite($s_text)
;~ GUICtrlSetData($edit, $s_text & @CRLF, 1)
MsgBox(0,123,$s_text & @CRLF ,5)
EndFunc ;==>memowrite
遍历所有子选项并勾上 回复 5# auto
悲剧的是我连父文件夹句柄都搞不定了 楼主,可以参考下我的帖子.
http://www.autoitx.com/thread-20199-1-1.html 回复 7# mo_shaojie
学习了 谢谢
页:
[1]