GUICtrlCreateTreeViewItem 勾选问题。求解决,求帮助(已解决)
本帖最后由 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
$jishubu = GUICtrlCreateTreeViewItem("技术部",$idTreeview)
$renyuan = GUICtrlCreateTreeViewItem("a",$jishubu)
$renyuan = GUICtrlCreateTreeViewItem("aa",$jishubu)
$renyuan = GUICtrlCreateTreeViewItem("aaa",$jishubu)
$renyuan = GUICtrlCreateTreeViewItem("aaaa",$jishubu)
$renyuan = GUICtrlCreateTreeViewItem("aaaaa",$jishubu)
$renyuan = GUICtrlCreateTreeViewItem("aaaaaa",$jishubu)
$renyuan = GUICtrlCreateTreeViewItem("aaaaaaa",$jishubu)
$renyuan = GUICtrlCreateTreeViewItem("aaaaaaaa",$jishubu)
$qihua = GUICtrlCreateTreeViewItem("企划部",$idTreeview)
$renyuan = GUICtrlCreateTreeViewItem("1",$qihua)
$renyuan = GUICtrlCreateTreeViewItem("2",$qihua)
$renyuan = GUICtrlCreateTreeViewItem("3",$qihua)
$renyuan = GUICtrlCreateTreeViewItem("4",$qihua)
$renyuan = GUICtrlCreateTreeViewItem("5",$qihua)
$xiangmu = GUICtrlCreateTreeViewItem("项目1",$idTreeview)
$renyuan = GUICtrlCreateTreeViewItem("6",$xiangmu)
$renyuan = GUICtrlCreateTreeViewItem("7",$xiangmu)
$renyuan = GUICtrlCreateTreeViewItem("8",$xiangmu)
$xiangmu2 = GUICtrlCreateTreeViewItem("项目2",$idTreeview)
$renyuan = GUICtrlCreateTreeViewItem("9",$xiangmu2)
$renyuan = GUICtrlCreateTreeViewItem("10",$xiangmu2)
$renyuan = GUICtrlCreateTreeViewItem("11",$xiangmu2)
$zixun = GUICtrlCreateTreeViewItem("咨询部",$idTreeview)
$renyuan = GUICtrlCreateTreeViewItem("12",$zixun)
$renyuan = GUICtrlCreateTreeViewItem("13",$zixun)
$renyuan = GUICtrlCreateTreeViewItem("14",$zixun)
$xinzhen = GUICtrlCreateTreeViewItem("行政",$idTreeview)
$renyuan = GUICtrlCreateTreeViewItem("15",$xinzhen)
$renyuan = GUICtrlCreateTreeViewItem("16",$xinzhen)
$renyuan = GUICtrlCreateTreeViewItem("17",$xinzhen)
EndFunc
Func _quanxuan($status) ;全选和全不选
$childWndArray = _WinAPI_EnumChildWindows($mainGUI)
If IsArray($childWndArray) Then
If $status Then
For $i=1 To $childWndArray
If $childWndArray[$i] = "Button" Then
$btnStyle = _WinAPI_GetWindowLong($childWndArray[$i], $GWL_STYLE)
If BitAND($btnStyle, $BS_AUTOCHECKBOX) = $BS_AUTOCHECKBOX Then
_SendMessage($childWndArray[$i], $BM_SETCHECK, $BST_CHECKED)
EndIf
EndIf
Next
Else
For $i=1 To $childWndArray
If $childWndArray[$i] = "Button" Then
$btnStyle = _WinAPI_GetWindowLong($childWndArray[$i], $GWL_STYLE)
If BitAND($btnStyle, $BS_AUTOCHECKBOX) = $BS_AUTOCHECKBOX Then
_SendMessage($childWndArray[$i], $BM_SETCHECK, $BST_UNCHECKED)
EndIf
EndIf
Next
EndIf
EndIf
EndFunc
;~ Func _fasong() ;发送
;~ $sql = "insert into tongzhi values "
;~
;~ For $i = $xuanxiang To $xuanxiang
;~ 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
Case $mainGUI
Switch $aMsg
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
希望按全选的时候,全部选上,重选的时候,全部不选。按部门按钮,部门一下全部选择。感谢,感谢,求思路,求解决。万分感谢 求帮助呀,求版主呀,感谢呀,感谢呀,非常感谢呀 源码区有现成的 完成一段,剩下的自己修改吧~#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
$renyuan = GUICtrlCreateTreeViewItem("技术部", $idTreeview)
$renyuan = GUICtrlCreateTreeViewItem("a", $renyuan)
$renyuan = GUICtrlCreateTreeViewItem("aa", $renyuan)
$renyuan = GUICtrlCreateTreeViewItem("aaa", $renyuan)
$renyuan = GUICtrlCreateTreeViewItem("aaaa", $renyuan)
$renyuan = GUICtrlCreateTreeViewItem("aaaaa", $renyuan)
$renyuan = GUICtrlCreateTreeViewItem("aaaaaa", $renyuan)
$renyuan = GUICtrlCreateTreeViewItem("aaaaaaa", $renyuan)
$renyuan = GUICtrlCreateTreeViewItem("aaaaaaaa", $renyuan)
$renyuan = GUICtrlCreateTreeViewItem("企划部", $idTreeview)
$renyuan = GUICtrlCreateTreeViewItem("1", $renyuan)
$renyuan = GUICtrlCreateTreeViewItem("2", $renyuan)
$renyuan = GUICtrlCreateTreeViewItem("3", $renyuan)
$renyuan = GUICtrlCreateTreeViewItem("4", $renyuan)
$renyuan = GUICtrlCreateTreeViewItem("5", $renyuan)
$renyuan = GUICtrlCreateTreeViewItem("项目1", $idTreeview)
$renyuan = GUICtrlCreateTreeViewItem("6", $renyuan)
$renyuan = GUICtrlCreateTreeViewItem("7", $renyuan)
$renyuan = GUICtrlCreateTreeViewItem("8", $renyuan)
$renyuan = GUICtrlCreateTreeViewItem("项目2", $idTreeview)
$renyuan = GUICtrlCreateTreeViewItem("9", $renyuan)
$renyuan = GUICtrlCreateTreeViewItem("10", $renyuan)
$renyuan = GUICtrlCreateTreeViewItem("11", $renyuan)
$renyuan = GUICtrlCreateTreeViewItem("咨询部", $idTreeview)
$renyuan = GUICtrlCreateTreeViewItem("12", $renyuan)
$renyuan = GUICtrlCreateTreeViewItem("13", $renyuan)
$renyuan = GUICtrlCreateTreeViewItem("14", $renyuan)
$renyuan = GUICtrlCreateTreeViewItem("行政", $idTreeview)
$renyuan = GUICtrlCreateTreeViewItem("15", $renyuan)
$renyuan = GUICtrlCreateTreeViewItem("16", $renyuan)
$renyuan = GUICtrlCreateTreeViewItem("17", $renyuan)
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], $GUI_UNCHECKED)
Else
GUICtrlSetState($renyuan[$i][$o], $GUI_CHECKED)
EndIf
Next
Next
EndFunc ;==>_quanxuan
;~ Func _fasong() ;发送
;~ $sql = "insert into tongzhi values "
;~
;~ For $i = $xuanxiang To $xuanxiang
;~ 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
Case $mainGUI
Switch $aMsg
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
页:
[1]