|
本帖最后由 dhlhmgc 于 2023-4-5 09:42 编辑
目标想得到 TreeView 的鼠标移入、移出消息事件,求出当前鼠标下的节点信息!
就是HotTrack形式,在处理TREEVIEW控件又遇到问题 ,GUI消息事件:WM_NOTIFY
====================================
$tNMHdr = DllStructCreate("hwnd hWndFrom;int IDFrom;int Code;dword dwFlags"
已经知道:鼠标移入,移出的动态值就是在 dwFlags 里面,调试输出也有变化
但case的事件常量不知道用什么,求指教:
Switch $iIDFrom
Case $TreeView1
Switch $iCode
Case $NM_CLICK ;左键单击
============================================
鼠标移入\移出 试过:
;Case $BCN_HOTITEMCHANGE ; Win XP and Above
; If BitAND($dwFlags, 0x10) = 0x10 Then
; $sText = "$BCN_HOTITEMCHANGE - Entering:当鼠标进入 "
; WinSetTitle($fm1, "", "dw : " & $dwFlags)
; ElseIf BitAND($dwFlags, 0x20) = 0x20 Then
; $sText = "$BCN_HOTITEMCHANGE - Leaving: 当鼠标移出"
; WinSetTitle($fm1, "", "dw : " & $dwFlags)
; EndIf
貌似不起作用,这个是不是只对Button等控件起作用!?
TVN_开头的也看了一堆,但不确定移入、移出的CODE代码常量是哪个!?
求高人指点!
[已解决]
==============
非常感谢各位大神无私的指导,虽然对WM_NOTIFY、WM_COMMAND的消息机构还不是太熟悉,但目前的问题已基本得到解决!现次感谢!
==============;---------------------------------------------------------------------------------------
; 功 能: 对 TreeView项目的鼠标跟踪
; 语 法:
;---------------------------------------------------------------------------------------
#include <WinAPI.au3>
#include <WinAPISys.au3>
#include <GuiTreeView.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <date.au3>
OnAutoItExitRegister('OnAutoItExit')
dim $hGUI = GUICreate('', 400, 300)
$iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)
;$TreeView1 = GUICtrlCreateTreeView(5, 5, 390, 280, $iStyle, $WS_EX_CLIENTEDGE)
$TreeView1 = GUICtrlCreateTreeView(5, 5, 390, 280, -1, $WS_EX_CLIENTEDGE )
$hTreeView = GUICtrlGetHandle(-1)
GUICtrlSetFont(-1, 12, 400, 0, "宋体")
$TreeViewItem1 = GUICtrlCreateTreeViewItem('TreeViewItem1', $TreeView1)
GUICtrlCreateTreeViewItem('TreeViewItem1-1', $TreeViewItem1)
GUICtrlCreateTreeViewItem('TreeViewItem1-2', $TreeViewItem1)
GUICtrlCreateTreeViewItem('TreeViewItem1-3', $TreeViewItem1)
$TreeViewItem2 = GUICtrlCreateTreeViewItem('TreeViewItem2', $TreeView1)
GUICtrlCreateTreeViewItem('TreeViewItem2-1', $TreeViewItem2)
GUICtrlCreateTreeViewItem('TreeViewItem2-2', $TreeViewItem2)
GUICtrlCreateTreeViewItem('TreeViewItem2-3', $TreeViewItem2)
$TreeViewItem3 = GUICtrlCreateTreeViewItem('TreeViewItem3', $TreeView1)
GUICtrlCreateTreeViewItem('TreeViewItem3-1', $TreeViewItem3)
GUICtrlCreateTreeViewItem('TreeViewItem3-2', $TreeViewItem3)
GUICtrlCreateTreeViewItem('TreeViewItem3-3', $TreeViewItem3)
;~ GUICtrlSetState($TreeViewItem1, $GUI_EXPAND)
;~ GUICtrlSetState($TreeViewItem2, $GUI_EXPAND)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ;捕捉窗口控件交互时事件
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
Exit
EndSwitch
WEnd
Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
#forceref $hWnd, $Msg, $wParam
Local Const $BCN_HOTITEMCHANGE = -1249
Local $tNMBHOTITEM = DllStructCreate("hwnd hWndFrom;int IDFrom;int Code;dword dwFlags", $lParam)
Local $nNotifyCode = DllStructGetData($tNMBHOTITEM, "Code")
Local $nID = DllStructGetData($tNMBHOTITEM, "IDFrom")
Local $hCtrl = DllStructGetData($tNMBHOTITEM, "hWndFrom")
Local $dwFlags = DllStructGetData($tNMBHOTITEM, "dwFlags")
;Local $iMousePosX = BitAND($lParam, 0xFFFF) ;低位字,鼠标的 X 位置
;Local $iMousePosY = BitShift($lParam, 16) ;高位字,鼠标的 Y 位置
local $hForm = _WinAPI_GetParent( $hCtrl ) ;//检索指定子窗口的父窗口句柄.
Switch $nNotifyCode
Case $NM_CLICK
Case $NM_SETCURSOR
if $dwFlags Then
Local $tMPos = _WinAPI_GetMousePos(True, $hCtrl)
Local $tHit = _GUICtrlTreeView_HitTestEx($hCtrl, DllStructGetData($tMPos, 1), DllStructGetData($tMPos, 2))
Local $hItem = DllStructGetData($tHit, "Item")
_GUICtrlTreeView_SelectItem ($TreeView1, $hItem, $TVGN_CARET) ;选中
$s = _GUICtrlTreeView_GetText ($TreeView1, $hItem)
$hItem = _GUICtrlTreeView_GetSelection($hCtrl)
if $hItem Then
$ss = " 热点:" & _GUICtrlTreeView_GetText ($TreeView1, $hItem)
else
$ss = ""
Endif
WinSetTitle($hForm, "", Random(10, 20, 1) & ' 鼠标:' & $s & $ss)
Return $GUI_RUNDEFMSG
Endif
EndSwitch
EndFunc
|
|