Jump to content
Sign in to follow this  
Yashied

TVExplorer UDF

Recommended Posts

Yashied I forgot some code in the main while loop.

here is the final one. Sorry...

;; Valuater
#include <GuiConstants.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <GuiComboBox.au3>
#include "include\TVExplorer.au3"

Dim $show = 0, $Child_[11], $children = 10, $ChildActual = 1
Global $Control_1[10]
Global $Control_2[10]
Global $Control_3[10]
Global $Control_4[10]
Global $Control_5[10]
Global $Control_6[10]
Global $Control_7[10]
Global $Control_8[10]
Global $Control_9[10]
Global $Control_10[10]

Global $hFocus = 0

$Main = GUICreate("New Link Wizard", 548, 360, (@DesktopWidth - 516) / 2, (@DesktopHeight - 323) / 2, -1, -1)

$Button_1 = GUICtrlCreateButton("&Next >", 20, 150, 80, 25)
$Button_2 = GUICtrlCreateButton("< &Back", 20, 120, 80, 25)
$Button_3 = GUICtrlCreateButton("&Exit", 20, 300, 80, 25)

GUISetState()

$Child_[1] = GUICreate("", 540, 330, 0, 0, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main)
_Form_1($Control_1)
GUISetState()

$Child_[2] = GUICreate("", 540, 330, 0, 0, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main)
_Form_2($Control_2)
GUISetState(@SW_HIDE)

$Child_[3] = GUICreate("", 540, 330, 0, 0, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main)
_Form_3($Control_3)
GUISetState(@SW_HIDE)

$Child_[4] = GUICreate("", 540, 330, 0, 0, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main)
_Form_4($Control_4)
GUISetState(@SW_HIDE)

$Child_[5] = GUICreate("", 540, 330, 0, 0, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main)
_Form_5($Control_5)
GUISetState(@SW_HIDE)

$Child_[6] = GUICreate("", 540, 330, 0, 0, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main)
_Form_6($Control_6)
GUISetState(@SW_HIDE)

$Child_[7] = GUICreate("", 540, 330, 0, 0, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main)
_Form_7($Control_7)
GUISetState(@SW_HIDE)

$Child_[8] = GUICreate("", 540, 330, 0, 0, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main)
_Form_8($Control_8)
GUISetState(@SW_HIDE)

$Child_[9] = GUICreate("", 540, 330, 0, 0, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main)
_Form_9($Control_9)
GUISetState(@SW_HIDE)

$Child_[10] = GUICreate("", 540, 330, 0, 0, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main)
_Form_10($Control_10)

GUISetState(@SW_HIDE)

While 1
    $msg = GUIGetMsg(1)

    Switch $msg[1]
        Case $Main
            Switch $msg[0]
                Case $GUI_EVENT_CLOSE
                    ExitLoop
                Case $Button_3
                    ExitLoop
                Case $Button_1
                    Set_ChildSwitch(+1)
                Case $Button_2
                    Set_ChildSwitch(-1)
            EndSwitch
        Case $Child_[2]
            Switch $msg[0]
                Case $Control_2[0]
                    $Path = _GUICtrlTVExplorer_GetSelected($hFocus)
                    _GUICtrlTVExplorer_AttachFolder($hFocus)
                    _GUICtrlTVExplorer_Expand($hFocus, $Path, 0)
                    $hFocus = 0
            EndSwitch
    EndSwitch
WEnd

GUIDelete($Main)
;--------- Functions -------------------

Func Set_ChildSwitch($ud)
    GUISetState(@SW_HIDE, $Child_[$ChildActual])
    $ChildActual += $ud
    If $ChildActual = 11 Then $ChildActual = 1
    If $ChildActual = 0 Then $ChildActual = 10
    GUISetState(@SW_SHOW, $Child_[$ChildActual])
EndFunc   ;==>Set_ChildSwitch

Func _Form_1(ByRef $Control_1)

EndFunc   ;==>_Form_1

Func _Form_2(ByRef $Control_2)
    $Control_2[0] = _GUICtrlTVExplorer_Create(@ProgramFilesDir, 320, 48, 200, 210, -1, $WS_EX_CLIENTEDGE, -1, '_TVEvent')
    $Control_2[1] = GUICtrlCreateDummy()
    HotKeySet('{F5}', '_TVRefresh')
    _GUICtrlTVExplorer_Expand($Control_2[0], @ProgramFilesDir & '\AutoIt3')
    _GUICtrlTVExplorer_Expand($Control_2[0])
    $Control_2[2] = GUICtrlCreateInput("", 320, 20, 200, 20)
EndFunc   ;==>_Form_2

Func _Form_3(ByRef $Control_3)

EndFunc   ;==>_Form_3

Func _Form_4(ByRef $Control_4)

EndFunc   ;==>_Form_4

Func _Form_5(ByRef $Control_5)

EndFunc   ;==>_Form_5

Func _Form_6(ByRef $Control_6)

EndFunc   ;==>_Form_6

Func _Form_7(ByRef $Control_7)

EndFunc   ;==>_Form_7

Func _Form_8(ByRef $Control_8)

EndFunc   ;==>_Form_8

Func _Form_9(ByRef $Control_9)

EndFunc   ;==>_Form_9

Func _Form_10(ByRef $Control_10)

EndFunc   ;==>_Form_10

Func _TVSetPath($iInput, $sPath)
    Local $Text = _WinAPI_PathCompactPath(GUICtrlGetHandle($iInput), $sPath, -2)
    If GUICtrlRead($iInput) <> $Text Then
        GUICtrlSetData($iInput, $Text)
    EndIf
EndFunc   ;==>_TVSetPath

Func _TVRefresh()
    Local $hWnd = _WinAPI_GetFocus()
    If $Control_2[0] = $hWnd Then
        If Not $hFocus Then
            $hFocus = $hWnd
            GUICtrlSendToDummy($Control_2[1])
        EndIf
        Return
    EndIf
    HotKeySet('{F5}')
    Send('{F5}')
    HotKeySet('{F5}', '_TVRefresh')
EndFunc   ;==>_TVRefresh

Func _TVEvent($hWnd, $iMsg, $sPath, $hItem)
    Switch $iMsg
        Case $TV_NOTIFY_BEGINUPDATE
            GUISetCursor(1, 1)
        Case $TV_NOTIFY_ENDUPDATE
            GUISetCursor(2)
        Case $TV_NOTIFY_SELCHANGED
            If $Control_2[0] = $hWnd Then
                _TVSetPath($Control_2[2], $sPath)
            EndIf
        Case $TV_NOTIFY_DBLCLK
        Case $TV_NOTIFY_RCLICK
            ; Nothing
        Case $TV_NOTIFY_DELETINGITEM
            ; Nothing
        Case $TV_NOTIFY_DISKMOUNTED
            ; Nothing
        Case $TV_NOTIFY_DISKUNMOUNTED
            ; Nothing
    EndSwitch
EndFunc   ;==>_TVEvent

Be Green Now or Never (BGNN)!

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

Just replace GUIGetMsg(1) to _GUICtrlTVExplorer_GetMsg(1) or use OnEvent mode. I wrote about it in the first post.

Yashied, thanks. This solve the example that I posted, however in my real application I have WM_NOTIFY function

that cause the same symptom.

Here is the code that is not working even after I put your correction.

;; Valuater
#include <GuiConstants.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <GuiComboBox.au3>
#include "include\TVExplorer.au3"
#include <GuiRichEdit.au3>
Dim $show = 0, $Child_[11], $children = 10, $ChildActual = 1
Global $Control_1[10]
Global $Control_2[10]
Global $Control_3[10]
Global $Control_4[10]
Global $Control_5[10]
Global $Control_6[10]
Global $Control_7[10]
Global $Control_8[10]
Global $Control_9[10]
Global $Control_10[10]

Global $hFocus = 0

$Main = GUICreate("New Link Wizard", 548, 360, (@DesktopWidth - 516) / 2, (@DesktopHeight - 323) / 2, -1, -1)

$Button_1 = GUICtrlCreateButton("&Next >", 20, 150, 80, 25)
$Button_2 = GUICtrlCreateButton("< &Back", 20, 120, 80, 25)
$Button_3 = GUICtrlCreateButton("&Exit", 20, 300, 80, 25)

GUISetState()

$Child_[1] = GUICreate("", 540, 330, 0, 0, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main)
_Form_1($Control_1)
GUISetState()

$Child_[2] = GUICreate("", 540, 330, 0, 0, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main)
_Form_2($Control_2)
GUISetState(@SW_HIDE)

$Child_[3] = GUICreate("", 540, 330, 0, 0, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main)
_Form_3($Control_3)
GUISetState(@SW_HIDE)

$Child_[4] = GUICreate("", 540, 330, 0, 0, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main)
_Form_4($Control_4)
GUISetState(@SW_HIDE)

$Child_[5] = GUICreate("", 540, 330, 0, 0, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main)
_Form_5($Control_5)
GUISetState(@SW_HIDE)

$Child_[6] = GUICreate("", 540, 330, 0, 0, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main)
_Form_6($Control_6)
GUISetState(@SW_HIDE)

$Child_[7] = GUICreate("", 540, 330, 0, 0, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main)
_Form_7($Control_7)
GUISetState(@SW_HIDE)

$Child_[8] = GUICreate("", 540, 330, 0, 0, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main)
_Form_8($Control_8)
GUISetState(@SW_HIDE)

$Child_[9] = GUICreate("", 540, 330, 0, 0, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main)
_Form_9($Control_9)
GUISetState(@SW_HIDE)

$Child_[10] = GUICreate("", 540, 330, 0, 0, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main)
_Form_10($Control_10)

GUISetState(@SW_HIDE)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While 1
    $msg = _GUICtrlTVExplorer_GetMsg(1)

    Switch $msg[1]
        Case $Main
            Switch $msg[0]
                Case $GUI_EVENT_CLOSE
                    ExitLoop
                Case $Button_3
                    ExitLoop
                Case $Button_1
                    Set_ChildSwitch(+1)
                Case $Button_2
                    Set_ChildSwitch(-1)
            EndSwitch
        Case $Child_[2]
            Switch $msg[0]
                Case $Control_2[0]
                    $Path = _GUICtrlTVExplorer_GetSelected($hFocus)
                    _GUICtrlTVExplorer_AttachFolder($hFocus)
                    _GUICtrlTVExplorer_Expand($hFocus, $Path, 0)
                    $hFocus = 0
            EndSwitch
    EndSwitch
WEnd

GUIDelete($Main)
;--------- Functions -------------------

Func Set_ChildSwitch($ud)
    GUISetState(@SW_HIDE, $Child_[$ChildActual])
    $ChildActual += $ud
    If $ChildActual = 11 Then $ChildActual = 1
    If $ChildActual = 0 Then $ChildActual = 10
    GUISetState(@SW_SHOW, $Child_[$ChildActual])
EndFunc   ;==>Set_ChildSwitch

Func _Form_1(ByRef $Control_1)
$Control_1[0] = GuiCtrlCreateButton("Button",20,20,40,22)
EndFunc   ;==>_Form_1

Func _Form_2(ByRef $Control_2)
    $Control_2[0] = _GUICtrlTVExplorer_Create(@ProgramFilesDir, 320, 48, 200, 210, -1, $WS_EX_CLIENTEDGE, -1, '_TVEvent')
    $Control_2[1] = GUICtrlCreateDummy()
    HotKeySet('{F5}', '_TVRefresh')
    _GUICtrlTVExplorer_Expand($Control_2[0], @ProgramFilesDir & '\AutoIt3')
    _GUICtrlTVExplorer_Expand($Control_2[0])
    $Control_2[2] = GUICtrlCreateInput("", 320, 20, 200, 20)
EndFunc   ;==>_Form_2

Func _Form_3(ByRef $Control_3)

EndFunc   ;==>_Form_3

Func _Form_4(ByRef $Control_4)

EndFunc   ;==>_Form_4

Func _Form_5(ByRef $Control_5)

EndFunc   ;==>_Form_5

Func _Form_6(ByRef $Control_6)

EndFunc   ;==>_Form_6

Func _Form_7(ByRef $Control_7)

EndFunc   ;==>_Form_7

Func _Form_8(ByRef $Control_8)

EndFunc   ;==>_Form_8

Func _Form_9(ByRef $Control_9)

EndFunc   ;==>_Form_9

Func _Form_10(ByRef $Control_10)

EndFunc   ;==>_Form_10

Func _TVSetPath($iInput, $sPath)
    Local $Text = _WinAPI_PathCompactPath(GUICtrlGetHandle($iInput), $sPath, -2)
    If GUICtrlRead($iInput) <> $Text Then
        GUICtrlSetData($iInput, $Text)
    EndIf
EndFunc   ;==>_TVSetPath

Func _TVRefresh()
    Local $hWnd = _WinAPI_GetFocus()
    If $Control_2[0] = $hWnd Then
        If Not $hFocus Then
            $hFocus = $hWnd
            GUICtrlSendToDummy($Control_2[1])
        EndIf
        Return
    EndIf
    HotKeySet('{F5}')
    Send('{F5}')
    HotKeySet('{F5}', '_TVRefresh')
EndFunc   ;==>_TVRefresh

Func _TVEvent($hWnd, $iMsg, $sPath, $hItem)
    Switch $iMsg
        Case $TV_NOTIFY_BEGINUPDATE
            GUISetCursor(1, 1)
        Case $TV_NOTIFY_ENDUPDATE
            GUISetCursor(2)
        Case $TV_NOTIFY_SELCHANGED
            If $Control_2[0] = $hWnd Then
                _TVSetPath($Control_2[2], $sPath)
            EndIf
        Case $TV_NOTIFY_DBLCLK
        Case $TV_NOTIFY_RCLICK
            ; Nothing
        Case $TV_NOTIFY_DELETINGITEM
            ; Nothing
        Case $TV_NOTIFY_DISKMOUNTED
            ; Nothing
        Case $TV_NOTIFY_DISKUNMOUNTED
            ; Nothing
    EndSwitch
EndFunc   ;==>_TVEvent

Func WM_NOTIFY($hWnd, $iMsg, $iWparam, $iLparam)
    #forceref $iMsg, $iWparam
    Local $hWndFrom, $iCode, $tNMHDR, $tMsgFilter, $hMenu
    $tNMHDR = DllStructCreate($tagNMHDR, $iLparam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $Control_1[0]
            Select
                Case $iCode = $EN_MSGFILTER
                    $tMsgFilter = DllStructCreate($tagEN_MSGFILTER, $iLparam)
                    If DllStructGetData($tMsgFilter, "msg") = $WM_RBUTTONUP Then
                    ;   $hMenu = GUICtrlGetHandle($Control_2[21])
                    ;   SetMenuTexts($hWndFrom, $hMenu)
                    ;   _GUICtrlMenu_TrackPopupMenu($hMenu, $hWnd)
                    EndIf
            EndSelect

    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Be Green Now or Never (BGNN)!

Share this post


Link to post
Share on other sites

Func WM_NOTIFY($hWnd, $iMsg, $iWparam, $iLparam)
    #forceref $iMsg, $iWparam

    ; VERY IMPORTANT!!!
    TV_WM_NOTIFY($hWnd, $iMsg, $iWparam, $iLparam)

    Local $hWndFrom, $iCode, $tNMHDR, $tMsgFilter, $hMenu
    $tNMHDR = DllStructCreate($tagNMHDR, $iLparam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $Control_1[0]
            Select
                Case $iCode = $EN_MSGFILTER
                    $tMsgFilter = DllStructCreate($tagEN_MSGFILTER, $iLparam)
                    If DllStructGetData($tMsgFilter, "msg") = $WM_RBUTTONUP Then
                    ;   $hMenu = GUICtrlGetHandle($Control_2[21])
                    ;   SetMenuTexts($hWndFrom, $hMenu)
                    ;   _GUICtrlMenu_TrackPopupMenu($hMenu, $hWnd)
                    EndIf
            EndSelect

    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY


Share this post


Link to post
Share on other sites

Func WM_NOTIFY($hWnd, $iMsg, $iWparam, $iLparam)
    #forceref $iMsg, $iWparam

    ; VERY IMPORTANT!!!
    TV_WM_NOTIFY($hWnd, $iMsg, $iWparam, $iLparam)

    Local $hWndFrom, $iCode, $tNMHDR, $tMsgFilter, $hMenu
    $tNMHDR = DllStructCreate($tagNMHDR, $iLparam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $Control_1[0]
            Select
                Case $iCode = $EN_MSGFILTER
                    $tMsgFilter = DllStructCreate($tagEN_MSGFILTER, $iLparam)
                    If DllStructGetData($tMsgFilter, "msg") = $WM_RBUTTONUP Then
                    ;   $hMenu = GUICtrlGetHandle($Control_2[21])
                    ;   SetMenuTexts($hWndFrom, $hMenu)
                    ;   _GUICtrlMenu_TrackPopupMenu($hMenu, $hWnd)
                    EndIf
            EndSelect

    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Hi Yashied. Billions of billions thanks For sharing and support! :)

Its took me a one night until I noticed your comment inside the WM_NOTIFY. ;)

; VERY IMPORTANT!!!

TV_WM_NOTIFY($hWnd, $iMsg, $iWparam, $iLparam)


Be Green Now or Never (BGNN)!

Share this post


Link to post
Share on other sites

Yashied,

This is nice mode and I realy like it and I am gona use it in my application.

Until now I tested it on Win XP SP3, windows 2003 and windows 2008 all systems 64 BIT and its worked fine.

A little issue I saw is that when using a background picture utilizing GUICtrlCreatePic() under the control then sometimes but not always, when the tree collapsed the picture overlapped the control.

I disabled the GUICtrlCreatePic control and set the TVExplorer control on top but nothing helped.

Like this:

GUICtrlCreatePic("img_bg.bmp", 0, 0, 700, 736)
GUICtrlSetState(-1, $GUI_DISABLE)

GUICtrlSetState($hTV[0], $GUI_FOCUS)

Be Green Now or Never (BGNN)!

Share this post


Link to post
Share on other sites

I have one more question please.

Is it possible to set a different root folder in the control after creating the control?

Something like detaching the tree and creating it with new root.

EDIT: ActuallyI found how to do it with simple case.

_GUICtrlTreeView_Delete($hTV,  0)
GUICtrlTVExplorer_AttachFolder ( hTV , $sPath)
Edited by lsakizada

Be Green Now or Never (BGNN)!

Share this post


Link to post
Share on other sites

Thanks Yashied for an excellent UDF, I've been sitting here wondering how to get two TreeViews into one GUI and next thing I know...problem solved.

Except I'm having a hard time just displaying a Directory Tree, I assume $TV_FLAG_DIRTREE is the flag I want but it seems to only display some directories and not others.

The code is basically the example with all the parts I didn't need stripped out.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_UseX64=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#Include <GUIConstantsEx.au3>
#Include <GUITreeView.au3>
#Include <TVExplorer.au3>
#Include <TreeViewConstants.au3>
#Include <WindowsConstants.au3>
#Include <WinAPIEx.au3>

Opt('MustDeclareVars', 1)

Global $hForm, $hTV[3], $Input[3], $hFocus = 0, $Dummy, $Path, $Style

If Not _WinAPI_DwmIsCompositionEnabled() Then
    $Style = $WS_EX_COMPOSITED
Else
    $Style = -1
EndIf
$hForm = GUICreate('TVExplorer UDF Example', 700, 340, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX), $Style)
GUISetIcon(@WindowsDir & '\explorer.exe')
$hTV[0] = _GUICtrlTVExplorer_Create('', 20, 20, 320, 310, -1, $WS_EX_CLIENTEDGE, $TV_FLAG_DIRTREE, '_TVEvent')
$hTV[1] = _GUICtrlTVExplorer_Create('', 360, 20, 320, 310, -1, $WS_EX_CLIENTEDGE, $TV_FLAG_DEFAULT, '_TVEvent')
For $i = 0 To 1
    _TVSetPath($Input[$i], _GUICtrlTVExplorer_GetSelected($hTV[$i]))
    _GUICtrlTVExplorer_SetExplorerStyle($hTV[$i])
Next
$Dummy = GUICtrlCreateDummy()
GUISetState()

While 1
    Switch _GUICtrlTVExplorer_GetMsg()
        Case $GUI_EVENT_CLOSE
            GUIDelete()
            _GUICtrlTVExplorer_DestroyAll()
            Exit
        Case $Dummy
            $Path = _GUICtrlTVExplorer_GetSelected($hFocus)
            _GUICtrlTVExplorer_AttachFolder($hFocus)
            _GUICtrlTVExplorer_Expand($hFocus, $Path, 0)
            $hFocus = 0
    EndSwitch
WEnd

Func _TVEvent($hWnd, $iMsg, $sPath, $hItem)
    Switch $iMsg
        Case $TV_NOTIFY_BEGINUPDATE
            GUISetCursor(1, 1)
        Case $TV_NOTIFY_ENDUPDATE
            GUISetCursor(2)
        Case $TV_NOTIFY_SELCHANGED
            For $i = 0 To 2
                If $hTV[$i] = $hWnd Then
                    _TVSetPath($Input[$i], $sPath)
                    ExitLoop
                EndIf
            Next
        Case $TV_NOTIFY_DBLCLK
            ; Nothing
        Case $TV_NOTIFY_RCLICK
            ; Nothing
        Case $TV_NOTIFY_DELETINGITEM
            ; Nothing
        Case $TV_NOTIFY_DISKMOUNTED
            ; Nothing
        Case $TV_NOTIFY_DISKUNMOUNTED
            ; Nothing
    EndSwitch
EndFunc   ;==>_TVEvent

Func _TVSetPath($iInput, $sPath)
    Local $Text = _WinAPI_PathCompactPath(GUICtrlGetHandle($iInput), $sPath, -2)

    If GUICtrlRead($iInput) <> $Text Then
        GUICtrlSetData($iInput, $Text)
    EndIf
EndFunc   ;==>_TVSetPath

Posted Image

What I'd like is the directory tree as per the tree view on the right without files but I can't seem to get it using various combinations of the $TV_FLAG_SHOW* flags.

While I'm using Win7 x64 on my main computer, it also seems to do it on XP Pro SP3 computers I have. It's not just that particular media, (flash drive), either it happens across all my hard drives, ie. some directory structures are there and some don't expand even though I know they go 1 or more levels deep.

So any help getting just a directory tree view that displays all (sub-)directories would be much appreciated.

TVExplorer v1.1

WinAPIEx v3.2

AutoIt v3.3.6.1

Thank you again for a really good UDF.

Share this post


Link to post
Share on other sites

Yashied,

Is it a possible to extract the code from the UDF to get the file's associated icon?

I have been looking around and most of the code that I have seen in the forums was not detected all icons associated with the files on my system.

Apparently that your code is doing it properly.

BTW: I realy like your coding.

Regards!

EDIT: OOOPSS: I just so this link and its works for me.

Edited by lsakizada

Be Green Now or Never (BGNN)!

Share this post


Link to post
Share on other sites

Yasheid,

I had posted a question a couple of weeks ago on the thread about On The Fly TreeViews in the hope that you would see it. But Melba23 suggested that I might want to bring it up on this active thread ... so, my question was this:

I've explored the examples you pointed to and also explored the tree view examples in help. I quickly found that I was reading too much "directory tree" into the purpose and functions of tree views. ... But before I abandon my idea, I wanted to show exactly what I was trying for and ask: is this impossible in a simple script?

Can you suggest a way? I seems to me that many would find this enhanced "on the fly" view useful.

post-29172-0-65407400-1299093103_thumb.p

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

Look at the example for _WinAPI_ShellExtractAssociatedIcon() function from library.

Yashied, thank you very much. I learn the example and implemented it into my application.

Just one thing notice that some icons are displayed properly with your TVExplorer control while the example could not display it well.

for example the link extension (.lnk) display as the windows not found icon.

cheers!


Be Green Now or Never (BGNN)!

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

If you specify just ".lnk" extension, of course the icons will not be (nowhere to take). But if you specify the full path to the ".lnk" file, everything will be OK.

I specify a full path and the example are also using full path to the .ink icon. So i guess its not the issue.

Yashied. I have just ran the example on win 2008. The tree item were unable to be expand and some icons shown on the screen are black.

See the picture.

http://img145.imageshack.us/i/tvexpwin2008.jpg


Be Green Now or Never (BGNN)!

Share this post


Link to post
Share on other sites

You are using 16-bit color depth? OK, replace the _WinAPI_AddIconTransparency() function in WinAPIEx.au3 or wait until I update it.

Thanks.

Func _WinAPI_AddIconTransparency($hIcon, $iPercent = 50, $fDelete = 0)

    Local $tICONINFO, $tBIHDR, $tBITMAP, $W, $H, $Ret, $iByte, $tBits, $pBits, $hResult = 0
    Local $hBitmap[2]

    $tICONINFO = DllStructCreate($tagICONINFO)
    $Ret = DllCall('user32.dll', 'int', 'GetIconInfo', 'ptr', $hIcon, 'ptr', DllStructGetPtr($tICONINFO))
    If (@error) Or (Not $Ret[0]) Then
        Return SetError(1, 0, 0)
    EndIf
    For $i = 0 To 1
        $hBitmap[$i] = DllStructGetData($tICONINFO, $i + 4)
    Next
    Do
        $tBITMAP = DllStructCreate($tagBITMAP)
        If Not _WinAPI_GetObject($hBitmap[1], DllStructGetSize($tBITMAP), DllStructGetPtr($tBITMAP)) Then
            ExitLoop
        EndIf
        $W = DllStructGetData($tBITMAP, 'bmWidth')
        $H = DllStructGetData($tBITMAP, 'bmHeight')
        $iByte = $W * $H * 4
        $tBits = DllStructCreate('byte[' & $iByte & ']')
        $pBits = DllStructGetPtr($tBits)
        If _WinAPI_GetBitmapBits($hBitmap[1], $iByte, $pBits) <> $iByte Then
            ExitLoop
        EndIf
        For $i = 1 To $iByte Step 4
            DllStructSetData($tBits, 1, DllStructGetData($tBits, 1, $i + 3) * $iPercent / 100, $i + 3)
        Next
        _WinAPI_DeleteObject($hBitmap[1])
        $tBIHDR = DllStructCreate($tagBITMAPINFOHEADER)
        DllStructSetData($tBIHDR, 'biSize', DllStructGetSize($tBIHDR))
        DllStructSetData($tBIHDR, 'biWidth', $W)
        DllStructSetData($tBIHDR, 'biHeight', $H)
        DllStructSetData($tBIHDR, 'biPlanes', 1)
        DllStructSetData($tBIHDR, 'biBitCount', 32)
        DllStructSetData($tBIHDR, 'biCompression', $BI_RGB)
        $hBitmap[1] = _WinAPI_CreateDIBSection(0, $tBIHDR, $DIB_RGB_COLORS, $Ret)
        If @error Then
            ExitLoop
        EndIf
        If _WinAPI_SetBitmapBits($hBitmap[1], $iByte, $pBits) <> $iByte Then
            ExitLoop
        EndIf
        $hResult = _WinAPI_CreateIconIndirect($hBitmap[1], $hBitmap[0])
    Until 1
    For $i = 0 To 1
        If $hBitmap[$i] Then
            _WinAPI_DeleteObject($hBitmap[$i])
        EndIf
    Next
    If Not $hResult Then
        Return SetError(1, 0, 0)
    EndIf
    If $fDelete Then
        _WinAPI_DestroyIcon($hIcon)
    EndIf
    Return $hResult
EndFunc   ;==>_WinAPI_AddIconTransparency

Share this post


Link to post
Share on other sites

You are using 16-bit color depth? OK, replace the _WinAPI_AddIconTransparency() function in WinAPIEx.au3 or wait until I update it.

Thanks.

Func _WinAPI_AddIconTransparency($hIcon, $iPercent = 50, $fDelete = 0)

    Local $tICONINFO, $tBIHDR, $tBITMAP, $W, $H, $Ret, $iByte, $tBits, $pBits, $hResult = 0
    Local $hBitmap[2]

    $tICONINFO = DllStructCreate($tagICONINFO)
    $Ret = DllCall('user32.dll', 'int', 'GetIconInfo', 'ptr', $hIcon, 'ptr', DllStructGetPtr($tICONINFO))
    If (@error) Or (Not $Ret[0]) Then
        Return SetError(1, 0, 0)
    EndIf
    For $i = 0 To 1
        $hBitmap[$i] = DllStructGetData($tICONINFO, $i + 4)
    Next
    Do
        $tBITMAP = DllStructCreate($tagBITMAP)
        If Not _WinAPI_GetObject($hBitmap[1], DllStructGetSize($tBITMAP), DllStructGetPtr($tBITMAP)) Then
            ExitLoop
        EndIf
        $W = DllStructGetData($tBITMAP, 'bmWidth')
        $H = DllStructGetData($tBITMAP, 'bmHeight')
        $iByte = $W * $H * 4
        $tBits = DllStructCreate('byte[' & $iByte & ']')
        $pBits = DllStructGetPtr($tBits)
        If _WinAPI_GetBitmapBits($hBitmap[1], $iByte, $pBits) <> $iByte Then
            ExitLoop
        EndIf
        For $i = 1 To $iByte Step 4
            DllStructSetData($tBits, 1, DllStructGetData($tBits, 1, $i + 3) * $iPercent / 100, $i + 3)
        Next
        _WinAPI_DeleteObject($hBitmap[1])
        $tBIHDR = DllStructCreate($tagBITMAPINFOHEADER)
        DllStructSetData($tBIHDR, 'biSize', DllStructGetSize($tBIHDR))
        DllStructSetData($tBIHDR, 'biWidth', $W)
        DllStructSetData($tBIHDR, 'biHeight', $H)
        DllStructSetData($tBIHDR, 'biPlanes', 1)
        DllStructSetData($tBIHDR, 'biBitCount', 32)
        DllStructSetData($tBIHDR, 'biCompression', $BI_RGB)
        $hBitmap[1] = _WinAPI_CreateDIBSection(0, $tBIHDR, $DIB_RGB_COLORS, $Ret)
        If @error Then
            ExitLoop
        EndIf
        If _WinAPI_SetBitmapBits($hBitmap[1], $iByte, $pBits) <> $iByte Then
            ExitLoop
        EndIf
        $hResult = _WinAPI_CreateIconIndirect($hBitmap[1], $hBitmap[0])
    Until 1
    For $i = 0 To 1
        If $hBitmap[$i] Then
            _WinAPI_DeleteObject($hBitmap[$i])
        EndIf
    Next
    If Not $hResult Then
        Return SetError(1, 0, 0)
    EndIf
    If $fDelete Then
        _WinAPI_DestroyIcon($hIcon)
    EndIf
    Return $hResult
EndFunc   ;==>_WinAPI_AddIconTransparency

Cool! its working now with 16 and 32 BIT color.

At the beginning I thought its about the OS, now I am happy that I do not have to revert the code :) (just kidding).

Let me know If you need me to retest it on any combination that you would use it.

I have almost anything at work.

Edited by lsakizada

Be Green Now or Never (BGNN)!

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • By Burgs
      Hello,
        I am having great difficulty with something I would have thought to be fairly easy.  I have an array containing (military) organization strings, similar to this:
      42nd Battalion
       Company A
        1st Platoon
         1st Squad
         2nd Squad
         3rd Squad
        2nd Platoon
         ...1st, 2nd, 3rd Squad
        3rd Platoon
        ...1st, 2nd, 3rd Squad
       Company B
        ...etc...
      I also have an associated array that contains the 'hierarchy' information associated with each string..."0", "1","2", etc   ...therefore using example above the "0" would associate with "42nd Battalion", while "1" would be "Company A", "2" is "1st Platoon", etc.  Each sequential number is a 'child' of the preceding number.  Therefore the information above would appear in the array as "0", "1", "2", "3", "3", "3", "2", "3", "3", "3", "2", "3", "3", "3", "1", etc...
        My issue is that I'm having great difficulty creating a 'Treeview' control using this information.  Mainly due to the fact that entries can, and will...repeat (for example multiple entries for "Company A", "Company B", "1st Platoon", "1st Squad", etc, etc).  The following code is operative, however it does not create the treeview items as 'child' entries of one another...it simply lists each item as a separate entity.
      For $_populate = 0 to Ubound($_HIERARCHY) - 1 _GUICtrlTreeView_BeginUpdate($idTreeView) _GUICtrlTreeView_Add($idTreeView, $_HIERARCHY[$_populate], String($_STRUCTURES[$_populate])) _GUICtrlTreeView_EndUpdate($idTreeView) Next ;Next $_populate, cycle thru '$_HIERARCHY' array to build 'TREEVIEW' Controls As I mentioned earlier I thought I could manage this...however i'm pulling out quite a bit of my hair trying to get this working properly...any help would be appreciated.  I thank you in advance. 
       
    • By xtcislove
      Hello,
      i stuck again,
      Im using this function to create a treeview from root dir.
       
      ;https://autoit.de/index.php?thread/86082-treeview-root-verbergen/&postID=691139#post691139 #include <File.au3> #include <WindowsConstants.au3> Global $sPath = @ScriptDir Global $hGui = GUICreate('TreeView-Example', 400, 600) Global $idTreeView = GUICtrlCreateTreeView(10, 10, 380, 580, Default, $WS_EX_CLIENTEDGE) GUISetState() _CreatePath($sPath, $idTreeView) Do Until GUIGetMsg() = -3 Func _CreatePath($sPath, $idParent) Local $aFolder, $aFiles, $idItem If StringRight($sPath, 1) <> '\' Then $sPath &= '\' $aFolder = _FileListToArray($sPath, '*', $FLTA_FOLDERS) If Not @error Then For $i = 1 To $aFolder[0] $idItem = GUICtrlCreateTreeViewItem($aFolder[$i], $idParent) _CreatePath($sPath & $aFolder[$i], $idItem) Next EndIf $aFiles = _FileListToArray($sPath, '*', $FLTA_FILES) If @error Then Return For $i = 1 To $aFiles[0] $idItem = GUICtrlCreateTreeViewItem($aFiles[$i], $idParent) Next EndFunc Folder Structure:

      Folder1
      Folder2
      Folder3
      If a file exists in multiple folders, i like to color it red, if not green. 

      I know how to do this for files, but nut for the folders.

      Because if there is only 1 file in Folder2 that is also in Folder1 that it should only color this single file red, inlcuding its whole tree.

      The Folder1 and Folder2 should be red in this case, too. Other files and trees should stay green.
       
      Edit:
      Basically i like to color a file and its belonging tree red if the file exists more than 1 time.
    • By xtcislove
      Hello,

      im searching like 6 hours and i didnt found the right solution.

      Im trying to build a treeview from a directory and its subfolders etc.

      This function give me right treeview, but i cant color each item seperated.

       
      #include <GuiTreeView.au3> $hGui = GUICreate("Demo1", 600, 400) $hTreeView = _GUICtrlTreeView_Create($hGui, 10, 10, 580, 380) GUISetState() _GUICtrlTreeView_BeginUpdate($hTreeView) ListFiles_ToTreeView(@ScriptDir, 0) _GUICtrlTreeView_EndUpdate($hTreeView) Do Until GUIGetMsg() = -3 Func ListFiles_ToTreeView($sSourceFolder, $hItem) Local $sFile ; Force a trailing \ If StringRight($sSourceFolder, 1) <> "\" Then $sSourceFolder &= "\" ; Start the search Local $hSearch = FileFindFirstFile($sSourceFolder & "*.*") ; If no files found then return If $hSearch = -1 Then Return ; This is where we break the recursive loop <<<<<<<<<<<<<<<<<<<<<<<<<< ; Now run through the contents of the folder While 1 ; Get next match $sFile = FileFindNextFile($hSearch) ; If no more files then close search handle and return If @error Then ExitLoop ; This is where we break the recursive loop <<<<<<<<<<<<<<<<<<<<<<<<<< ; Check if a folder If @extended Then ; If so then call the function recursively ListFiles_ToTreeView($sSourceFolder & $sFile, _GUICtrlTreeView_AddChild($hTreeView, $hItem, $sFile)) Else ; If a file than write path and name _GUICtrlTreeView_AddChild($hTreeView, $hItem, $sFile) EndIf WEnd ; Close search handle FileClose($hSearch) EndFunc ;==>ListFiles_ToTreeView
      So i am searching for the exact same function just with
      GUICtrlCreateTreeViewItem
      instead of 
      _GUICtrlTreeView_AddChild
       
      Ps: i have a folder structure where i like to color each item green if a file only exist once and red if it exist more than once.

      Could someone help?
       
      Solution:

       
       
    • By Sven-Seyfert
      Hi Community,

      I have a problem with the usage of _GUICtrlTreeView_AddChild and setting different item text colors (and different background colors), separately for the TreeView levels.

      I use the UDF GUITreeViewEx.au3 of 'Melba23' and I renamed the functions to increase my understanding about the content. I already talked to him about his UDF to respect his rights and intellectual property. I read many forum threads, I tried many ways to get it, but it's seems to be impossible in the way that I use the UDF.

      Question:
      How can I set different item text colors, separately for the TreeView levels?
      How can I set different item background colors, separately for the TreeView levels?

      I found out that _GUICtrlTreeView_AddChild don't let my set this properties directly. But after loading the TreeView content I can't change the items (children) too. Only the font weight to bold I could set with _GUICtrlTreeView_SetBold but I want to do this in a generic way directly at the creation (loading) of the TreeView.

      Of course I tried the different functions to set text color or bkgColor, but it didn't work - maybe I do it wrong.
      I really hope you can help me, give me a hint and understand what I want to do.
      [Solved] final solution made by @LarsJ (see below)

      Thanks for your help - I'm grateful!
      Sven

      CODE
      BEFORE
      AFTER
      ExecutionPlan.zip
    • By gillesg
      Hello,
      I am struggling in merging GUITreeViewEx, Shelltristate and enhancing to handle a third state that means : some items under are selected.
      I have difficulties handling expand order and key Space (especially when node is collapsed).
      Here the zip with UDF and and example.
       
      The problem I might need some advice to handle : 
      1- When load Treeview, have a correct settings of the checkbox for a tristate tree
      2 - Handle keyboard used for walking in tree
           Chicken is checked and  Steak is unchecked
          When walking with arrow to Meat, it gets unchecked
      3 - When node is collapsed and checked thru keyboard (space)
         the middle state is possible which should not
      Here is joined an animated gif showing the 3 problems
       
      Thanks for your advices
       
       
       
       
       
       
       
       
       
       
       

      GUITreeview3Ex.zip
×
×
  • Create New...