GUICtrlCreateTreeView 单击后怎么样获取当前项目[已解决]
本帖最后由 破帽遮颜 于 2011-5-11 10:48 编辑希望高人出手帮忙解决个问题
双击是没有问题的,但单击子项目后怎么样才能获取当前项目?循环的方法就算了。希望使用消息能解决这个问题。感谢。{:face (59):}
下面已解决。该例子没问题了。#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 这个好像是帮助中例子? 回复 2# lpxx
是啊~随便改改做个实例给大家。有办法米? 看了,暂时没有好的思路和那个能力帮你解决,等待能人帮你解决。 回复 4# lpxx
呵呵~谢谢 WM消息是不能获取的(原因我忘了...),所以,目前靠谱的方法是使用SetOnevenet的方法,至少我是这么做的。 回复 6# republican
能把你 用注册WM消息的方法 贴上来看下吗?~ 回复 7# pusofalse
P版能帮忙解决这个问题吗?拜托了。{:face (198):} 回复 6# republican
有简单的实例看看吗?{:face (59):} 回复 6# republican
哦,明白了。给每个项目GUICtrlSetOnEvent 回复 8# 破帽遮颜
If $iCode = $NM_CLICK ..., 这里不应该判断是否是鼠标单击,鼠标单击这个通知发送得太早,TreeView中的项目的状态和颜色等信息 还没来得及改变,就已经收到了这个NM_CLICK。另外,如果是用上下键选择呢?
要截取的通知应该是在NM_CLICK之后接收到的,仔细看下TreeViewConstants.au3中以TVN_*开头的常量,相信很快就能修正过来了。 回复 11# pusofalse
谢谢P版~解决了。感谢。
消息上用If $iCode <> -400 - 51 Then Return搞定 回复 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 现在对au3中的常量很头大
常量没解释,看着晕忽忽的 回复 13# 3mile
呵呵~没分送了~不然送上点金币。
页:
[1]
2