找回密码
 加入
搜索
查看: 5369|回复: 3

[AU3基础] GUICtrlCreateTreeViewItem 勾选问题。求解决,求帮助(已解决)

[复制链接]
发表于 2014-11-26 16:12:15 | 显示全部楼层 |阅读模式
本帖最后由 ak47gglllk 于 2014-11-29 16:20 编辑
#NoTrayIcon
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <TrayConstants.au3>
#include <TreeViewConstants.au3>
#include <ButtonConstants.au3>
#Include <WinAPIEx.au3>
#Include <Constants.au3 >
#Include <WinAPI.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>


Opt("TrayMenuMode", 3);没有默认菜单
Dim $databaseIp = '192.168.1.221', $databaseName = 'sa', $databasePwd ='abc123'
Global $mainGUI,$tpyj1,$tpyj2,$tptc,$fatongzhi,$yijian,$fasong,$renyuanmingdan,$quanxuan,$idTreeview
Global $fatongzhitab,$quanbuxuan,$Conn,$RS,$shijian = @YEAR&"-"&@MON&"-"&@MDAY&"-"&@HOUR&":"&@MIN&":"&@SEC

_maingui()
Func _maingui() ;主窗口
        $mainGUI = GUICreate("行政软件",800,600,192,124,BitOR($GUI_SS_DEFAULT_GUI,$WS_MAXIMIZEBOX,$WS_MAXIMIZE,$WS_TABSTOP))
        GUICtrlCreateTab(0, 0, @DesktopWidth, @DesktopHeight)
        _fatongzhi()
        _yijian()
        TrayItemSetState(-1,$TRAY_FOCUS)
        $tpyj1 = TrayCreateItem("右键1",-1,-1,-1)
        $tpyj2 = TrayCreateItem("右键2",-1,-1,-1)
        $tptc = TrayCreateItem("退出",-1,-1,-1)
        GUISetState(@SW_SHOW,$mainGUI)
        _GUICloseEvent()
EndFunc

Func _fatongzhi() ;发通知
        $fatongzhitab = GUICtrlCreateTabItem("发通知")
        GUICtrlCreateLabel("请在下面输入要发送的内容",30,40,BitOR($GUI_SS_DEFAULT_GUI,$WS_MAXIMIZEBOX,$WS_MAXIMIZE,$WS_TABSTOP))
        GUICtrlCreateLabel("请在下面选择要发送的人员名单",710,40,BitOR($GUI_SS_DEFAULT_GUI,$WS_MAXIMIZEBOX,$WS_MAXIMIZE,$WS_TABSTOP))
        $fatongzhi = GUICtrlCreateEdit("",30,60,600,400,$ws_vscroll + $es_wantreturn)
        $fasong = GUICtrlCreateButton("发送",290,470,80,40)
        $quanxuan = GUICtrlCreateButton("全选",800,470,80,40)
        $quanbuxuan = GUICtrlCreateButton("重选",1000,470,80,40)
        $idTreeview = GUICtrlCreateTreeView(700,60,600,400,BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES))
        Global $renyuan[10][20]
        $jishubu = GUICtrlCreateTreeViewItem("技术部",$idTreeview)
        $renyuan[0][0] = GUICtrlCreateTreeViewItem("a",$jishubu)
        $renyuan[0][1] = GUICtrlCreateTreeViewItem("aa",$jishubu)
        $renyuan[0][2] = GUICtrlCreateTreeViewItem("aaa",$jishubu)
        $renyuan[0][3] = GUICtrlCreateTreeViewItem("aaaa",$jishubu)
        $renyuan[0][4] = GUICtrlCreateTreeViewItem("aaaaa",$jishubu)
        $renyuan[0][5] = GUICtrlCreateTreeViewItem("aaaaaa",$jishubu)
        $renyuan[0][6] = GUICtrlCreateTreeViewItem("aaaaaaa",$jishubu)
        $renyuan[0][7] = GUICtrlCreateTreeViewItem("aaaaaaaa",$jishubu)
        $qihua = GUICtrlCreateTreeViewItem("企划部",$idTreeview)
        $renyuan[1][0] = GUICtrlCreateTreeViewItem("1",$qihua)
        $renyuan[1][1] = GUICtrlCreateTreeViewItem("2",$qihua)
        $renyuan[1][2] = GUICtrlCreateTreeViewItem("3",$qihua)
        $renyuan[1][3] = GUICtrlCreateTreeViewItem("4",$qihua)
        $renyuan[1][4] = GUICtrlCreateTreeViewItem("5",$qihua)
        $xiangmu = GUICtrlCreateTreeViewItem("项目1",$idTreeview)
        $renyuan[2][0] = GUICtrlCreateTreeViewItem("6",$xiangmu)
        $renyuan[2][1] = GUICtrlCreateTreeViewItem("7",$xiangmu)
        $renyuan[2][2] = GUICtrlCreateTreeViewItem("8",$xiangmu)
        $xiangmu2 = GUICtrlCreateTreeViewItem("项目2",$idTreeview)
        $renyuan[3][0] = GUICtrlCreateTreeViewItem("9",$xiangmu2)
        $renyuan[3][1] = GUICtrlCreateTreeViewItem("10",$xiangmu2)
        $renyuan[3][2] = GUICtrlCreateTreeViewItem("11",$xiangmu2)
        $zixun = GUICtrlCreateTreeViewItem("咨询部",$idTreeview)
        $renyuan[4][0] = GUICtrlCreateTreeViewItem("12",$zixun)
        $renyuan[4][1] = GUICtrlCreateTreeViewItem("13",$zixun)
        $renyuan[4][2] = GUICtrlCreateTreeViewItem("14",$zixun)
        $xinzhen = GUICtrlCreateTreeViewItem("行政",$idTreeview)
        $renyuan[5][0] = GUICtrlCreateTreeViewItem("15",$xinzhen)
        $renyuan[5][1] = GUICtrlCreateTreeViewItem("16",$xinzhen)
        $renyuan[5][2] = GUICtrlCreateTreeViewItem("17",$xinzhen)
        
EndFunc

Func _quanxuan($status) ;全选和全不选
        $childWndArray = _WinAPI_EnumChildWindows($mainGUI)
        If IsArray($childWndArray) Then
                If $status Then
                        For $i=1 To $childWndArray[0][0]
                                If $childWndArray[$i][1] = "Button" Then
                                        $btnStyle = _WinAPI_GetWindowLong($childWndArray[$i][0], $GWL_STYLE)
                                        If BitAND($btnStyle, $BS_AUTOCHECKBOX) = $BS_AUTOCHECKBOX Then
                                                _SendMessage($childWndArray[$i][0], $BM_SETCHECK, $BST_CHECKED)
                                        EndIf
                                EndIf
                        Next
                Else
                        For $i=1 To $childWndArray[0][0]
                                If $childWndArray[$i][1] = "Button" Then
                                        $btnStyle = _WinAPI_GetWindowLong($childWndArray[$i][0], $GWL_STYLE)
                                        If BitAND($btnStyle, $BS_AUTOCHECKBOX) = $BS_AUTOCHECKBOX Then
                                                _SendMessage($childWndArray[$i][0], $BM_SETCHECK, $BST_UNCHECKED)
                                        EndIf
                                EndIf
                        Next
                EndIf
        EndIf
EndFunc

;~ Func _fasong() ;发送

;~         $sql = "insert into tongzhi values "
;~         
;~         For $i = $xuanxiang[0] To $xuanxiang[7]
;~                 If BitAND(GUICtrlRead($i), $GUI_CHECKED) Then 
;~                 $sql =$sql & "('" & GUICtrlRead($i,1) & "','" & GUICtrlRead($fatongzhi) & "','" & $shijian & "'),"
;~                 EndIf
;~         Next
;~         $sql=StringLeft($sql,StringLen($sql)-1)
;~         _databaseOpen()
;~         $Conn.Execute($sql)
;~         
;~         $RS = ObjCreate("ADODB.Recordset")
;~         $RS.ActiveConnection = $Conn
;~         $rs.open("select id from tongzhi where convert(nvarchar(255),neirong) ='" & GUICtrlRead($fatongzhi) & "'")
;~         While (Not $RS.eof And Not $RS.bof)
;~                 $id = $rs.fields("id").value
;~                 $RS.movenext
;~         WEnd
;~         If $id > 0 Then
;~                 $rs.close
;~                 $Conn.close
;~                 MsgBox(0,"ok","已经发送")
;~         EndIf
;~                 
;~ EndFunc


Func _yijian() ;意见
        GUICtrlCreateTabItem("意见建议")
EndFunc

Func _tpyj1() ;右键托盘1
        MsgBox(64,"提示","你点击了右键1")
EndFunc

Func _tpyj2() ;右键托盘2
        MsgBox(64,"提示","你点击了右键2")
EndFunc

Func _zuixiaohua() ;最小化
        TraySetState(1)
        GUISetState(@SW_HIDE, $mainGUI)
EndFunc 

Func _huifu() ;恢复
        GUISetState(@SW_SHOW, $mainGUI)
        TraySetState(2)
EndFunc

Func _exit() ;退出
        Exit
        GUIDelete($mainGUI)
EndFunc 

Func _GUICloseEvent() ;所有事件
        Local $aMsg = 0  
        While 1
                $aMsg = GUIGetMsg(1)

                Switch $aMsg[1]
                        
                        Case $mainGUI
                                
                                Switch $aMsg[0]
                                        
                                        Case $GUI_EVENT_CLOSE
                                                ExitLoop
                                        Case $GUI_EVENT_MINIMIZE
                                                _zuixiaohua()
                                        Case $quanxuan
                                                _quanxuan(True)
;~                                                 ConsoleWrite(_quanxuan(True))
;~                                         Case $fasong
;~                                                 _fasong()
                                        Case $quanbuxuan
                                                _quanxuan(False)
                                                

                                EndSwitch
                                
                EndSwitch
                
        
                Switch TrayGetMsg() ;获取托盘事件
                        Case $TRAY_EVENT_PRIMARYDOUBLE
                                _huifu()
                        Case $tpyj1
                                _tpyj1()
                        Case $tpyj2
                                _tpyj2()
                        Case $tptc
                                _exit()
                                
                EndSwitch
                
                                
                
        WEnd
        GUIDelete($mainGUI)
EndFunc

Func _databaseOpen()  ;打开数据库
$Conn=ObjCreate("ADODB.Connection")
$Conn.open("DRIVER={SQL Server};SERVER="& $databaseIp & ";UID="& $databaseName & ";PWD="& $databasePwd & ";")
$Conn.Execute("use xinzhengguanli")
$RS = ObjCreate("ADODB.Recordset")
$RS.ActiveConnection = $Conn
EndFunc

Func _databaseclose()  ;关闭数据库
        
$Conn.close

EndFunc
希望按全选的时候,全部选上,重选的时候,全部不选。按部门按钮,部门一下全部选择。感谢,感谢,求思路,求解决。万分感谢

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2014-11-27 11:44:00 | 显示全部楼层
求帮助呀,求版主呀,感谢呀,感谢呀,非常感谢呀
发表于 2014-11-27 15:54:16 | 显示全部楼层
源码区有现成的
发表于 2014-11-27 17:14:51 | 显示全部楼层
完成一段,剩下的自己修改吧~
#NoTrayIcon
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <TrayConstants.au3>
#include <TreeViewConstants.au3>
#include <ButtonConstants.au3>
#include <WinAPIEx.au3>
#include <Constants.au3 >
#include <WinAPI.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>
#include <array.au3>


Opt("TrayMenuMode", 3);没有默认菜单
Dim $databaseIp = '192.168.1.221', $databaseName = 'sa', $databasePwd = 'abc123'
Global $mainGUI, $tpyj1, $tpyj2, $tptc, $fatongzhi, $yijian, $fasong, $renyuanmingdan, $quanxuan, $idTreeview
Global $fatongzhitab, $quanbuxuan, $Conn, $RS, $shijian = @YEAR & "-" & @MON & "-" & @MDAY & "-" & @HOUR & ":" & @MIN & ":" & @SEC

_maingui()
Func _maingui() ;主窗口
        $mainGUI = GUICreate("行政软件", 800, 600, 192, 124, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_MAXIMIZE, $WS_TABSTOP))
        GUICtrlCreateTab(0, 0, @DesktopWidth, @DesktopHeight)
        _fatongzhi()
        _yijian()
        TrayItemSetState(-1, $TRAY_FOCUS)
        $tpyj1 = TrayCreateItem("右键1", -1, -1, -1)
        $tpyj2 = TrayCreateItem("右键2", -1, -1, -1)
        $tptc = TrayCreateItem("退出", -1, -1, -1)
        GUISetState(@SW_SHOW, $mainGUI)
        _GUICloseEvent()
EndFunc   ;==>_maingui

Func _fatongzhi() ;发通知
        $fatongzhitab = GUICtrlCreateTabItem("发通知")
        GUICtrlCreateLabel("请在下面输入要发送的内容", 30, 40, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_MAXIMIZE, $WS_TABSTOP))
        GUICtrlCreateLabel("请在下面选择要发送的人员名单", 710, 40, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_MAXIMIZE, $WS_TABSTOP))
        $fatongzhi = GUICtrlCreateEdit("", 30, 60, 600, 400, $ws_vscroll + $es_wantreturn)
        $fasong = GUICtrlCreateButton("发送", 290, 470, 80, 40)
        $quanxuan = GUICtrlCreateButton("全选", 800, 470, 80, 40)
        $quanbuxuan = GUICtrlCreateButton("重选", 1000, 470, 80, 40)
        $idTreeview = GUICtrlCreateTreeView(700, 60, 600, 400, BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES))
        Global $renyuan[10][20]
        $renyuan[0][0] = GUICtrlCreateTreeViewItem("技术部", $idTreeview)
        $renyuan[0][8] = GUICtrlCreateTreeViewItem("a", $renyuan[0][0])
        $renyuan[0][1] = GUICtrlCreateTreeViewItem("aa", $renyuan[0][0])
        $renyuan[0][2] = GUICtrlCreateTreeViewItem("aaa", $renyuan[0][0])
        $renyuan[0][3] = GUICtrlCreateTreeViewItem("aaaa", $renyuan[0][0])
        $renyuan[0][4] = GUICtrlCreateTreeViewItem("aaaaa", $renyuan[0][0])
        $renyuan[0][5] = GUICtrlCreateTreeViewItem("aaaaaa", $renyuan[0][0])
        $renyuan[0][6] = GUICtrlCreateTreeViewItem("aaaaaaa", $renyuan[0][0])
        $renyuan[0][7] = GUICtrlCreateTreeViewItem("aaaaaaaa", $renyuan[0][0])
        $renyuan[1][0] = GUICtrlCreateTreeViewItem("企划部", $idTreeview)
        $renyuan[1][5] = GUICtrlCreateTreeViewItem("1", $renyuan[1][0])
        $renyuan[1][1] = GUICtrlCreateTreeViewItem("2", $renyuan[1][0])
        $renyuan[1][2] = GUICtrlCreateTreeViewItem("3", $renyuan[1][0])
        $renyuan[1][3] = GUICtrlCreateTreeViewItem("4", $renyuan[1][0])
        $renyuan[1][4] = GUICtrlCreateTreeViewItem("5", $renyuan[1][0])
        $renyuan[2][0] = GUICtrlCreateTreeViewItem("项目1", $idTreeview)
        $renyuan[2][3] = GUICtrlCreateTreeViewItem("6", $renyuan[2][0])
        $renyuan[2][1] = GUICtrlCreateTreeViewItem("7", $renyuan[2][0])
        $renyuan[2][2] = GUICtrlCreateTreeViewItem("8", $renyuan[2][0])
        $renyuan[3][0] = GUICtrlCreateTreeViewItem("项目2", $idTreeview)
        $renyuan[3][3] = GUICtrlCreateTreeViewItem("9", $renyuan[3][0])
        $renyuan[3][1] = GUICtrlCreateTreeViewItem("10", $renyuan[3][0])
        $renyuan[3][2] = GUICtrlCreateTreeViewItem("11", $renyuan[3][0])
        $renyuan[4][0] = GUICtrlCreateTreeViewItem("咨询部", $idTreeview)
        $renyuan[4][3] = GUICtrlCreateTreeViewItem("12", $renyuan[4][0])
        $renyuan[4][1] = GUICtrlCreateTreeViewItem("13", $renyuan[4][0])
        $renyuan[4][2] = GUICtrlCreateTreeViewItem("14", $renyuan[4][0])
        $renyuan[5][0] = GUICtrlCreateTreeViewItem("行政", $idTreeview)
        $renyuan[5][3] = GUICtrlCreateTreeViewItem("15", $renyuan[5][0])
        $renyuan[5][1] = GUICtrlCreateTreeViewItem("16", $renyuan[5][0])
        $renyuan[5][2] = GUICtrlCreateTreeViewItem("17", $renyuan[5][0])

EndFunc   ;==>_fatongzhi

Func _quanxuan($status) ;全选和全不选
        For $i = 0 To 6
                For $o = 0 To 10
                        If GUICtrlRead($renyuan[$i][$o]) = $GUI_CHECKED Then
                                GUICtrlSetState($renyuan[$i][$o], $GUI_UNCHECKED)
                                GUICtrlSetState($renyuan[$i][0], $GUI_UNCHECKED)
                        Else
                                GUICtrlSetState($renyuan[$i][$o], $GUI_CHECKED)
                                
                        EndIf
                        
                Next
        Next
EndFunc   ;==>_quanxuan

;~ Func _fasong() ;发送

;~         $sql = "insert into tongzhi values "
;~
;~         For $i = $xuanxiang[0] To $xuanxiang[7]
;~                 If BitAND(GUICtrlRead($i), $GUI_CHECKED) Then
;~                 $sql =$sql & "('" & GUICtrlRead($i,1) & "','" & GUICtrlRead($fatongzhi) & "','" & $shijian & "'),"
;~                 EndIf
;~         Next
;~         $sql=StringLeft($sql,StringLen($sql)-1)
;~         _databaseOpen()
;~         $Conn.Execute($sql)
;~
;~         $RS = ObjCreate("ADODB.Recordset")
;~         $RS.ActiveConnection = $Conn
;~         $rs.open("select id from tongzhi where convert(nvarchar(255),neirong) ='" & GUICtrlRead($fatongzhi) & "'")
;~         While (Not $RS.eof And Not $RS.bof)
;~                 $id = $rs.fields("id").value
;~                 $RS.movenext
;~         WEnd
;~         If $id > 0 Then
;~                 $rs.close
;~                 $Conn.close
;~                 MsgBox(0,"ok","已经发送")
;~         EndIf
;~
;~ EndFunc


Func _yijian() ;意见
        GUICtrlCreateTabItem("意见建议")
EndFunc   ;==>_yijian

Func _tpyj1() ;右键托盘1
        MsgBox(64, "提示", "你点击了右键1")
EndFunc   ;==>_tpyj1

Func _tpyj2() ;右键托盘2
        MsgBox(64, "提示", "你点击了右键2")
EndFunc   ;==>_tpyj2

Func _zuixiaohua() ;最小化
        TraySetState(1)
        GUISetState(@SW_HIDE, $mainGUI)
EndFunc   ;==>_zuixiaohua

Func _huifu() ;恢复
        GUISetState(@SW_SHOW, $mainGUI)
        TraySetState(2)
EndFunc   ;==>_huifu

Func _exit() ;退出
        Exit
        GUIDelete($mainGUI)
EndFunc   ;==>_exit

Func _GUICloseEvent() ;所有事件
        Local $aMsg = 0
        While 1
                
                $aMsg = GUIGetMsg(1)

                Switch $aMsg[1]

                        Case $mainGUI

                                Switch $aMsg[0]

                                        Case $GUI_EVENT_CLOSE
                                                ExitLoop
                                        Case $GUI_EVENT_MINIMIZE
                                                _zuixiaohua()
                                        Case $quanxuan
                                                _quanxuan(True)
;~                                                 ConsoleWrite(_quanxuan(True))
;~                                         Case $fasong
;~                                                 _fasong()
                                        Case $quanbuxuan
                                                _quanxuan(False)


                                EndSwitch

                EndSwitch


                Switch TrayGetMsg() ;获取托盘事件
                        Case $TRAY_EVENT_PRIMARYDOUBLE
                                _huifu()
                        Case $tpyj1
                                _tpyj1()
                        Case $tpyj2
                                _tpyj2()
                        Case $tptc
                                _exit()

                EndSwitch



        WEnd
        GUIDelete($mainGUI)
EndFunc   ;==>_GUICloseEvent

Func _databaseOpen() ;打开数据库
        $Conn = ObjCreate("ADODB.Connection")
        $Conn.open("DRIVER={SQL Server};SERVER=" & $databaseIp & ";UID=" & $databaseName & ";PWD=" & $databasePwd & ";")
        $Conn.Execute("use xinzhengguanli")
        $RS = ObjCreate("ADODB.Recordset")
        $RS.ActiveConnection = $Conn
EndFunc   ;==>_databaseOpen

Func _databaseclose() ;关闭数据库

        $Conn.close

EndFunc   ;==>_databaseclose
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-28 10:16 , Processed in 0.090350 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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