找回密码
 加入
搜索
楼主: jinhao

[GUI管理] _GUICtrlTreeView和_GUICtrlListBox问题(已解决)

 火.. [复制链接]
 楼主| 发表于 2010-2-18 17:00:50 | 显示全部楼层
UDF函数经常出现对中文支持不好,容易乱码!我遇到好几次。
水木子 发表于 2010-2-12 23:03
#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GuiConstantsEx.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
#include <GUIListBox.au3>

;Opt('MustDeclareVars', 1)

$Debug_TV = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work

Global $hTreeView, $List1

_Main()

Func _Main()
        Global $hItem, $hImage, $iImage, $hTreeView,$nMsg,$dll
        Global $GUI, $hItem,$Child0,$Child1,$Child2,$Child3,$Child4,$Child5,$Child6,$Child7,$hItem0,$hItem1
        Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)
        $GUI = GUICreate("(UDF Created) TreeView Create", 400, 540)

        $hTreeView = _GUICtrlTreeView_Create($GUI, 2, 2, 396, 268, $iStyle, $WS_EX_CLIENTEDGE)
        $List1 = GUICtrlCreateList("", 2, 277, 394, 268)
        GUISetState()

        GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

        _GUICtrlTreeView_BeginUpdate($hTreeView)
   $hItem0 = _GUICtrlTreeView_Add($hTreeView, 0, "soft1", 1, 1)
   $Child0=_GUICtrlTreeView_AddChild($hTreeView,$hItem0,StringFormat("%02d : Random string",0), 1, 1)
   $Child1=_GUICtrlTreeView_AddChild($hTreeView,$hItem0,StringFormat("%02d : Random string",1), 1, 1)
   $Child2=_GUICtrlTreeView_AddChild($hTreeView,$hItem0,StringFormat("%02d : Random string",2), 1, 1)
   $Child3=_GUICtrlTreeView_AddChild($hTreeView,$hItem0,StringFormat("%02d : Random string",3), 1, 1)

   $hItem1 = _GUICtrlTreeView_Add($hTreeView, 0, "soft2", 1, 1)
   $Child4=_GUICtrlTreeView_AddChild($hTreeView,$hItem1,StringFormat("%02d : Random string",4), 1, 1)
   $Child5=_GUICtrlTreeView_AddChild($hTreeView,$hItem1,StringFormat("%02d : Random string",5), 1, 1)
   $Child6=_GUICtrlTreeView_AddChild($hTreeView,$hItem1,StringFormat("%02d : Random string",6), 1, 1)
   $Child7=_GUICtrlTreeView_AddChild($hTreeView,$hItem1,StringFormat("%02d : Random string",7), 1, 1)
        _GUICtrlTreeView_EndUpdate($hTreeView)

        ; Loop until user exits
        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE
        GUIDelete()
EndFunc   ;==>_Main

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
        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
                                        For $i = 0 To 7
                                                If _GUICtrlTreeView_GetChecked($hTreeView,Eval("Child"&$i)) Then
                                                        _GUICtrlListBox_InsertString($List1,'准备安装:'&StringFormat("%02d : Random string",$i),$i)
                                                Else
                                                        _GUICtrlListBox_DeleteString($List1, $i)
                                                EndIf
                                Next
                        EndSwitch
        EndSwitch
        Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
你给我的例子我只能改成这样了,如何让已加到GUICtrlCreateList的数据不再重复添加,和判断没有选择时在GUICtrlCreateList删除相应项?
发表于 2010-2-20 13:34:11 | 显示全部楼层
本帖最后由 水木子 于 2010-2-20 13:59 编辑

TreeView To List 有点乱,将就着看吧!
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>

Global $sa, $txit
$iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)
$hGUI = GUICreate("_GUICtrlTreeView To _GUICtrlListBox", 500, 300)
$TreeView1 = GUICtrlCreateTreeView(2, 2, 200, 282, $iStyle, $WS_EX_CLIENTEDGE)
$hListBox1 = GUICtrlCreateList("", 208, 2, 290, 288)
GUISetState(@SW_SHOW)

$Item1 = GUICtrlCreateTreeViewItem('软件分类1', $TreeView1)
$Item2 = GUICtrlCreateTreeViewItem('软件分类2', $TreeView1)
For $Item = 1 To 5
        GUICtrlCreateTreeViewItem('软件1-' & $Item, $Item1)
        GUICtrlCreateTreeViewItem('软件2-' & $Item, $Item2)
Next

While 1
        $all = _GUICtrlTreeView_GetCount($TreeView1)
        For $i = 1 To $all + 5
                $Check = _GUICtrlTreeView_GetChecked($TreeView1, $i)
                If $Check = True Then
                        $txit &= _GUICtrlTreeView_GetText($TreeView1, $i) & '|'
                EndIf
        Next

        If $txit <> $sa Then
                $z = 1
                GUICtrlSetData($hListBox1, '')
                $che = StringSplit($txit, '|')
                For $x = 2 To $che[0]
                        GUICtrlSetData($hListBox1, StringFormat("[%02d]", $z) & ' 准备安装 ' & $che[$x - 1])
                        $z += 1
                Next
                $sa = $txit
        EndIf
        $txit = ''

        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case - 3
                        Exit

        EndSwitch
WEnd

评分

参与人数 1金钱 +20 收起 理由
jinhao + 20 辛苦了

查看全部评分

发表于 2010-3-24 22:14:41 | 显示全部楼层
回复 17# 水木子
#         $all = _GUICtrlTreeView_GetCount($TreeView1)
#         For $i = 1 To $all + 5
#                 $Check = _GUICtrlTreeView_GetChecked($TreeView1, $i)
#                 If $Check = True Then
#                         $txit &= _GUICtrlTreeView_GetText($TreeView1, $i) & '|'
#                 EndIf
#         Next
为什么要$all+5呢?
另外$i是项目句柄吗?
发表于 2010-4-12 11:28:41 | 显示全部楼层
学习了,标记后用。
发表于 2011-12-17 22:59:13 | 显示全部楼层
代码很好,收下了
发表于 2013-8-13 19:04:20 | 显示全部楼层
会报错哟,,
发表于 2014-2-16 21:44:25 | 显示全部楼层
回复 17# 水木子
收下了,多谢啦!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-17 04:23 , Processed in 0.094828 second(s), 15 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表