Jump to content

Bbackground GUI picture overlaps TreeVew Control problem


lsakizada
 Share

Recommended Posts

Hi,

I am using picture as background for a GUI that contain treeview control.

when expanding the root's children's items tree down to the last children and clicking back on the [-] sign next to the root item, then the all picture overlap the tree. It is looks bad and I want to know how to avoid that mess.

How to reproduce the issue.

1) Create a rectangle bmp picture with mspaint.exe and save it as 'image.bmp' under the scripts folder.

(fill that picture with any color.)

2) Run the code bellow

3) Click on the [+] sign next to the the most top root item ("[01] New Item")

4) Click on the first chiled item ("[01] New Chiled") or any others untill the vertical scroll bar appears

5) Click on the Root

If that steps does not reveal the issue then expand randomly the children but always keep in mind to hit the root at end of the steps where the scroll bar available.

here is the code (Taken from the help file):

#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GuiConstantsEx.au3>
#include <GuiTreeView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)
Global $PIC_GUI_3 = @ScriptDir & '\image.bmp'
$Debug_TV = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work

Global $hTreeView

_Main()

Func _Main()

    Local $hItem, $hImage, $iImage
    Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)
    
    GUICreate("TreeView Click Item", 500, 400)
    GUICtrlCreatePic($PIC_GUI_3,0,0,500,400)
    GUICtrlSetState(-1, $GUI_DISABLE)
    
    
    
    $hTreeView = GUICtrlCreateTreeView(2, 2, 396, 268, $iStyle, $WS_EX_CLIENTEDGE)
    GUISetState()

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    $hImage = _GUIImageList_Create(16, 16, 5, 3)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 110)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 131)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 165)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 168)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 137)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 146)
    _GUICtrlTreeView_SetNormalImageList($hTreeView, $hImage)

    _GUICtrlTreeView_BeginUpdate($hTreeView)
    For $x = 1 To Random(2, 10, 1)
        $iImage = Random(0, 5, 1)
        $hItem = _GUICtrlTreeView_Add($hTreeView, 0, StringFormat("[%02d] New Item", $x), $iImage, $iImage)
        For $y = 1 To Random(2, 10, 1)
            $iImage = Random(0, 5, 1)
            _GUICtrlTreeView_AddChild($hTreeView, $hItem, StringFormat("[%02d] New Child", $y), $iImage, $iImage)
        Next
    Next
    _GUICtrlTreeView_EndUpdate($hTreeView)

    _GUICtrlTreeView_ClickItem($hTreeView, $hItem, "left", False, 2)

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview
    $hWndTreeview = $hTreeView
    If Not IsHWnd($hTreeView) Then $hWndTreeview = GUICtrlGetHandle($hTreeView)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndTreeview
            Switch $iCode
                Case $NM_CLICK ; The user has clicked the left mouse button within the control
                    _DebugPrint("$NM_CLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
;~                  Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
                Case $NM_DBLCLK ; The user has double-clicked the left mouse button within the control
                    _DebugPrint("$NM_DBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
;~                  Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
                Case $NM_RCLICK ; The user has clicked the right mouse button within the control
                    _DebugPrint("$NM_RCLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
;~                  Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
                Case $NM_RDBLCLK ; The user has clicked the right mouse button within the control
                    _DebugPrint("$NM_RDBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
;~                  Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _DebugPrint($s_text, $line = @ScriptLineNumber)
    ConsoleWrite( _
            "!===========================================================" & @LF & _
            "+======================================================" & @LF & _
            "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _
            "+======================================================" & @LF)
EndFunc   ;==>_DebugPrint

Be Green Now or Never (BGNN)!

Link to comment
Share on other sites

Hi,

I am using picture as background for a GUI that contain treeview control.

when expanding the root's children's items tree down to the last children and clicking back on the [-] sign next to the root item, then the all picture overlap the tree. It is looks bad and I want to know how to avoid that mess.

How to reproduce the issue.

1) Create a rectangle bmp picture with mspaint.exe and save it as 'image.bmp' under the scripts folder.

(fill that picture with any color.)

2) Run the code bellow

3) Click on the [+] sign next to the the most top root item ("[01] New Item")

4) Click on the first chiled item ("[01] New Chiled") or any others untill the vertical scroll bar appears

5) Click on the Root

If that steps does not reveal the issue then expand randomly the children but always keep in mind to hit the root at end of the steps where the scroll bar available.

Use WS_CLIPSIBLINGS or/and $WS_EX_COMPOSITED styles

The control order matters, especially with WS_EX_COMPOSITED

#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GuiConstantsEx.au3>
#include <GuiTreeView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>

Opt('MustDeclareVars', 1)
Global $PIC_GUI_3 = @ScriptDir & '\image.bmp'
$Debug_TV = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work

Global $hTreeView

_Main()

Func _Main()

    Local $hItem, $hImage, $iImage
    Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)


    GUICreate("TreeView Click Item", 500, 400) ;, -1, -1, -1, $WS_EX_COMPOSITED)
    $hTreeView = GUICtrlCreateTreeView(2, 2, 396, 268, $iStyle, $WS_EX_CLIENTEDGE)
    GUICtrlCreatePic($PIC_GUI_3,0,0,500,400, BitOR($GUI_SS_DEFAULT_PIC, $WS_CLIPSIBLINGS))
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUISetState()

;or
;~  GUICreate("TreeView Click Item", 500, 400, -1, -1, -1, $WS_EX_COMPOSITED)
;~     $hTreeView = GUICtrlCreateTreeView(2, 2, 396, 268, $iStyle, $WS_EX_CLIENTEDGE)
;~  GUICtrlCreatePic($PIC_GUI_3,0,0,500,400)
;~     GUICtrlSetState(-1, $GUI_DISABLE)
;~     GUISetState()


;or use both WS_EX_COMPOSITED double buffering in GUICreate() and WS_CLIPSIBLINGS in GUICtrlCreatePic()


    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    $hImage = _GUIImageList_Create(16, 16, 5, 3)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 110)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 131)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 165)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 168)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 137)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 146)
    _GUICtrlTreeView_SetNormalImageList($hTreeView, $hImage)

    _GUICtrlTreeView_BeginUpdate($hTreeView)
    For $x = 1 To Random(4, 10, 1)
        $iImage = Random(0, 5, 1)
        $hItem = _GUICtrlTreeView_Add($hTreeView, 0, StringFormat("[%02d] New Item", $x), $iImage, $iImage)
        For $y = 1 To Random(2, 10, 1)
            $iImage = Random(0, 5, 1)
            _GUICtrlTreeView_AddChild($hTreeView, $hItem, StringFormat("[%02d] New Child", $y), $iImage, $iImage)
        Next
    Next
    _GUICtrlTreeView_EndUpdate($hTreeView)

    _GUICtrlTreeView_ClickItem($hTreeView, $hItem, "left", False, 2)

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview
    $hWndTreeview = $hTreeView
    If Not IsHWnd($hTreeView) Then $hWndTreeview = GUICtrlGetHandle($hTreeView)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndTreeview
            Switch $iCode
                Case $NM_CLICK ; The user has clicked the left mouse button within the control
                    _DebugPrint("$NM_CLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
;~                  Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
                Case $NM_DBLCLK ; The user has double-clicked the left mouse button within the control
                    _DebugPrint("$NM_DBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
;~                  Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
                Case $NM_RCLICK ; The user has clicked the right mouse button within the control
                    _DebugPrint("$NM_RCLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
;~                  Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
                Case $NM_RDBLCLK ; The user has clicked the right mouse button within the control
                    _DebugPrint("$NM_RDBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
;~                  Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _DebugPrint($s_text, $line = @ScriptLineNumber)
    ConsoleWrite( _
            "!===========================================================" & @LF & _
            "+======================================================" & @LF & _
            "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _
            "+======================================================" & @LF)
EndFunc   ;==>_DebugPrint
Edited by rover

I see fascists...

Link to comment
Share on other sites

Rover thanks.

Its solved the example that I posted. BUT, its does not solved on my environment.

I tried to simplify my case but now I know I that will need more help... :)

here is another simulated environment but with chiled windows, each on top others.

I am appreciate your help!

To run the script you will need two UDFs:

1)

2)

#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


Global $PIC_GUI_3 = @ScriptDir & '\image.bmp'

$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)
Global $PICA=GUICtrlCreatePic($PIC_GUI_3,0,0,540,330, BitOR($GUI_SS_DEFAULT_PIC, $WS_CLIPSIBLINGS))
GUICtrlSetState(-1, $GUI_DISABLE)
;GUICtrlSetState(-1, $GUI_ONTOP)
_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
    
        ; 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

Be Green Now or Never (BGNN)!

Link to comment
Share on other sites

I can not reproduce this problem. Works fine for me.

The steps are: Going from the root to last children until the VERTICAL SCROLL BAR appears.

Once the scroll bar appears, click on the root item minus sign [-]. good to hear from you again :)

By the way: here is my picture. Anything to do with my pic?

InetGet("http://img263.imageshack.us/img263/4990/imgbg.png", @ScriptDir & "\imgbg.png", 1, 1)

(The png needs to be converted to bmp) Edited by lsakizada

Be Green Now or Never (BGNN)!

Link to comment
Share on other sites

Like I said, this is a problem in GUICtrlCreateTreeView(). I do not know why it happens but you can avoid this by using _WinAPI_SetParent() function (see example).

#Include <File.au3>
#Include <GUIConstantsEx.au3>
#Include <GUIImageList.au3>
#Include <GUITreeView.au3>
#Include <TreeViewConstants.au3>
#Include <WindowsConstants.au3>

Global Const $sRoot = 'C:\Program Files\AutoIt3'

$hForm = GUICreate('MyGUI', 300, 300)
$Pic = GUICtrlCreatePic('image.bmp', 0, 0, 300, 300)
GUICtrlCreateTreeView(20, 20, 260, 260, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
$hTreeView = GUICtrlGetHandle(-1)

_WinAPI_SetParent($hTreeView, GUICtrlGetHandle($Pic))

$hImageList = _GUIImageList_Create(16, 16, 5, 1)
_GUIImageList_AddIcon($hImageList, @SystemDir & '\shell32.dll', 3)
_GUIImageList_AddIcon($hImageList, @SystemDir & '\shell32.dll', 0)
_GUICtrlTreeView_SetNormalImageList($hTreeView, $hImageList)
_GUICtrlTreeView_BeginUpdate($hTreeView)
_EnumDir($hTreeView, $sRoot)
_GUICtrlTreeView_SetState($hTreeView, _GUICtrlTreeView_GetFirstItem($hTreeView), $TVIS_EXPANDED, 1)
_GUICtrlTreeView_EndUpdate($hTreeView)

GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func _EnumDir($hWnd, $sRoot, $hItem = 0)

    Local $hSubItem, $sItem, $aList

    $sRoot = StringRegExpReplace($sRoot, '\\+\Z', '')
    $sItem = StringRegExpReplace($sRoot, '^.*\\', '')
    If StringRight($sItem, 1) = ':' Then
        $sItem &= '\'
    EndIf
    $hSubItem = _GUICtrlTreeView_AddChild($hWnd, $hItem, $sItem, 0, 0)
    $aList = _FileListToArray($sRoot, '*', 2)
    If Not @error Then
        For $i = 1 To $aList[0]
            _EnumDir($hWnd, $sRoot & '\' & $aList[$i], $hSubItem)
        Next
    EndIf
    $aList = _FileListToArray($sRoot, '*', 1)
    If Not @error Then
        For $i = 1 To $aList[0]
            _GUICtrlTreeView_AddChild($hWnd, $hSubItem, $aList[$i], 1, 1)
        Next
    EndIf
EndFunc   ;==>_EnumDir
Edited by Yashied
Link to comment
Share on other sites

Like I said, this is a problem in GUICtrlCreateTreeView(). I do not know why it happens but you can avoid this by using _WinAPI_SetParent() function (see example).

#Include <File.au3>
#Include <GUIConstantsEx.au3>
#Include <GUIImageList.au3>
#Include <GUITreeView.au3>
#Include <TreeViewConstants.au3>
#Include <WindowsConstants.au3>

Global Const $sRoot = 'C:\Program Files\AutoIt3'

$hForm = GUICreate('MyGUI', 300, 300)
$Pic = GUICtrlCreatePic('image.bmp', 0, 0, 300, 300)
GUICtrlCreateTreeView(20, 20, 260, 260, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
$hTreeView = GUICtrlGetHandle(-1)

_WinAPI_SetParent($hTreeView, GUICtrlGetHandle($Pic))

$hImageList = _GUIImageList_Create(16, 16, 5, 1)
_GUIImageList_AddIcon($hImageList, @SystemDir & '\shell32.dll', 3)
_GUIImageList_AddIcon($hImageList, @SystemDir & '\shell32.dll', 0)
_GUICtrlTreeView_SetNormalImageList($hTreeView, $hImageList)
_GUICtrlTreeView_BeginUpdate($hTreeView)
_EnumDir($hTreeView, $sRoot)
_GUICtrlTreeView_SetState($hTreeView, _GUICtrlTreeView_GetFirstItem($hTreeView), $TVIS_EXPANDED, 1)
_GUICtrlTreeView_EndUpdate($hTreeView)

GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func _EnumDir($hWnd, $sRoot, $hItem = 0)

    Local $hSubItem, $sItem, $aList

    $sRoot = StringRegExpReplace($sRoot, '\\+\Z', '')
    $sItem = StringRegExpReplace($sRoot, '^.*\\', '')
    If StringRight($sItem, 1) = ':' Then
        $sItem &= '\'
    EndIf
    $hSubItem = _GUICtrlTreeView_AddChild($hWnd, $hItem, $sItem, 0, 0)
    $aList = _FileListToArray($sRoot, '*', 2)
    If Not @error Then
        For $i = 1 To $aList[0]
            _EnumDir($hWnd, $sRoot & '\' & $aList[$i], $hSubItem)
        Next
    EndIf
    $aList = _FileListToArray($sRoot, '*', 1)
    If Not @error Then
        For $i = 1 To $aList[0]
            _GUICtrlTreeView_AddChild($hWnd, $hSubItem, $aList[$i], 1, 1)
        Next
    EndIf
EndFunc   ;==>_EnumDir

Yashied! You are the master! Thank you so much. its solved.

Well the _WinAPI_SetParent() did the matter. It was not worked for me at the beginning until I've expirience it.

So I am please to share my expirience for others.

The order of using pic control under treeview should be in this order.

GuiCreate()
GUICtrlCreateTreeView()
$PIC_CONTROL=GUICtrlCreatePic()
_WinAPI_SetParent($hTreeView, GUICtrlGetHandle($PIC_CONTROL))
..
other controls

The pic control should be set with the style $WS_CLIPSIBLINGS

Important: Do not disable the pic control by using: GUICtrlSetState(PIC_CONTROL,$GUI_DISABLE).

Here is the example above working:

#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


;Local $hDownload = InetGet("http://img263.imageshack.us/img263/4990/imgbg.png", @ScriptDir & "\imgbg.png", 1, 1)


Global $PIC_GUI_3 = @ScriptDir & '\X.bmp'

$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)

;GUICtrlSetState(-1, $GUI_ONTOP)
_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')
    $hTreeView = GUICtrlGetHandle($Control_2[0])
    $PICA = GUICtrlCreatePic($PIC_GUI_3, 0, 0, 540, 330, $WS_CLIPSIBLINGS)
    ;
    _WinAPI_SetParent($hTreeView, GUICtrlGetHandle($PICA))
    
    
    $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

    ; 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
Edited by lsakizada

Be Green Now or Never (BGNN)!

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...