ツリービュー のSingleExpand属性を設定

なぜ、この機能が標準でONなのが、僕はとっても疑問。
個人的にあまり好きじゃない・・・。




Option Explicit

Private Const GWL_STYLE = (-16)
Private Const TVS_SINGLEEXPAND = &H400

Private Declare Function GetWindowLong Lib "User32" Alias "GetWindowLongA" ( _
    ByVal hWnd As Long, _
    ByVal nIndex As Long _
) As Long

Private Declare Function SetWindowLong Lib "User32" Alias "SetWindowLongA" ( _
    ByVal hWnd As Long, _
    ByVal nIndex As Long, _
    ByVal dwNewLong As Long _
) As Long

Public Sub TreeView_SetSingleExpand(tvw As TreeView, bFlag As Boolean)
    Dim nStyle As Long
    nStyle = GetWindowLong(tvw.hWnd, GWL_STYLE)
    If bFlag Then
        nStyle = nStyle Or TVS_SINGLEEXPAND
    Else
        nStyle = nStyle And (Not TVS_SINGLEEXPAND)
    End If
    Call SetWindowLong(tvw.hWnd, GWL_STYLE, nStyle)
End Sub