Treeview 为何取不到正确的值?请求帮助。
#include <Constants.au3>#include <GDIPlusConstants.au3>
#include <StructureConstants.au3>
#include <ListBoxConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <GUIListView.au3>
#include <Access.au3>
#include <Excel.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <TabConstants.au3>
#include <GuiIPAddress.au3>
#include <EditConstants.au3>
#include <TreeViewConstants.au3>
#include <TabConstants.au3>
#include <GuiTreeView.au3>
#include <GuiImageList.au3>
;防止程序被重复运行
If WinExists("Outsourcing Tools") Then Exit
AutoItWinSetTitle("Outsourcing Tools")
#CS
全局参数设置
#CE
;版权信息
Global $Program_name = "外包人员管理工具(单机版)"
Global $Program_desc = "外包人员管理工具(单机版)。"
Global $Program_ver = "版本:1.0"
Global $Program_copyright = "版权所有:查明胜 Mason@zhenhao.me"
Global $dirData = @ScriptDir & "\data"
Global $adSource = $dirData & "\Outsourcing.MDB"
Global $psTable = 'personal';人员信息
Global $coTable = 'company';公司信息
Global $usTable = 'user';用户
Global $paTable = 'parameter';参数
Global $T = '*'
Global $ID = ''
Global $Key_Word = " WHERE 1=1"
If Not FileExists($dirData) Then DirCreate($dirData)
#region ### START Koda GUI section ### Form=c:\users\mason-home\desktop\外包人员管理软件单机版\公司管理.kxf
$Main = GUICreate($Program_name, 785, 563, 499, 142)
$MenuItem1 = GUICtrlCreateMenu("设置(&O)")
$MenuItem3 = GUICtrlCreateMenuItem("用户管理", $MenuItem1)
$MenuItem4 = GUICtrlCreateMenuItem("参数设置", $MenuItem1)
$MenuItem2 = GUICtrlCreateMenu("帮助(&H)")
$MenuItem5 = GUICtrlCreateMenuItem("关于(&A)", $MenuItem2)
$MenuItem6 = GUICtrlCreateMenuItem("退出(&Q)", $MenuItem2)
$StatusBar = _GUICtrlStatusBar_Create($Main)
Dim $StatusBar_PartsWidth =
_GUICtrlStatusBar_SetParts($StatusBar, $StatusBar_PartsWidth)
_GUICtrlStatusBar_SetText($StatusBar, "", 0)
_GUICtrlStatusBar_SetText($StatusBar, "", 1)
$Button1 = GUICtrlCreateButton("Button1", 56, 8, 70, 70)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
;公司信息维护窗口
#region ### START Koda GUI section ### Form=C:\Users\Mason-Home\Desktop\外包人员管理软件单机版\Company.kxf
$Company = GUICreate("公司信息维护", 785, 563, 418, 179)
$TreeView_co = GUICtrlCreateTreeView(10, 18, 160, 524, BitOR($GUI_SS_DEFAULT_TREEVIEW, $WS_BORDER))
;$TreeView_co_0 = GUICtrlCreateTreeViewItem("全部", $TreeView_co)
;$TreeView_co_1 = GUICtrlCreateTreeViewItem("AA公司", $TreeView_co_0)
$Group_co = GUICtrlCreateGroup("公司基本信息", 188, 18, 569, 436)
$Input_co_1 = GUICtrlCreateInput("", 256, 48, 121, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button_addco = GUICtrlCreateButton("新增", 232, 488, 120, 40)
$Button_savco = GUICtrlCreateButton("保存", 399, 488, 120, 40)
$Button_delco = GUICtrlCreateButton("删除", 567, 488, 120, 40)
;GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While 1
$nMsg = GUIGetMsg(1)
Switch $nMsg
Case $GUI_EVENT_CLOSE
Switch $nMsg
Case $Main
Exit
Case $Company
GUISetState(@SW_HIDE, $Company)
EndSwitch
Case $Button1
GUISetState(@SW_SHOW, $Company)
_getCompanyTree()
EndSwitch
WEnd
Func _getCompanyTree()
_GUICtrlTreeView_DeleteAll($TreeView_co)
_GUICtrlTreeView_BeginUpdate($TreeView_co)
$hItem = _GUICtrlTreeView_Add($TreeView_co, 0, "全部")
_GUICtrlTreeView_AddChild($TreeView_co, $hItem, "AAA")
_GUICtrlTreeView_AddChild($TreeView_co, $hItem, "BBB")
_GUICtrlTreeView_Expand($TreeView_co)
_GUICtrlTreeView_EndUpdate($TreeView_co)
EndFunc ;==>_getCompanyTree
Func WM_NOTIFY($hWndGUI, $MsgID, $WParam, $LParam)
Local $tagNMHDR, $Event, $hWndFrom, $IDFrom
Local $tagNMHDR = DllStructCreate("int;int;int", $LParam)
If @error Then Return $GUI_RUNDEFMSG
$IDFrom = DllStructGetData($tagNMHDR, 2)
$Event = DllStructGetData($tagNMHDR, 3)
$tagNMHDR = 0
Switch $IDFrom
Case $TreeView_co
Switch $Event; 选择产生的事件
Case $TVN_SELCHANGEDW
ConsoleWrite($TreeView_co)
;If GUICtrlRead($TreeView_co) > 0 Then
ConsoleWrite(_GUICtrlTreeView_GetText($TreeView_co, GUICtrlRead($TreeView_co)))
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY http://www.autoitx.com/thread-30451-1-1.html 此贴没解决? 没有啊。多窗口、TAB下面都无效。 此贴没解决?
afan 发表于 2012-2-21 00:14 http://www.autoitx.com/images/common/back.gif
源码和数据库贴上来,谁能帮忙看看。就是如何获取2Gui中的treeview点击的文本和上级文本。
比如:点击 某某某,就能获取 某某某和他的公司。 本帖最后由 Ycxw2008 于 2012-2-21 14:04 编辑
这么多头文件{:face (293):} 这么多头文件
Ycxw2008 发表于 2012-2-21 14:02 http://www.autoitx.com/images/common/back.gif
代码做了精简。希望有人帮忙看看。要如何获取2个窗口的treeview的点击项。 本帖最后由 Ycxw2008 于 2012-2-21 16:02 编辑
回复 6# zerozha
消息循环不太会
用事件做个例子 你看怎么样#include <GuiTreeView.au3>
Opt('GUIOnEventMode', 1)
Global $main=GUICreate("",400,300,100,100)
GUISetOnEvent(-3,"_Exit")
Global $TreeView=GUICtrlCreateTreeView(0,0,200,300)
Global $test=['王二','张三','李四']
_test($TreeView,$test)
GUISetState()
Global $main2=GUICreate("",400,300,500,100)
GUISetOnEvent(-3,"_Exit")
Global $TreeView2=GUICtrlCreateTreeView(0,0,200,300)
Global $test2=['阿森纳','曼联','切尔西']
_test($TreeView2,$test2)
GUISetState()
While 1
Sleep(100)
WEnd
Func _Exit()
Exit
EndFunc
Func _test($Tree,$Array)
For $x=0 To UBound($Array)-1
$item=GUICtrlCreateTreeViewItem($Array[$x],$Tree)
GUICtrlSetOnEvent(-1,"_GUICLICK")
For $y=0 To 10
GUICtrlCreateTreeViewItem(Random(),$item)
GUICtrlSetOnEvent(-1,"_GUICLICK")
Next
Next
EndFunc
Func _guiclick()
MsgBox(0, '', _GUICtrlTreeView_GetText($TreeView,GUICtrlGetHandle(@GUI_CtrlId)))
EndFunc
页:
[1]