用戶登錄  |  用戶注冊
首 頁源碼下載網絡學院最新源碼源碼排行屏蔽廣告
當前位置:新興網絡 > 網絡學院 > 編程開發 > Visual Basic

VB 獲取TreeView 控件Node節點的位置大小RECT

減小字體 增大字體 作者:佚名  來源:本站整理  發布時間:2014-03-29 12:47:17

VB  TreeView控件中的Item節點坐標位置大小獲取

VBScript code復制代碼
Private Const TV_FIRST = &H1100
Private Const TVM_HITTEST = (TV_FIRST + 17)
Private Const TVM_GETITEMRECT = (TV_FIRST + 4)

Private Const TVHT_ABOVE = &H100
Private Const TVHT_BELOW = &H200
Private Const TVHT_NOWHERE = &H1
Private Const TVHT_ONITEMBUTTON = &H10
Private Const TVHT_ONITEMICON = &H2
Private Const TVHT_ONITEMINDENT = &H8
Private Const TVHT_ONITEMLABEL = &H4
Private Const TVHT_ONITEMRIGHT = &H20
Private Const TVHT_ONITEMSTATEICON = &H40
Private Const TVHT_TOLEFT = &H800
Private Const TVHT_TORIGHT = &H400

Private Type POINTAPI
    x As Long
    y As Long
End Type

Private Type RECT
    Left    As Long
    Top     As Long
    Right   As Long
    Bottom  As Long
End Type

Private Type TV_HITTESTINFO
    pt      As POINTAPI
    flags   As Long
    hItem   As Long
End Type

Private Declare Function GetClientRect Lib "user32" ( _
    ByVal hwnd As Long, _
    ByRef lpRect As RECT) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
    ByVal hwnd As Long, _
    ByVal wMsg As Long, _
    ByVal wParam As Long, _
    lParam As Any) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
    ByRef pDest As Any, _
    ByRef pSrc As Any, _
    ByVal ByteLen As Long)

Private Sub Form_Load()
    TreeView1.Nodes.Add , , "Root", "Root"
    TreeView1.Nodes.Add "Root", tvwChild, "Child", "Child"
End Sub

Private Sub TreeView1_MouseUp( _
    ByRef Button As Integer, _
    ByRef Shift As Integer, _
    ByRef x As Single, _
    ByRef y As Single)

    Dim msg     As String
    Dim pt      As POINTAPI
    Dim rc      As RECT
    Dim hti     As TV_HITTESTINFO
    Dim hItem   As Long
   
    pt.x = x / Screen.TwipsPerPixelX
    pt.y = y / Screen.TwipsPerPixelY
   
    hti.pt.x = pt.x
    hti.pt.y = pt.y
   
    Call SendMessage(TreeView1.hwnd, TVM_HITTEST, 0, hti) '1. Notice
    hItem = hti.hItem
   
    rc.Left = hItem
    Call SendMessage(TreeView1.hwnd, TVM_GETITEMRECT, True, rc) '2.Notice
   
    msg = _
        "Left   = " & rc.Left & vbCrLf & _
        "Top    = " & rc.Top & vbCrLf & _
        "Right  = " & rc.Right & vbCrLf & _
        "Bottom = " & rc.Bottom
    Debug.Print hItem
    Debug.Print msg
   
End Sub
 

Tags:TreeView 坐標

作者:佚名
  • 好的評價 如果您覺得此文章好,就請您
      0%(0)
  • 差的評價 如果您覺得此文章差,就請您
      100%(1)

網絡學院評論評論內容只代表網友觀點,與本站立場無關!

   評論摘要(共 0 條,得分 0 分,平均 0 分) 查看完整評論
美国百家乐注册