找回密码
 加入
搜索
查看: 2241|回复: 8

如何在选中保存后可将选择结果保存起来,附原码!

[复制链接]
发表于 2009-7-7 11:13:07 | 显示全部楼层 |阅读模式
本帖最后由 hhasee 于 2009-7-8 08:11 编辑

原码如下:所提的问题是:现在我用GuiCtrlSetState将所有的先项全部选中,但有时我只想选中其中的任意项目保存后,再次打开时也只选中我所选中保存的几条,例如我选中2、3两个保存后,关掉再次打开时,也只有2、3两项前面有小勾,其它的都没有!
我的基本思路如下,用一函数读取是否选中,选中的话可用一文本来标示为:test?=1,没选中的就标示为:test?=0,当再次打开此代码时,先选文体里的内容,当标志为1时前面就打勾,0时就不用,所以现在的问题也就挡在了,用什么函数来判断前面是否选中??仅一思路,不知各位大侠有无更好方法?
在线等啊
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <GUIConstants.au3>
#include <Date.au3>
#include <WindowsConstants.au3>
#include <Excel.au3>
#include <EditConstants.au3> 
#include <file.au3>
#include <AVIConstants.au3>
#include <TreeViewConstants.au3>
Opt('MustDeclareVars', 1)

#Region ### START  GUI section ###
    Local $Mac, $tree, $pctest,$btn1,$btn2
    Local $jls=0    
        
        $pctest = GUICreate("示例        ", 200, 300)
                GUICtrlSetState(-1, $Gui_Disable)
                GUICtrlCreateGroup("选中后保存", 40, 75, 105, 220)
                GUICtrlCreateGroup("", 5, 420, 510, 35)
                GUICtrlSetBkColor(-1, 0xf5deb3)
        
                GUISetFont(10, 400, 1)
                $tree =  GuiCtrlCreateTreeView(55, 95, 75, 160, $TVS_CHECKBOXES)
Local $tree1= GuiCtrlCreateTreeViewItem("test1", $tree)
                    GuiCtrlSetState(-1, $GUI_CHECKED)
Local $tree2=GuiCtrlCreateTreeViewItem("test2", $tree)
                    GuiCtrlSetState(-1, $GUI_CHECKED)
Local $tree3= GuiCtrlCreateTreeViewItem("test3", $tree)
        GuiCtrlSetState(-1, $GUI_CHECKED)
Local $tree4=GuiCtrlCreateTreeViewItem("test4", $tree)
        GuiCtrlSetState(-1, $GUI_CHECKED)
Local $tree5=GuiCtrlCreateTreeViewItem("test5", $tree)
        GuiCtrlSetState(-1, $GUI_CHECKED)
Local $tree6=GuiCtrlCreateTreeViewItem("test6", $tree)
        GuiCtrlSetState(-1, $GUI_CHECKED)
Local $tree7=GuiCtrlCreateTreeViewItem("test7", $tree)
        GuiCtrlSetState(-1, $GUI_CHECKED)
Local $tree8=GuiCtrlCreateTreeViewItem("test8", $tree)
                GuiCtrlSetState(-1, $GUI_CHECKED)                
        $btn1 = GUICtrlCreateButton("保存", 45, 260, 45, 25, $BS_DEFPUSHBUTTON)                
        $btn2 = GUICtrlCreateButton("退出", 95, 260, 45, 25)

        GUISetState()
#EndRegion ### end  GUI section ###

;-------------------------------------------------------------------------------------------------------------------------
While 1
        Switch GUIGetMsg()
                Case $GUI_EVENT_CLOSE
                        Exit
        Case $btn1
                       MsgBox(48, "Error!", "按此健后能絋reeView里所选的结果保存吗?")  
        Case $btn2
               ExitLoop
                                
       EndSwitch
WEnd
发表于 2009-7-7 14:41:21 | 显示全部楼层
本帖最后由 大绯狼 于 2009-7-7 15:43 编辑

[au3]#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <GUIConstants.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

#Region ### START  GUI section ###
Local $Mac, $treeview, $pctest, $btn1, $btn2
Local $jls = 0
Local $tree[8]
$pctest = GUICreate("示例        ", 200, 300)
GUICtrlSetState(-1, $Gui_Disable)
GUICtrlCreateGroup("选中后保存", 40, 75, 105, 220)
GUICtrlCreateGroup("", 5, 420, 510, 35)
GUICtrlSetBkColor(-1, 0xf5deb3)
GUISetFont(10, 400, 1)
$treeview = GUICtrlCreateTreeView(55, 95, 75, 160, $TVS_CHECKBOXES)
For $i = 0 To UBound($tree)-1
        $tree[$i] = GUICtrlCreateTreeViewItem("test" & $i+1, $treeview)
        If IniRead("txt.txt", "config", "tree" & $i, 0) = 1 Then
                GUICtrlSetState($tree[$i], $GUI_CHECKED)
        EndIf
Next
$btn1 = GUICtrlCreateButton("保存", 45, 260, 45, 25, $BS_DEFPUSHBUTTON)
$btn2 = GUICtrlCreateButton("退出", 95, 260, 45, 25)

GUISetState()
#EndRegion ### end  GUI section ###

;-------------------------------------------------------------------------------------------------------------------------
While 1
        Switch GUIGetMsg()
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $btn1
                        If MsgBox(4, "提示", "保存吗?") = 6 Then
                                For $i = 0 To UBound($tree)-1
                                        If GUICtrlRead($tree[$i]) = 1 or  GUICtrlRead($tree[$i])=257 Then
                                                IniWrite("txt.txt", "config", "tree" & $i, 1)
                                        Else
                                                IniWrite("txt.txt", "config", "tree" & $i, 0)
                                        EndIf
                                Next
                        EndIf
                Case $btn2
                        ExitLoop
        EndSwitch
WEnd[/au3]
 楼主| 发表于 2009-7-7 14:48:57 | 显示全部楼层
本帖最后由 hhasee 于 2009-7-7 15:22 编辑

基本能搞定,但当我全部选中时发现最后一个保存后再打开,并没有选中,不知是怎么回事?
发表于 2009-7-7 15:21:30 | 显示全部楼层
二楼的貌似还有点小问题吧
运行:(3.3.1.0):C:\autoit3\autoit3.exe "C:\Documents and Settings\Administrator\桌面\选中后保存.au3"    
C:\Documents and Settings\Administrator\??\?????.au3 (20) : ==> ?????????????.:
$tree[$i] = GUICtrlCreateTreeViewItem("test" & $i + 1, $treeview)
^ ERROR
发表于 2009-7-7 15:43:48 | 显示全部楼层
二楼的貌似还有点小问题吧运行:(3.3.1.0):C:\autoit3\autoit3.exe "C:\Documents and Settings\Administrator\桌面\选中后保存.au3"   
C:\Documents and Settings\Administrator\??\?????.au3 (20) : ==> ??????? ...
autoit3CN 发表于 2009-7-7 15:21


不好意思 刚才修改的时候有点错误 已更正
发表于 2009-7-7 15:45:29 | 显示全部楼层
还差一个头文件
#include <TreeViewConstants.au3>
发表于 2009-7-7 15:48:35 | 显示全部楼层
还差一个头文件
#include
autoit3CN 发表于 2009-7-7 15:45


啊。。。。我的老版本不需要这个头
 楼主| 发表于 2009-7-7 16:59:18 | 显示全部楼层
现在就OK了,太感谢了!
发表于 2009-7-13 08:21:16 | 显示全部楼层
顶一下,呵呵
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-5 12:05 , Processed in 0.072949 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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