找回密码
 加入
搜索
查看: 16145|回复: 22

[GUI管理] GUICtrlCreateTreeView 单击后怎么样获取当前项目[已解决]

 火.. [复制链接]
发表于 2010-10-12 23:32:52 | 显示全部楼层 |阅读模式
本帖最后由 破帽遮颜 于 2011-5-11 10:48 编辑

希望高人出手帮忙解决个问题
双击是没有问题的,但单击子项目后怎么样才能获取当前项目?循环的方法就算了。希望使用消息能解决这个问题。感谢。

下面已解决。该例子没问题了。
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>
#include <StaticConstants.au3>
#Include <GuiListView.au3>
#include <GUIConstantsEx.au3>
#Include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <Constants.au3>

Local $treeview, $generalitem, $displayitem, $aboutitem, $compitem
Local $useritem, $resitem, $otheritem, $startlabel, $aboutlabel, $compinfo
Local $togglebutton, $infobutton, $statebutton, $cancelbutton
Local $msg, $item, $hItem, $text

GUICreate("My GUI with treeview", 350, 215)

$treeview = GUICtrlCreateTreeView(6, 6, 200, 180, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
$generalitem = GUICtrlCreateTreeViewItem("General", $treeview)
GUICtrlSetColor(-1, 0x0000C0)
$displayitem = GUICtrlCreateTreeViewItem("Display", $treeview)
GUICtrlSetColor(-1, 0x0000C0)
$aboutitem = GUICtrlCreateTreeViewItem("About", $generalitem)
$compitem = GUICtrlCreateTreeViewItem("Computer", $generalitem)
$useritem = GUICtrlCreateTreeViewItem("User", $generalitem)
$resitem = GUICtrlCreateTreeViewItem("Resolution", $displayitem)
$otheritem = GUICtrlCreateTreeViewItem("Other", $displayitem)

GUICtrlSetState($generalitem, BitOR($GUI_EXPAND, $GUI_DEFBUTTON)) ; Expand the "General"-item and paint in bold
GUICtrlSetState($displayitem, BitOR($GUI_EXPAND, $GUI_DEFBUTTON)) ; Expand the "Display"-item and paint in bold

GUIRegisterMsg(0x004E, 'MY_WM')
GUISetState()
While 1
        $msg = GUIGetMsg()
        Select
                Case $msg = $GUI_EVENT_CLOSE
                        ExitLoop
        EndSelect
WEnd
GUIDelete()


Func MY_WM($hWnd, $msg, $wParam, $lParam)
        Local $tNMHDR, $hWndFrom, $iIDFrom, $iCode, $tNMTOOLBAR, $iItem
        $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
        $hWndFrom = HWnd(DllStructGetData($tNMHDR, 'hWndFrom'))
        $iIDFrom = DllStructGetData($tNMHDR, 'IDFrom')
        $iCode = DllStructGetData($tNMHDR, 'Code')
        $tNMTOOLBAR = DllStructCreate($tagNMTOOLBAR, $lParam)
        $iItem = DllStructGetData($tNMTOOLBAR, 'iItem')
        Switch $hWndFrom
                Case GUICtrlGetHandle($treeview)
                        If $iCode <> -400 - 51 Then Return
                                $read = GUICtrlRead(GUICtrlRead($treeview), 1)
                                MsgBox(4096, '', $read)
                        EndIf
        EndSwitch
EndFunc   ;==>MY_WM

评分

参与人数 1金钱 +10 收起 理由
afan + 10 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

发表于 2010-10-12 23:39:54 | 显示全部楼层
这个好像是帮助中例子?
 楼主| 发表于 2010-10-12 23:41:33 | 显示全部楼层
回复 2# lpxx

是啊~随便改改做个实例给大家。有办法米?
发表于 2010-10-12 23:41:49 | 显示全部楼层
看了,暂时没有好的思路和那个能力帮你解决,等待能人帮你解决。

评分

参与人数 1金钱 +20 收起 理由
破帽遮颜 + 20 谢谢帮忙

查看全部评分

 楼主| 发表于 2010-10-12 23:46:24 | 显示全部楼层
回复 4# lpxx

呵呵~谢谢
发表于 2010-10-13 00:13:41 | 显示全部楼层
WM消息是不能获取的(原因我忘了...),所以,目前靠谱的方法是使用SetOnevenet的方法,至少我是这么做的。

评分

参与人数 1金钱 +30 贡献 +15 收起 理由
破帽遮颜 + 30 + 15 谢谢帮忙

查看全部评分

发表于 2010-10-13 00:15:19 | 显示全部楼层
回复 6# republican


    能把你 用注册WM消息的方法 贴上来看下吗?~
 楼主| 发表于 2010-10-13 00:17:41 | 显示全部楼层
回复 7# pusofalse

P版能帮忙解决这个问题吗?拜托了。
 楼主| 发表于 2010-10-13 00:22:30 | 显示全部楼层
回复 6# republican

有简单的实例看看吗?
 楼主| 发表于 2010-10-13 00:28:16 | 显示全部楼层
回复 6# republican

哦,明白了。给每个项目GUICtrlSetOnEvent
发表于 2010-10-13 00:30:31 | 显示全部楼层
回复 8# 破帽遮颜


If $iCode = $NM_CLICK ..., 这里不应该判断是否是鼠标单击,鼠标单击这个通知发送得太早,TreeView中的项目的状态和颜色等信息 还没来得及改变,就已经收到了这个NM_CLICK。另外,如果是用上下键选择呢?

要截取的通知应该是在NM_CLICK之后接收到的,仔细看下TreeViewConstants.au3中以TVN_*开头的常量,相信很快就能修正过来了。

评分

参与人数 2金钱 +60 贡献 +20 收起 理由
afan + 5
破帽遮颜 + 60 + 15 很棒的见解

查看全部评分

 楼主| 发表于 2010-10-13 00:44:42 | 显示全部楼层
回复 11# pusofalse

谢谢P版~解决了。感谢。
消息上用If $iCode <> -400 - 51 Then Return搞定
发表于 2010-10-13 09:42:38 | 显示全部楼层
回复 1# 破帽遮颜
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>
#include <GuiTreeView.au3>

Local $treeview, $generalitem, $displayitem, $aboutitem, $compitem
Local $useritem, $resitem, $otheritem, $startlabel, $aboutlabel, $compinfo
Local $togglebutton, $infobutton, $statebutton, $cancelbutton
Local $msg, $item, $hItem, $text

GUICreate("My GUI with treeview", 350, 215)

$treeview = GUICtrlCreateTreeView(6, 6, 200, 180, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
$generalitem = GUICtrlCreateTreeViewItem("General", $treeview)
GUICtrlSetColor(-1, 0x0000C0)
$displayitem = GUICtrlCreateTreeViewItem("Display", $treeview)
GUICtrlSetColor(-1, 0x0000C0)
$aboutitem = GUICtrlCreateTreeViewItem("About", $generalitem)
$compitem = GUICtrlCreateTreeViewItem("Computer", $generalitem)
$useritem = GUICtrlCreateTreeViewItem("User", $generalitem)
$resitem = GUICtrlCreateTreeViewItem("Resolution", $displayitem)
$otheritem = GUICtrlCreateTreeViewItem("Other", $displayitem)

GUICtrlSetState($generalitem, BitOR($GUI_EXPAND, $GUI_DEFBUTTON)) ; Expand the "General"-item and paint in bold
GUICtrlSetState($displayitem, BitOR($GUI_EXPAND, $GUI_DEFBUTTON)) ; Expand the "Display"-item and paint in bold

GUIRegisterMsg($WM_NOTIFY, 'MY_WM')
GUISetState()
While 1
        $msg = GUIGetMsg()
        Select
                Case $msg = $GUI_EVENT_CLOSE
                        ExitLoop
        EndSelect
WEnd
GUIDelete()

Func MY_WM($hWnd, $Msg, $wParam, $lParam)
    Local $tNMHdr   = DllStructCreate($tagNMHDR, $lParam), $tNM_TREEVIEW
    Local $hWndFrom = DllStructGetData($tNMHdr, 'hWndFrom')
    Local $iIDFrom  = DllStructGetData($tNMHdr, 'IDFrom')
    Local $iCode    = DllStructGetData($tNMHdr, 'Code')
 
    If $iIDFrom = $TreeView Then
        Switch $iCode
            Case $TVN_SELCHANGEDA, $TVN_SELCHANGEDW
                If GUICtrlRead($TreeView) > 0 Then _
                    MsgBox(0, 0, 'ID: ' & GUICtrlRead($TreeView) & @CRLF & 'Text: ' & GUICtrlRead($TreeView, 1))
        EndSwitch
    EndIf
    
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_OnNotify

评分

参与人数 2金钱 +90 贡献 +15 收起 理由
破帽遮颜 + 60 + 15 很棒的见解
afan + 30

查看全部评分

发表于 2010-10-13 11:09:55 | 显示全部楼层
现在对au3中的常量很头大
常量没解释,看着晕忽忽的
 楼主| 发表于 2010-10-13 12:00:25 | 显示全部楼层
回复 13# 3mile

呵呵~没分送了~不然送上点金币。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-16 23:33 , Processed in 0.104229 second(s), 31 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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