狠狠色丁香婷婷综合尤物/久久精品综合一区二区三区/中国有色金属学报/国产日韩欧美在线观看 - 国产一区二区三区四区五区tv

LOGO OA教程 ERP教程 模切知識交流 PMS教程 CRM教程 開發文檔 其他文檔  
 
網站管理員

巧用SendMessage函數擴展Treeview功能

admin
2013年11月15日 0:19 本文熱度 5096

Option Explicit
Private Type TPoint
    x As Long
    y As Long
End Type

Private Type TVHITTESTINFO
    pt As TPoint
    flags As Long
    hItem As Long
End Type

Private Type TVITEM
    mask As Long
    HTreeItem As Long
    state As Long
    stateMask As Long
    pszText As Long
    cchTextMax As Long
    iImage As Long
    iSelectedImage As Long
    cChildren As Long
    lParam As Long
End Type

Const TV_FIRST [color=#0000ff]=
&H1100
Const TVM_HITTEST = TV_FIRST + 17
Const TVM_GETITEM = TV_FIRST + 12
Const TVHT_ONITEMLABEL = &H4
Const TVIF_TEXT = &H1
Const GMEM_FIXED = &H0
'設置行高
Const TVM_SETITEMHEIGHT = TV_FIRST + 27
'設置背景色
Const TVM_SETBKCOLOR = TV_FIRST + 29


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" (ByVal Destination As String, ByVal Source As Long, ByVal Length As Long)
Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function GlobalFree Lib "kernel32" (ByVal hMem As Long) As Long

Dim hItemPrv As Long

Private Sub Form_Load()

    Dim ndX As Node

    '加入若干Item

    Set ndX = TreeView1.Nodes.Add(, , "R", "Root", 1)

    Set ndX = TreeView1.Nodes.Add("R", tvwChild, "Key1", "Node1", 1)

    Set ndX = TreeView1.Nodes.Add("Key1", tvwChild, "SubKey1", "SubNode1", 3)

    Set ndX = TreeView1.Nodes.Add("SubKey1", tvwChild, "SubKeys1", "SubNode1", 3)

    Set ndX = TreeView1.Nodes.Add("Key1", tvwChild, "SubKey2", "SubNode2")

    Set ndX = TreeView1.Nodes.Add("Key1", tvwChild, "SubKey3", "SubNode3")

    Set ndX = TreeView1.Nodes.Add("Key1", tvwChild, "SubKey4", "SubNode4")
    
  '設置樹型列表控件節點行(Node)高度
    Call SendMessage(TreeView1.hwnd, TVM_SETITEMHEIGHT, 30, 0)
  '設置樹型列表控件的背景顏色
    Call SendMessage(TreeView1.hwnd, TVM_SETBKCOLOR, 0, RGB(255, 0, 0))

End Sub

'為樹型列表控件(Treeview)中不同的節點行(Node)設置不同的Tooltips氣泡提示
'在TVM類消息中有一個TVM_HITTEST消息,發送該消息可以檢測控件表面上的某一點,
'如果該點位于一個標題上,則返回該標題的句柄。而利用TVM_GETITEM消息,則可以
'根據標題句柄返回該標題行的文本。所以結合利用這兩個消息可以獲取光標所在標題行的標題文本.
Private Sub TreeView1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)

    Dim ptA As TPoint

    Dim tf As TVHITTESTINFO

    Dim TV As TVITEM

    Dim hStr As Long

    Dim hItem As Long

    Dim astr As String * 1024

    Dim bstr

    On Error GoTo errLab

    '獲得當前光標所在的位置坐標

    ptA.x = Int(x / Screen.TwipsPerPixelX)

    ptA.y = Int(y / Screen.TwipsPerPixelY)

    tf.pt = ptA

    tf.flags = TVHT_ONITEMLABEL

    '獲得光標所在的Item的句柄

    hItem = SendMessage(TreeView1.hwnd, TVM_HITTEST, 0, tf)

    '如果未獲得句柄或者同上一次是同一個Item的句柄則退出

    If ((hItem <= 0) or (hItem = hItemPrv)) Then Exit Sub

    hItemPrv = hItem

    '分配一定的內存空間用以存儲Item的標題

    hStr = GlobalAlloc(GMEM_FIXED, 1024)

    If hStr > 0 Then

        TV.mask = TVIF_TEXT

        '獲取標題文本

        TV.HTreeItem = hItem

        'Item句柄

        TV.pszText = hStr

        TV.cchTextMax = 1023

        '發送TVM_GETITEM獲得標題文本

        Call SendMessage(TreeView1.hwnd, TVM_GETITEM, 0, TV)

        '將標題文本拷貝到字符串astr中

        CopyMemory astr, hStr, 1024

        bstr = Left$(astr, (InStr(astr, Chr$(0)) - 1))

        TreeView1.ToolTipText = bstr

        '釋放分配的內存空間

        GlobalFree hStr

    End If

    Exit Sub

errLab:

    Resume Next

End Sub

該文章在 2013/11/15 0:19:06 編輯過
關鍵字查詢
相關文章
正在查詢...
點晴ERP是一款針對中小制造業的專業生產管理軟件系統,系統成熟度和易用性得到了國內大量中小企業的青睞。
點晴PMS碼頭管理系統主要針對港口碼頭集裝箱與散貨日常運作、調度、堆場、車隊、財務費用、相關報表等業務管理,結合碼頭的業務特點,圍繞調度、堆場作業而開發的。集技術的先進性、管理的有效性于一體,是物流碼頭及其他港口類企業的高效ERP管理信息系統。
點晴WMS倉儲管理系統提供了貨物產品管理,銷售管理,采購管理,倉儲管理,倉庫管理,保質期管理,貨位管理,庫位管理,生產管理,WMS管理系統,標簽打印,條形碼,二維碼管理,批號管理軟件。
點晴免費OA是一款軟件和通用服務都免費,不限功能、不限時間、不限用戶的免費OA協同辦公管理系統。
Copyright 2010-2025 ClickSun All Rights Reserved