hhasee 发表于 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 ### STARTGUI 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 ### endGUI 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 编辑

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

Opt('MustDeclareVars', 1)

#Region ### STARTGUI section ###
Local $Mac, $treeview, $pctest, $btn1, $btn2
Local $jls = 0
Local $tree
$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 ### endGUI 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 orGUICtrlRead($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

hhasee 发表于 2009-7-7 14:48:57

本帖最后由 hhasee 于 2009-7-7 15:22 编辑

基本能搞定,但当我全部选中时发现最后一个保存后再打开,并没有选中,不知是怎么回事?

autoit3CN 发表于 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 http://autoitx.com/images/common/back.gif

不好意思 刚才修改的时候有点错误 已更正

autoit3CN 发表于 2009-7-7 15:45:29

还差一个头文件
#include <TreeViewConstants.au3>

大绯狼 发表于 2009-7-7 15:48:35

还差一个头文件
#include
autoit3CN 发表于 2009-7-7 15:45 http://autoitx.com/images/common/back.gif

啊。。。。我的老版本不需要这个头

hhasee 发表于 2009-7-7 16:59:18

:face (33):现在就OK了,太感谢了!

My2009 发表于 2009-7-13 08:21:16

顶一下,呵呵
页: [1]
查看完整版本: 如何在选中保存后可将选择结果保存起来,附原码!