Jump to content

CustomDraw TreeView


Iczer
 Share

Recommended Posts

How i can make additional text ("some info") in CustomDraw TreeView not get selected and still be visible when i click on any TreeView item?

demo:

#include <GuiListView.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiTreeView.au3>
#include <SQLite.au3>
#include <Math.au3>

Global Const $tagNMLVCACHEHINT = $tagNMHDR & ";int iFrom;int iTo"
Global $aListView, $hListView, $TreeView_SelTitle, $aTreeViewState[19][8] = [[18,"","","","","","",""]], $sSelectedTVIndex = 3
Opt("GUIOnEventMode", 1)

#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("Form1", 881, 516, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
Global $TreeView = _GUICtrlTreeView_Create($Form1, 8, 16, 319, 489, BitOR($GUI_SS_DEFAULT_TREEVIEW,$WS_HSCROLL,$WS_VSCROLL,$WS_BORDER), BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE))
$TreeView_Root_1 = _GUICtrlTreeView_Add($TreeView, 0, "Root - 1")
_GUICtrlTreeView_SetIcon($TreeView, $TreeView_Root_1, "shell32.dll", 4)
$TreeView_Root_2 = _GUICtrlTreeView_Add($TreeView, 0, "Root - 2")
_GUICtrlTreeView_SetIcon($TreeView, $TreeView_Root_2, "shell32.dll", 4)
Global $ListView = GUICtrlCreateListView("Rowid|Name|Time|Category", 336, 16, 538, 486, $LVS_OWNERDATA, BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE)) ; $LVS_OWNERDATA must be included for a virtual listview
_GUICtrlListView_SetExtendedListViewStyle( $ListView, $LVS_EX_DOUBLEBUFFER+$LVS_EX_FULLROWSELECT )
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 200)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 88)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 3, 112)
GUICtrlSetOnEvent(-1, "ListViewClick")
;------------------------------------------------------------------------------------------
Local $idTVContextMenu = GUICtrlCreateContextMenu(GUICtrlCreateDummy())
$hTVContextMenu = GUICtrlGetHandle($idTVContextMenu)
Local $idTVContextMenu_Refresh = GUICtrlCreateMenuItem("Refresh", $idTVContextMenu)
Local $idTVContextMenu_Rename = GUICtrlCreateMenuItem("Rename", $idTVContextMenu)
GUICtrlCreateMenuItem("", $idTVContextMenu) ; separator
Local $idTVContextMenu_MarkALLRead = GUICtrlCreateMenuItem("Mark ALL Items Read", $idTVContextMenu)
Local $idTVContextMenu_MarkALLUnRead = GUICtrlCreateMenuItem("Mark ALL Items UnRead", $idTVContextMenu)
;------------------------------------------------------------------------------------------
GUIRegisterMsg($WM_NOTIFY, "LWS_WM_NOTIFY")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
SubFunction_FillTreeView()

While 1
    Sleep(100)
WEnd

Func Form1Close()
    GUIRegisterMsg( $WM_NOTIFY, "" )
    ;
    Exit
EndFunc
;==========================================================================================
Func ListViewClick()

EndFunc
;==========================================================================================
Func TreeView1Click()
    Local $sQuery, $aResult, $iRows, $iColumns
    Static Local $TreeView_SelTitlePRE = ""

    If $TreeView_SelTitlePRE == "" Then
        $TreeView_Selected = _GUICtrlTreeView_GetFirstChild($TreeView, $TreeView_Root_1)
        _GUICtrlTreeView_ClickItem($TreeView, $TreeView_Selected, "left")
    Else
        $TreeView_Selected = _GUICtrlTreeView_GetSelection($TreeView)
    EndIf
    $TreeView_SelTitle = _GUICtrlTreeView_GetText($TreeView, $TreeView_Selected)
    If $TreeView_SelTitle == $TreeView_SelTitlePRE Then
        Return
    Else
        $TreeView_SelTitlePRE = $TreeView_SelTitle
    EndIf

    ConsoleWrite($TreeView_SelTitle & @CRLF)

EndFunc
;==========================================================================================
Func SubFunction_FillTreeView()

    ConsoleWrite(" > $sSelected TV Index = " & $sSelectedTVIndex & @CRLF)
    ConsoleWrite(" > $sSelected TV Name = " & $aTreeViewState[$sSelectedTVIndex][5] & @CRLF)

    Local $idTVItem[$aTreeViewState[0][0]+1] = [$aTreeViewState[0][0]]
    _GUICtrlTreeView_BeginUpdate($TreeView)
    _GUICtrlTreeView_DeleteChildren($TreeView, $TreeView_Root_1)
    _GUICtrlTreeView_DeleteChildren($TreeView, $TreeView_Root_2)
    _GUICtrlTreeView_SetTextColor($TreeView, 0x77B5FE) ; color of additional text
    For $i = 1 To $aTreeViewState[0][0]
        $aTreeViewState[$i][0] = 3 ; icon num in "shell32.dll"
        $aTreeViewState[$i][1] = 0x000000 ; item text color
        $aTreeViewState[$i][2] = 0 ; text is bold (or not)
        $aTreeViewState[$i][3] = "some info" ; some additional text
        $aTreeViewState[$i][5] = String("item " & $i); item name
        Switch Mod($i,2)
            Case 0
                $idTVItem[$i] = _GUICtrlTreeView_AddChild($TreeView,$TreeView_Root_2, $aTreeViewState[$i][5])
            Case Else
                $idTVItem[$i] = _GUICtrlTreeView_AddChild($TreeView,$TreeView_Root_1, $aTreeViewState[$i][5])
        EndSwitch
        Switch Mod($i,3)
            Case 0
                $aTreeViewState[$i][2] = 0
            Case Else
                $aTreeViewState[$i][2] = 1
        EndSwitch
        _GUICtrlTreeView_SetItemParam($TreeView, $idTVItem[$i], $i)
        _GUICtrlTreeView_SetIcon($TreeView, $idTVItem[$i], "shell32.dll", $aTreeViewState[$i][0])
    Next
    _GUICtrlTreeView_Expand($TreeView, $TreeView_Root_1, True)
    _GUICtrlTreeView_EndUpdate($TreeView)

    _GUICtrlTreeView_ClickItem($TreeView, $idTVItem[$sSelectedTVIndex])

    SubFunction_FillListView()

EndFunc
;==========================================================================================
Func SubFunction_FillListView_Delayed()
    AdlibUnRegister("SubFunction_FillListView_Delayed")
    SubFunction_FillListView()
EndFunc
;==========================================================================================
Func SubFunction_FillListView()

    _GUICtrlListView_BeginUpdate ($ListView)
    _GUICtrlListView_DeleteAllItems ($ListView)
    For $i = 0 To 63
        $ret = _GUICtrlListView_AddItem($ListView, "Row "&$i&": Col 0")
        ;ConsoleWrite($i & @TAB & "$ret = " & $ret & @CRLF)
        _GUICtrlListView_AddSubItem($ListView, $i, "Row "&$i&": Col 1", 1)

        _GUICtrlListView_AddSubItem($ListView, $i, "Row "&$i&": Col 2", 2)

        _GUICtrlListView_AddSubItem($ListView, $i, "Row "&$i&": Col 3", 3)

    Next
    _GUICtrlListView_EndUpdate ($ListView)

EndFunc
;==========================================================================================
Func LWS_WM_NOTIFY( $hWnd, $iMsg, $wParam, $lParam )
    Local Static $tText = DllStructCreate( "wchar[512]" )
    Local Static $pText = DllStructGetPtr( $tText )
    Local Static $aResult, $iRows, $iFrom

    Local $tNMHDR, $hWndFrom, $iCode, $tInfo, $VKey
    $tNMHDR = DllStructCreate( $tagNMHDR, $lParam )
    $hWndFrom = HWnd( DllStructGetData( $tNMHDR, "hWndFrom" ) )
    $iCode = DllStructGetData( $tNMHDR, "Code" )

    Switch $hWndFrom
        Case $TreeView
            Switch $iCode

                Case $NM_CUSTOMDRAW
                    Local $tNMTVCUSTOMDRAW = DllStructCreate($tagNMTVCUSTOMDRAW, $lParam)
                    Local $dwDrawStage = DllStructGetData($tNMTVCUSTOMDRAW, "DrawStage")

                    Switch $dwDrawStage                                             ; Holds a value that specifies the drawing stage

                        Case $CDDS_PREPAINT
                            ; Before the paint cycle begins
                            Return BitOr( $CDRF_NOTIFYITEMDRAW, _   ; Notify the parent window of any item-related drawing operations
                                                        $CDRF_NOTIFYPOSTPAINT ) ; Notify the parent window after item-related drawing operations

                        Case $CDDS_ITEMPREPAINT
                            ; Before painting an item
                            Local $hItemSpec  = DllStructGetData($tNMTVCUSTOMDRAW, "ItemSpec")          ; $hItemSpec = $hItem
                            Local $iItemState = DllStructGetData($tNMTVCUSTOMDRAW, "ItemState")
                            Local $iItemParam = DllStructGetData($tNMTVCUSTOMDRAW, "ItemParam")         ; ItemParam = index in array
                            Local $hDC        = DllStructGetData($tNMTVCUSTOMDRAW, "HDC")               ; Handle to the item's device context

                            ;If Not BitAnd( $iItemState, $CDIS_FOCUS ) Then
                                DllStructSetData( $tNMTVCUSTOMDRAW, "ClrText", $aTreeViewState[$iItemParam][1] )            ; Forecolor of item text
                                ;DllStructSetData( $tNMTVCUSTOMDRAW, "clrTextBk",$aTreeViewState[$iItemParam][1] )  ; Backcolor of item text

                                Local $tRECT = _GUICtrlTreeView_DisplayRectEx ( $TreeView, $hItemSpec, True)
                                DllStructSetData( $tRECT, "Left", DllStructGetData( $tRECT, "Right") + 7)
                                DllStructSetData( $tRECT, "Right", DllStructGetData( $tRECT, "Right") + 188)


                                _WinAPI_DrawText( $hDC, $aTreeViewState[$iItemParam][3], $tRECT, $DT_LEFT ) ; and background color of the device context.
                                _GUICtrlTreeView_SetBold ($TreeView, $hItemSpec, $aTreeViewState[$iItemParam][2])
                            ;Else
                                ;_GUICtrlTreeView_SetBold ($TreeView, $hItemSpec, $aTreeViewState[$iItemParam][2])
                            ;EndIf

                            Return BitOr( $CDRF_NEWFONT, _              ; $CDRF_NEWFONT must be returned after changing font or colors
                                                        $CDRF_NOTIFYPOSTPAINT ) ; Notify the parent window after item-related drawing operations
                    EndSwitch

                Case $TVN_SELCHANGEDA, $TVN_SELCHANGEDW
                    AdlibRegister("SubFunction_FillListView_Delayed",300)
                    _WinAPI_RedrawWindow($TreeView)

                Case $NM_RCLICK
                    Local $tMPos = _WinAPI_GetMousePos(True, $hWndFrom) ; координаты относительно элемента
                    Local $hItem = _GUICtrlTreeView_HitTestItem($hWndFrom, DllStructGetData($tMPos, 1), DllStructGetData($tMPos, 2)) ; получаем дескриптор пункта
                    If $hItem <> -1 And $hItem <> 0x0 Then
                        DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hTVContextMenu, "int", 0, "int", MouseGetPos(0), "int", MouseGetPos(1), "hwnd", $Form1, "ptr", 0)
                    EndIf
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc

 

Link to comment
Share on other sites

By drawing the selected item in the postpaint stage:

#include <GuiListView.au3>
#include <FontConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiTreeView.au3>
#include <SQLite.au3>
#include <Math.au3>

Global Const $tagNMLVCACHEHINT = $tagNMHDR & ";int iFrom;int iTo"
Global $aListView, $hListView, $TreeView_SelTitle, $aTreeViewState[19][8] = [[18,"","","","","","",""]], $sSelectedTVIndex = 3
Opt("GUIOnEventMode", 1)

#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("Form1", 881, 516, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
Global $TreeView = _GUICtrlTreeView_Create($Form1, 8, 16, 319, 489, BitOR($GUI_SS_DEFAULT_TREEVIEW,$WS_HSCROLL,$WS_VSCROLL,$WS_BORDER), BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE))
$TreeView_Root_1 = _GUICtrlTreeView_Add($TreeView, 0, "Root - 1")
_GUICtrlTreeView_SetIcon($TreeView, $TreeView_Root_1, "shell32.dll", 4)
$TreeView_Root_2 = _GUICtrlTreeView_Add($TreeView, 0, "Root - 2")
_GUICtrlTreeView_SetIcon($TreeView, $TreeView_Root_2, "shell32.dll", 4)
Global $ListView = GUICtrlCreateListView("Rowid|Name|Time|Category", 336, 16, 538, 486, $LVS_OWNERDATA, BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE)) ; $LVS_OWNERDATA must be included for a virtual listview
_GUICtrlListView_SetExtendedListViewStyle( $ListView, $LVS_EX_DOUBLEBUFFER+$LVS_EX_FULLROWSELECT )
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 200)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 88)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 3, 112)
GUICtrlSetOnEvent(-1, "ListViewClick")
;------------------------------------------------------------------------------------------

  ; Get the font of the TreeView control
  ; Copied from the _GUICtrlGetFont example by KaFu
  ; See http://www.autoitscript.com/forum/index.php?showtopic=124526
  Local $hDC = _WinAPI_GetDC( $TreeView )
  $hFont = _SendMessage( $TreeView, $WM_GETFONT )
  Local $hObject = _WinAPI_SelectObject( $hDC, $hFont )
  Local $lvLOGFONT = DllStructCreate( $tagLOGFONT )
  DllCall( 'gdi32.dll', 'int', 'GetObjectW', 'ptr', $hFont, 'int', DllStructGetSize( $lvLOGFONT ), 'ptr', DllStructGetPtr( $lvLOGFONT ) )
  _WinAPI_SelectObject( $hDC, $hObject )
  _WinAPI_ReleaseDC( $TreeView, $hDC )
  $TreeViewFont = _WinAPI_CreateFontIndirect( $lvLOGFONT )
  Local $iWeight = BitOR( DllStructGetData( $lvLOGFONT, "Weight" ), $FW_BOLD )
  DllStructSetData( $lvLOGFONT, "Weight", $iWeight )
  $TreeViewFontBold = _WinAPI_CreateFontIndirect( $lvLOGFONT )

;------------------------------------------------------------------------------------------
Local $idTVContextMenu = GUICtrlCreateContextMenu(GUICtrlCreateDummy())
$hTVContextMenu = GUICtrlGetHandle($idTVContextMenu)
Local $idTVContextMenu_Refresh = GUICtrlCreateMenuItem("Refresh", $idTVContextMenu)
Local $idTVContextMenu_Rename = GUICtrlCreateMenuItem("Rename", $idTVContextMenu)
GUICtrlCreateMenuItem("", $idTVContextMenu) ; separator
Local $idTVContextMenu_MarkALLRead = GUICtrlCreateMenuItem("Mark ALL Items Read", $idTVContextMenu)
Local $idTVContextMenu_MarkALLUnRead = GUICtrlCreateMenuItem("Mark ALL Items UnRead", $idTVContextMenu)
;------------------------------------------------------------------------------------------
GUIRegisterMsg($WM_NOTIFY, "LWS_WM_NOTIFY")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
SubFunction_FillTreeView()

While 1
    Sleep(100)
WEnd

Func Form1Close()
    GUIRegisterMsg( $WM_NOTIFY, "" )
    ;
    Exit
EndFunc
;==========================================================================================
Func ListViewClick()

EndFunc
;==========================================================================================
Func TreeView1Click()
    Local $sQuery, $aResult, $iRows, $iColumns
    Static Local $TreeView_SelTitlePRE = ""

    If $TreeView_SelTitlePRE == "" Then
        $TreeView_Selected = _GUICtrlTreeView_GetFirstChild($TreeView, $TreeView_Root_1)
        _GUICtrlTreeView_ClickItem($TreeView, $TreeView_Selected, "left")
    Else
        $TreeView_Selected = _GUICtrlTreeView_GetSelection($TreeView)
    EndIf
    $TreeView_SelTitle = _GUICtrlTreeView_GetText($TreeView, $TreeView_Selected)
    If $TreeView_SelTitle == $TreeView_SelTitlePRE Then
        Return
    Else
        $TreeView_SelTitlePRE = $TreeView_SelTitle
    EndIf

    ConsoleWrite($TreeView_SelTitle & @CRLF)

EndFunc
;==========================================================================================
Func SubFunction_FillTreeView()

    ConsoleWrite(" > $sSelected TV Index = " & $sSelectedTVIndex & @CRLF)
    ConsoleWrite(" > $sSelected TV Name = " & $aTreeViewState[$sSelectedTVIndex][5] & @CRLF)

    Local $idTVItem[$aTreeViewState[0][0]+1] = [$aTreeViewState[0][0]]
    _GUICtrlTreeView_BeginUpdate($TreeView)
    _GUICtrlTreeView_DeleteChildren($TreeView, $TreeView_Root_1)
    _GUICtrlTreeView_DeleteChildren($TreeView, $TreeView_Root_2)
    _GUICtrlTreeView_SetTextColor($TreeView, 0x77B5FE) ; color of additional text
    For $i = 1 To $aTreeViewState[0][0]
        $aTreeViewState[$i][0] = 3 ; icon num in "shell32.dll"
        $aTreeViewState[$i][1] = 0x000000 ; item text color
        $aTreeViewState[$i][2] = 0 ; text is bold (or not)
        $aTreeViewState[$i][3] = "some info" ; some additional text
        $aTreeViewState[$i][5] = String("item " & $i); item name
        Switch Mod($i,2)
            Case 0
                $idTVItem[$i] = _GUICtrlTreeView_AddChild($TreeView,$TreeView_Root_2, $aTreeViewState[$i][5])
            Case Else
                $idTVItem[$i] = _GUICtrlTreeView_AddChild($TreeView,$TreeView_Root_1, $aTreeViewState[$i][5])
        EndSwitch
        Switch Mod($i,3)
            Case 0
                $aTreeViewState[$i][2] = 0
            Case Else
                $aTreeViewState[$i][2] = 1
        EndSwitch
        _GUICtrlTreeView_SetItemParam($TreeView, $idTVItem[$i], $i)
        _GUICtrlTreeView_SetIcon($TreeView, $idTVItem[$i], "shell32.dll", $aTreeViewState[$i][0])
    Next
    _GUICtrlTreeView_Expand($TreeView, $TreeView_Root_1, True)
    _GUICtrlTreeView_EndUpdate($TreeView)

    _GUICtrlTreeView_ClickItem($TreeView, $idTVItem[$sSelectedTVIndex])

    SubFunction_FillListView()

EndFunc
;==========================================================================================
Func SubFunction_FillListView_Delayed()
    AdlibUnRegister("SubFunction_FillListView_Delayed")
    SubFunction_FillListView()
EndFunc
;==========================================================================================
Func SubFunction_FillListView()

    _GUICtrlListView_BeginUpdate ($ListView)
    _GUICtrlListView_DeleteAllItems ($ListView)
    For $i = 0 To 63
        $ret = _GUICtrlListView_AddItem($ListView, "Row "&$i&": Col 0")
        ;ConsoleWrite($i & @TAB & "$ret = " & $ret & @CRLF)
        _GUICtrlListView_AddSubItem($ListView, $i, "Row "&$i&": Col 1", 1)

        _GUICtrlListView_AddSubItem($ListView, $i, "Row "&$i&": Col 2", 2)

        _GUICtrlListView_AddSubItem($ListView, $i, "Row "&$i&": Col 3", 3)

    Next
    _GUICtrlListView_EndUpdate ($ListView)

EndFunc
;==========================================================================================
Func LWS_WM_NOTIFY( $hWnd, $iMsg, $wParam, $lParam )
    Local Static $tText = DllStructCreate( "wchar[512]" )
    Local Static $pText = DllStructGetPtr( $tText )
    Local Static $aResult, $iRows, $iFrom

    Local $tNMHDR, $hWndFrom, $iCode, $tInfo, $VKey
    $tNMHDR = DllStructCreate( $tagNMHDR, $lParam )
    $hWndFrom = HWnd( DllStructGetData( $tNMHDR, "hWndFrom" ) )
    $iCode = DllStructGetData( $tNMHDR, "Code" )

    Switch $hWndFrom
        Case $TreeView
            Switch $iCode

                Case $NM_CUSTOMDRAW
                    Local $tNMTVCUSTOMDRAW = DllStructCreate($tagNMTVCUSTOMDRAW, $lParam)
                    Local $dwDrawStage = DllStructGetData($tNMTVCUSTOMDRAW, "DrawStage")

                    Switch $dwDrawStage                                             ; Holds a value that specifies the drawing stage

                        Case $CDDS_PREPAINT
                            ; Before the paint cycle begins
                            Return $CDRF_NOTIFYITEMDRAW ; Notify the parent window of any item-related drawing operations

                        Case $CDDS_ITEMPREPAINT
                            ; Before painting an item
                            Local $hItemSpec  = DllStructGetData($tNMTVCUSTOMDRAW, "ItemSpec")          ; $hItemSpec = $hItem
                            Local $iItemState = DllStructGetData($tNMTVCUSTOMDRAW, "ItemState")
                            Local $iItemParam = DllStructGetData($tNMTVCUSTOMDRAW, "ItemParam")         ; ItemParam = index in array
                            Local $hDC        = DllStructGetData($tNMTVCUSTOMDRAW, "HDC")               ; Handle to the item's device context

                            $iSelected = DllCall( "user32.dll", "lresult", "SendMessageW", "hwnd", $TreeView, "uint", $TVM_GETITEMSTATE, "wparam", $hItemSpec, "lparam", $TVIS_SELECTED )[0] ; Selected state
                            If BitAND( $iSelected, $TVIS_SELECTED ) Then Return $CDRF_NOTIFYPOSTPAINT

                            ;If Not BitAnd( $iItemState, $CDIS_FOCUS ) Then
                                DllStructSetData( $tNMTVCUSTOMDRAW, "ClrText", $aTreeViewState[$iItemParam][1] )            ; Forecolor of item text
                                ;DllStructSetData( $tNMTVCUSTOMDRAW, "clrTextBk",$aTreeViewState[$iItemParam][1] )  ; Backcolor of item text

                                Local $tRECT = _GUICtrlTreeView_DisplayRectEx ( $TreeView, $hItemSpec, True)
                                DllStructSetData( $tRECT, "Left", DllStructGetData( $tRECT, "Right") + 7)
                                DllStructSetData( $tRECT, "Right", DllStructGetData( $tRECT, "Right") + 188)


                                _WinAPI_DrawText( $hDC, $aTreeViewState[$iItemParam][3], $tRECT, $DT_LEFT ) ; and background color of the device context.
                                _GUICtrlTreeView_SetBold ($TreeView, $hItemSpec, $aTreeViewState[$iItemParam][2])
                            ;Else
                                ;_GUICtrlTreeView_SetBold ($TreeView, $hItemSpec, $aTreeViewState[$iItemParam][2])
                            ;EndIf
                            Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors

                        Case $CDDS_ITEMPOSTPAINT
                            Local $hItemSpec  = DllStructGetData($tNMTVCUSTOMDRAW, "ItemSpec")          ; $hItemSpec = $hItem
                            Local $iItemState = DllStructGetData($tNMTVCUSTOMDRAW, "ItemState")
                            Local $iItemParam = DllStructGetData($tNMTVCUSTOMDRAW, "ItemParam")         ; ItemParam = index in array
                            Local $hDC        = DllStructGetData($tNMTVCUSTOMDRAW, "HDC")               ; Handle to the item's device context

                            Local $tRECT = _GUICtrlTreeView_DisplayRectEx( $TreeView, $hItemSpec, True)
                            DllStructSetData( $tRECT, "Left", DllStructGetData( $tRECT, "Right") + 7)
                            DllStructSetData( $tRECT, "Right", DllStructGetData( $tRECT, "Right") + 188)

                            ;DllStructSetData( $tNMTVCUSTOMDRAW, "ClrText", $aTreeViewState[$iItemParam][1] )            ; Forecolor of item text
                            DllCall( "gdi32.dll", "int", "SetTextColor", "handle", $hDC, "int", 0xFEB577 ) ; 0x77B5FE
                            _WinAPI_SelectObject( $hDC, $aTreeViewState[$iItemParam][2] ? $TreeViewFontBold : $hFont ) ; Bold/normal font

                            _WinAPI_DrawText( $hDC, $aTreeViewState[$iItemParam][3], $tRECT, $DT_LEFT ) ; and background color of the device context.
                            _GUICtrlTreeView_SetBold ($TreeView, $hItemSpec, $aTreeViewState[$iItemParam][2])
                            Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors
                    EndSwitch

                Case $TVN_SELCHANGEDA, $TVN_SELCHANGEDW
                    AdlibRegister("SubFunction_FillListView_Delayed",300)
                    _WinAPI_RedrawWindow($TreeView)

                Case $NM_RCLICK
                    Local $tMPos = _WinAPI_GetMousePos(True, $hWndFrom) ; ?????????? ???????????? ????????
                    Local $hItem = _GUICtrlTreeView_HitTestItem($hWndFrom, DllStructGetData($tMPos, 1), DllStructGetData($tMPos, 2)) ; ???????? ?????????? ??????
                    If $hItem <> -1 And $hItem <> 0x0 Then
                        DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hTVContextMenu, "int", 0, "int", MouseGetPos(0), "int", MouseGetPos(1), "hwnd", $Form1, "ptr", 0)
                    EndIf
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc

 

Link to comment
Share on other sites

Nicely done @LarsJ

Is there a way to do it without flickering ?

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

I think that most flicker is caused by the two lines in "Case $TVN_SELCHANGED". It should help to comment out these two lines.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...