找回密码
 加入
搜索
查看: 3435|回复: 0

[GUI管理] 不同的GUICtrlCreateListView 点击事件

[复制链接]
发表于 2015-3-7 16:33:07 | 显示全部楼层 |阅读模式
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <GuiListView.au3>
#include <Array.au3>
Global $Form1, $Tab1, $TabSheet1, $TabSheet2, $TabSheet3, $TabSheet4, $TabSheet5
Global $ListView1, $ListView2, $ListView3, $ListView4, $ListView5
Global $Button1, $Button2, $Button3, $Button4, $Button5, $Button6, $Button7, $Button8, $Button9, $Button10
Global $tianjia1, $tianjia2, $tianjia3, $tianjia4, $tianjia5, $files_name, $files_dir, $tmp
Global $lujing = @DesktopDir & "\笑话\短信"
Global $lujing2 = @DesktopDir & "\笑话\问候"
Global $lujing3 = @DesktopDir & "\笑话\经典"
Global $lujing4 = @DesktopDir & "\笑话\案例"
Global $lujing5 = @DesktopDir & "\笑话\等等"
Global $cishu, $cishu2, $cishu3, $cishu4, $cishu5
_maingui()
Func _maingui()
        $Form1 = GUICreate("Form1", 1152, 702, 160, 80)
        $Tab1 = GUICtrlCreateTab(24, 40, 1105, 601)
        _duanxin()
        _wenhou()
        _jindian()
        _anlie()
        _dengdeng()
        GUISetState(@SW_SHOW)
        _GUICloseEvent()
EndFunc   ;==>_maingui

Func _duanxin()
        If $TabSheet1 <= 0 Then
                $TabSheet1 = GUICtrlCreateTabItem("短信")
                $ListView1 = GUICtrlCreateListView("序号|文章", 64, 88, 1026, 470, -1, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES))
        EndIf
        _GUICtrlListView_DeleteAllItems($ListView1)
        GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
        GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 50)
        GUICtrlDelete($Button1)
        $Button1 = GUICtrlCreateButton("添加", 368, 585, 121, 39)
        GUICtrlDelete($Button2)
        $Button2 = GUICtrlCreateButton("生成", 568, 585, 121, 39)
        Local $aFileList = _FileListToArray("D:\短信", "*")
        Local $iRows = UBound($aFileList)
        For $i = 1 To $iRows - 1 Step 1
                Local $idItem = GUICtrlCreateListViewItem($i & "|" & $aFileList[$i], $ListView1)
        Next
EndFunc   ;==>_duanxin

Func _wenhou()
        If $TabSheet2 <= 0 Then
                $TabSheet2 = GUICtrlCreateTabItem("问候")
                $ListView2 = GUICtrlCreateListView("序号|文章", 64, 88, 1026, 470, -1, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES))
        EndIf
        _GUICtrlListView_DeleteAllItems($ListView2)
        GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
        GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 50)
        GUICtrlDelete($Button3)
        $Button3 = GUICtrlCreateButton("添加", 368, 585, 121, 39)
        GUICtrlDelete($Button4)
        $Button4 = GUICtrlCreateButton("生成", 568, 585, 121, 39)
        Local $aFileList = _FileListToArray("D:\问候", "*")
        Local $iRows = UBound($aFileList)
        For $i = 1 To $iRows - 1 Step 1
                Local $idItem = GUICtrlCreateListViewItem($i & "|" & $aFileList[$i], $ListView2)
        Next
EndFunc   ;==>_wenhou

Func _jindian()
        If $TabSheet3 <= 0 Then
                $TabSheet3 = GUICtrlCreateTabItem("经典")
                $ListView3 = GUICtrlCreateListView("序号|文章", 64, 88, 1026, 470, -1, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES))
        EndIf
        _GUICtrlListView_DeleteAllItems($ListView3)
        GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
        GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 50)
        GUICtrlDelete($Button5)
        $Button5 = GUICtrlCreateButton("添加", 368, 585, 121, 39)
        GUICtrlDelete($Button6)
        $Button6 = GUICtrlCreateButton("生成", 568, 585, 121, 39)
        Local $aFileList = _FileListToArray("D:\经典", "*")
        Local $iRows = UBound($aFileList)
        For $i = 1 To $iRows - 1 Step 1
                Local $idItem = GUICtrlCreateListViewItem($i & "|" & $aFileList[$i], $ListView3)
        Next
EndFunc   ;==>_jindian

Func _anlie()
        If $TabSheet4 <= 0 Then
                $TabSheet4 = GUICtrlCreateTabItem("案列")
                $ListView4 = GUICtrlCreateListView("序号|文章", 64, 88, 1026, 470, -1, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES))
        EndIf
        _GUICtrlListView_DeleteAllItems($ListView4)
        GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
        GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 50)
        GUICtrlDelete($Button7)
        $Button7 = GUICtrlCreateButton("添加", 368, 585, 121, 39)
        GUICtrlDelete($Button8)
        $Button8 = GUICtrlCreateButton("生成", 568, 585, 121, 39)
        Local $aFileList = _FileListToArray("D:\案例", "*")
        Local $iRows = UBound($aFileList)
        For $i = 1 To $iRows - 1 Step 1
                Local $idItem = GUICtrlCreateListViewItem($i & "|" & $aFileList[$i], $ListView4)
        Next
EndFunc   ;==>_anlie

Func _dengdeng()
        If $TabSheet5 <= 0 Then
                $TabSheet5 = GUICtrlCreateTabItem("等等")
                $ListView5 = GUICtrlCreateListView("序号|文章", 64, 88, 1026, 470, -1, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES))
        EndIf
        _GUICtrlListView_DeleteAllItems($ListView5)
        GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
        GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 50)
        GUICtrlDelete($Button9)
        $Button9 = GUICtrlCreateButton("添加", 368, 585, 121, 39)
        GUICtrlDelete($Button10)
        $Button10 = GUICtrlCreateButton("生成", 568, 585, 121, 39)
        Local $aFileList = _FileListToArray("D:\等等", "*")
        Local $iRows = UBound($aFileList)
        For $i = 1 To $iRows - 1 Step 1
                Local $idItem = GUICtrlCreateListViewItem($i & "|" & $aFileList[$i], $ListView5)
        Next
EndFunc   ;==>_dengdeng

Func _button1()
        
        If FileExists("D:\短信") = 0 Then
                DirCreate("D:\短信")
        EndIf
        $tianjia1 = FileOpenDialog("选择你要添加的文件", @DesktopDir, "(*.txt)", 1 + 2 + 4)
        If @error Then Return
        Local $a = StringInStr($tianjia1, "|")
        If $a = 0 Then
                FileCopy($tianjia1, "D:\短信", 1 + 8)
                _duanxin()
        Else
                
                $a = StringSplit($tianjia1, "|", 2)
                For $i = 1 To UBound($a) - 1
                        FileCopy($a[0] & "" & $a[$i], 'D:\短信', 1 + 8)
                        Local $jiancha = FileExists($a[0] & "" & $a[$i])
                        _duanxin()
                Next
        EndIf

EndFunc   ;==>_button1

Func _button2()
        
        If FileExists(@DesktopDir & "\零时.txt") = 1 Then
                FileDelete(@DesktopDir & "\零时.txt")
        EndIf
        Local $aFileList = _FileListToArray("D:\短信", "*")
        Local $iRows = UBound($aFileList)
        For $i = 1 To $iRows - 1 Step 1
                $aa = FileOpen("D:\短信" & $aFileList[$i])
;~
                
                FileWrite(@DesktopDir & "\零时.txt", FileRead($aa))
                
                If FileExists(@DesktopDir & "\零时.txt") = 1 Then
                        FileClose($aa)
                EndIf
        Next
        
        Local $aLine = StringRegExp(FileRead('零时.txt'), '\V+', 3)
        If @error Then
                MsgBox(64, "错误", "错误")
                Return
        EndIf
        
        Local $iC = UBound($aLine) - 1, $i, $iRd, $vTmp

        For $i = 0 To $iC
                $iRd = Random($i, $iC, 1) ;随机产生浮点数
                $vTmp = $aLine[$i]
                $aLine[$i] = $aLine[$iRd]
                $aLine[$iRd] = $vTmp
        Next

        For $i = 1 To $iC
                FileWrite($lujing & "" & @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & ".txt", $aLine[$i - 1] & @CRLF)
        Next
        FileDelete('零时.txt')
        
EndFunc   ;==>_button2

Func _button3()
        
        If FileExists("D:\问候") = 0 Then
                DirCreate("D:\问候")
        EndIf
        $tianjia2 = FileOpenDialog("选择你要添加的文件", @DesktopDir, "(*.txt)", 1 + 2 + 4)
        If @error Then Return
        Local $a = StringInStr($tianjia2, "|")
        If $a = 0 Then
                FileCopy($tianjia2, "D:\问候", 1 + 8)
                _duanxin()
        Else
                
                $a = StringSplit($tianjia2, "|", 2)
                For $i = 1 To UBound($a) - 1
                        FileCopy($a[0] & "" & $a[$i], 'D:\问候', 1 + 8)
                        Local $jiancha = FileExists($a[0] & "" & $a[$i])
                        _wenhou()
                Next
        EndIf
        
EndFunc   ;==>_button3

Func _button4()
        
        If FileExists(@DesktopDir & "\零时.txt") = 1 Then
                FileDelete(@DesktopDir & "\零时.txt")
        EndIf
        Local $aFileList = _FileListToArray("D:\问候", "*")
        Local $iRows = UBound($aFileList)
        For $i = 1 To $iRows - 1 Step 1
                $aa = FileOpen("D:\问候" & $aFileList[$i])
;~
                
                FileWrite(@DesktopDir & "\零时.txt", FileRead($aa))
                
                If FileExists(@DesktopDir & "\零时.txt") = 1 Then
                        FileClose($aa)
                EndIf
        Next
        
        Local $aLine = StringRegExp(FileRead('零时.txt'), '\V+', 3)
        If @error Then
                MsgBox(64, "错误", "错误")
                Return
        EndIf
        Local $iC = UBound($aLine) - 1, $i, $iRd, $vTmp

        For $i = 0 To $iC
                $iRd = Random($i, $iC, 1) ;随机产生浮点数
                $vTmp = $aLine[$i]
                $aLine[$i] = $aLine[$iRd]
                $aLine[$iRd] = $vTmp
        Next

        For $i = 1 To $iC
                FileWrite($lujing2 & "" & @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & ".txt", $aLine[$i - 1] & @CRLF)
        Next
        FileDelete('零时.txt')
        
EndFunc   ;==>_button4

Func _button5()
        
        If FileExists("D:\经典") = 0 Then
                DirCreate("D:\经典")
        EndIf
        $tianjia3 = FileOpenDialog("选择你要添加的文件", @DesktopDir, "(*.txt)", 1 + 2 + 4)
        If @error Then Return
        Local $a = StringInStr($tianjia3, "|")
        If $a = 0 Then
                FileCopy($tianjia3, "D:\经典", 1 + 8)
                _jindian()
        Else
                
                $a = StringSplit($tianjia3, "|", 2)
                For $i = 1 To UBound($a) - 1
                        FileCopy($a[0] & "" & $a[$i], 'D:\经典', 1 + 8)
                        Local $jiancha = FileExists($a[0] & "" & $a[$i])
                        _jindian()
                Next
        EndIf
        
EndFunc   ;==>_button5

Func _button6()
        
        If FileExists(@DesktopDir & "\零时.txt") = 1 Then
                FileDelete(@DesktopDir & "\零时.txt")
        EndIf
        Local $aFileList = _FileListToArray("D:\经典", "*")
        Local $iRows = UBound($aFileList)
        For $i = 1 To $iRows - 1 Step 1
                $aa = FileOpen("D:\经典" & $aFileList[$i])
;~
                
                FileWrite(@DesktopDir & "\零时.txt", FileRead($aa))
                
                If FileExists(@DesktopDir & "\零时.txt") = 1 Then
                        FileClose($aa)
                EndIf
        Next
        
        Local $aLine = StringRegExp(FileRead('零时.txt'), '\V+', 3)
        If @error Then
                MsgBox(64, "错误", "错误")
                Return
        EndIf
        Local $iC = UBound($aLine) - 1, $i, $iRd, $vTmp

        For $i = 0 To $iC
                $iRd = Random($i, $iC, 1) ;随机产生浮点数
                $vTmp = $aLine[$i]
                $aLine[$i] = $aLine[$iRd]
                $aLine[$iRd] = $vTmp
        Next

        For $i = 1 To $iC
                FileWrite($lujing3 & "" & @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & ".txt", $aLine[$i - 1] & @CRLF)
        Next
        FileDelete('零时.txt')
        
EndFunc   ;==>_button6

Func _button7()
        
        If FileExists("D:\案例") = 0 Then
                DirCreate("D:\案例")
        EndIf
        $tianjia4 = FileOpenDialog("选择你要添加的文件", @DesktopDir, "(*.txt)", 1 + 2 + 4)
        If @error Then Return
        Local $a = StringInStr($tianjia4, "|")
        If $a = 0 Then
                FileCopy($tianjia4, "D:\案例", 1 + 8)
                _anlie()
        Else
                
                $a = StringSplit($tianjia4, "|", 2)
                For $i = 1 To UBound($a) - 1
                        FileCopy($a[0] & "" & $a[$i], 'D:\案例', 1 + 8)
                        Local $jiancha = FileExists($a[0] & "" & $a[$i])
                        _anlie()
                Next
        EndIf
        
EndFunc   ;==>_button7

Func _button8()
        
        If FileExists(@DesktopDir & "\零时.txt") = 1 Then
                FileDelete(@DesktopDir & "\零时.txt")
        EndIf
        Local $aFileList = _FileListToArray("D:\案例", "*")
        Local $iRows = UBound($aFileList)
        For $i = 1 To $iRows - 1 Step 1
                $aa = FileOpen("D:\案例" & $aFileList[$i])
;~
                
                FileWrite(@DesktopDir & "\零时.txt", FileRead($aa))
                
                If FileExists(@DesktopDir & "\零时.txt") = 1 Then
                        FileClose($aa)
                EndIf
        Next
        
        Local $aLine = StringRegExp(FileRead('零时.txt'), '\V+', 3)
        If @error Then
                MsgBox(64, "错误", "错误")
                Return
        EndIf
        Local $iC = UBound($aLine) - 1, $i, $iRd, $vTmp

        For $i = 0 To $iC
                $iRd = Random($i, $iC, 1) ;随机产生浮点数
                $vTmp = $aLine[$i]
                $aLine[$i] = $aLine[$iRd]
                $aLine[$iRd] = $vTmp
        Next

        For $i = 1 To $iC
                FileWrite($lujing4 & "" & @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & ".txt", $aLine[$i - 1] & @CRLF)
        Next
        FileDelete('零时.txt')
        
EndFunc   ;==>_button8

Func _button9()
        
        If FileExists("D:\等等") = 0 Then
                DirCreate("D:\等等")
        EndIf
        $tianjia5 = FileOpenDialog("选择你要添加的文件", @DesktopDir, "(*.txt)", 1 + 2 + 4)
        If @error Then Return
        Local $a = StringInStr($tianjia5, "|")
        If $a = 0 Then
                FileCopy($tianjia5, "D:\等等", 1 + 8)
                _dengdeng()
        Else
                
                $a = StringSplit($tianjia5, "|", 2)
                For $i = 1 To UBound($a) - 1
                        FileCopy($a[0] & "" & $a[$i], 'D:\等等', 1 + 8)
                        Local $jiancha = FileExists($a[0] & "" & $a[$i])
                        _dengdeng()
                Next
        EndIf
        
EndFunc   ;==>_button9

Func _button10()
        
        If FileExists(@DesktopDir & "\零时.txt") = 1 Then
                FileDelete(@DesktopDir & "\零时.txt")
        EndIf
        Local $aFileList = _FileListToArray("D:\等等", "*")
        Local $iRows = UBound($aFileList)
        For $i = 1 To $iRows - 1 Step 1
                $aa = FileOpen("D:\等等" & $aFileList[$i])
;~
                
                FileWrite(@DesktopDir & "\零时.txt", FileRead($aa))
                
                If FileExists(@DesktopDir & "\零时.txt") = 1 Then
                        FileClose($aa)
                EndIf
        Next
        
        Local $aLine = StringRegExp(FileRead('零时.txt'), '\V+', 3)
        If @error Then
                MsgBox(64, "错误", "错误")
                Return
        EndIf
        Local $iC = UBound($aLine) - 1, $i, $iRd, $vTmp

        For $i = 0 To $iC
                $iRd = Random($i, $iC, 1) ;随机产生浮点数
                $vTmp = $aLine[$i]
                $aLine[$i] = $aLine[$iRd]
                $aLine[$iRd] = $vTmp
        Next

        For $i = 1 To $iC
                FileWrite($lujing5 & "" & @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & ".txt", $aLine[$i - 1] & @CRLF)
        Next
        FileDelete('零时.txt')
        
EndFunc   ;==>_button10

Func _GUICloseEvent()
        Local $aMsg = 0
        While 1
                $aMsg = GUIGetMsg(1)
                Switch $aMsg[1]
                        Case $Form1
                                Switch $aMsg[0]
                                        
                                        Case $GUI_EVENT_CLOSE
                                                FileDelete(@DesktopDir & "\零时.txt")
                                                ExitLoop
                                        Case $Button1
                                                _button1()
                                        Case $Button2
                                                If FileExists($lujing) = 0 Then
                                                        DirCreate($lujing)
                                                EndIf
;~                                                 ConsoleWrite($lujing)
                                                $cishu = InputBox("请输入数字", "输入要生成文章的数量")
                                                Local $ddd = StringIsDigit($cishu)
                                                If $ddd = 0 Then
                                                        MsgBox(64, "错误", "请输入正确的数字")
                                                        Return
                                                EndIf
                                                
                                                Do
                                                        _button2()
                                                        Local $a = _FileListToArray($lujing)
                                                        Local $b = UBound($a) - 1
                                                        Sleep(1000)
                                                Until $b = $cishu
                                                MsgBox(0, "ok", "生成完毕")

                                        Case $Button3
                                                _button3()
                                        Case $Button4
                                                If FileExists($lujing2) = 0 Then
                                                        DirCreate($lujing2)
                                                EndIf
                                                $cishu2 = InputBox("请输入数字", "输入要生成文章的数量")
                                                Local $ddd = StringIsDigit($cishu2)
                                                If $ddd = 0 Then
                                                        MsgBox(64, "错误", "请输入正确的数字")
                                                        Return
                                                EndIf

                                                Do
                                                        _button4()
                                                        Local $a = _FileListToArray($lujing2)
                                                        Local $b = UBound($a) - 1
                                                        Sleep(1000)
                                                Until $b = $cishu2
                                                MsgBox(0, "ok", "生成完毕")
                                                
                                        Case $Button5
                                                _button5()
                                        Case $Button6
                                                If FileExists($lujing3) = 0 Then
                                                        DirCreate($lujing3)
                                                EndIf
                                                $cishu3 = InputBox("请输入数字", "输入要生成文章的数量")
                                                Local $ddd = StringIsDigit($cishu3)
                                                If $ddd = 0 Then
                                                        MsgBox(64, "错误", "请输入正确的数字")
                                                        Return
                                                EndIf
                                                
                                                Do
                                                        _button6()
                                                        Local $a = _FileListToArray($lujing3)
                                                        Local $b = UBound($a) - 1
                                                        Sleep(1000)
                                                Until $b = $cishu3
                                                MsgBox(0, "ok", "生成完毕")
                                        Case $Button7
                                                _button7()
                                        Case $Button8
                                                $cishu4 = InputBox("请输入数字", "输入要生成文章的数量")
                                                Local $ddd = StringIsDigit($cishu4)
                                                If $ddd = 0 Then
                                                        MsgBox(64, "错误", "请输入正确的数字")
                                                        Return
                                                EndIf
                                                
                                                Do
                                                        _button8()
                                                        If FileExists($lujing4) = 0 Then
                                                                DirCreate($lujing4)
                                                        EndIf
                                                        Local $a = _FileListToArray($lujing4)
                                                        Local $b = UBound($a) - 1
                                                        Sleep(1000)
                                                Until $b = $cishu4
                                                MsgBox(0, "ok", "生成完毕")
                                        Case $Button9
                                                _button9()
                                        Case $Button10
                                                If FileExists($lujing5) = 0 Then
                                                        DirCreate($lujing5)
                                                EndIf
                                                $cishu5 = InputBox("请输入数字", "输入要生成文章的数量")
                                                Local $ddd = StringIsDigit($cishu5)
                                                If $ddd = 0 Then
                                                        MsgBox(64, "错误", "请输入正确的数字")
                                                        Return
                                                EndIf
                                                
                                                Do
                                                        _button10()
                                                        Local $a = _FileListToArray($lujing5)
                                                        Local $b = UBound($a) - 1
                                                        Sleep(1000)
                                                Until $b = $cishu5
                                                MsgBox(0, "ok", "生成完毕")
                                                
                                                

                                EndSwitch
                EndSwitch
                
        WEnd
EndFunc   ;==>_GUICloseEvent
问题是这样的,有12个按钮在不同的ListView上面  先点击1,3,5,7,9,11这几个按钮中的其中任何一个,2,4,6,8,10,12这几个按钮都只能用后来点击的第一个,如果先点击按钮2,4,6,8,10,12则全部正常。求帮助,谢谢。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-18 14:39 , Processed in 0.077989 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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