Sign in to follow this  
Followers 0
momitty

Pop "_GUICtrlTreeView_CreateDragImage" out of tree?

1 post in this topic

_GUICtrlTreeView_CreateDragImage makes a cool little copy of the item i'm dragging around... but I need to find a way to make it drag outside of the TreeView object. Does anybody know how to do this?

I'm just using the code straight out of the CHM help file.

#include <GuiConstantsEx.au3>
#include <GuiTreeView.au3>
#include <GuiImageList.au3>
#include <WinAPI.au3>

Opt('MustDeclareVars', 1)

$Debug_TV = False; Check ClassName being passed to functions, set to True and use a handle to another control to see it work

Example_Internal()
Example_External()

Func Example_Internal()

    Local $GUI, $hItemChild, $hImage, $iImage, $hItem, $fDragging = False, $aDrag, $hTreeView
    Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)
    
    $GUI = GUICreate("(Internal) TreeView Create Drage Image", 400, 300)
    $hTreeView = GUICtrlGetHandle(GUICtrlCreateTreeView(2, 2, 396, 268, $iStyle, $WS_EX_CLIENTEDGE))
    
    _GUICtrlTreeView_SetUnicodeFormat ($hTreeView, False)
    GUISetState()

   ; Load images
    $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)
    _GUIImageList_Add ($hImage, _GUICtrlTreeView_CreateSolidBitMap ($hTreeView, 0xFF0000, 16, 16))
    _GUIImageList_Add ($hImage, _GUICtrlTreeView_CreateSolidBitMap ($hTreeView, 0x00FF00, 16, 16))
    _GUIImageList_Add ($hImage, _GUICtrlTreeView_CreateSolidBitMap ($hTreeView, 0x0000FF, 16, 16))
    _GUICtrlTreeView_SetNormalImageList ($hTreeView, $hImage)

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

   ; Loop until user exits
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_MOUSEMOVE
                If $fDragging Then DrawDragImage($hTreeView, $aDrag)
                
            Case $GUI_EVENT_PRIMARYDOWN
                Local $hSelected = _GUICtrlTreeView_GetSelection ($hTreeView)
                If $hSelected Then
                    $fDragging = True
                   ; Create drag image
                    $aDrag = _GUICtrlTreeView_CreateDragImage ($hTreeView, $hSelected)
                    DrawDragImage($hTreeView, $aDrag)
                EndIf
                
            Case $GUI_EVENT_PRIMARYUP
                If $fDragging Then
                    $fDragging = False
                   ; delete image list
                    _GUIImageList_Destroy ($aDrag)
                    _WinAPI_InvalidateRect ($hTreeView)
                    _WinAPI_InvalidateRect (HWnd($GUI))
                EndIf
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
    GUIDelete()
EndFunc  ;==>Example_Internal

Func Example_External()

    Local $GUI, $hItemChild, $hImage, $iImage, $hItem, $fDragging = False, $aDrag, $hTreeView
    Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)
    
    $GUI = GUICreate("(External) TreeView Create Drage Image", 400, 300)

    $hTreeView = _GUICtrlTreeView_Create ($GUI, 2, 2, 396, 268, $iStyle, $WS_EX_WINDOWEDGE)
    GUISetState()

   ; Load images
    $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)
    _GUIImageList_Add ($hImage, _GUICtrlTreeView_CreateSolidBitMap ($hTreeView, 0xFF0000, 16, 16))
    _GUIImageList_Add ($hImage, _GUICtrlTreeView_CreateSolidBitMap ($hTreeView, 0x00FF00, 16, 16))
    _GUIImageList_Add ($hImage, _GUICtrlTreeView_CreateSolidBitMap ($hTreeView, 0x0000FF, 16, 16))
    _GUICtrlTreeView_SetNormalImageList ($hTreeView, $hImage)

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

   ; Loop until user exits
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_MOUSEMOVE
                If $fDragging Then DrawDragImage($hTreeView, $aDrag)
                
            Case $GUI_EVENT_PRIMARYDOWN
                Local $hSelected = _GUICtrlTreeView_GetSelection ($hTreeView)
                If $hSelected Then
                    $fDragging = True
                   ; Create drag image
                    $aDrag = _GUICtrlTreeView_CreateDragImage ($hTreeView, $hSelected)
                    DrawDragImage($hTreeView, $aDrag)
                EndIf
                
            Case $GUI_EVENT_PRIMARYUP
                If $fDragging Then
                    $fDragging = False
                   ; delete image list
                    _GUIImageList_Destroy ($aDrag)
                    _WinAPI_InvalidateRect ($hTreeView)
                    _WinAPI_InvalidateRect (HWnd($GUI))
                EndIf
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
    GUIDelete()
EndFunc  ;==>Example_External

; Draw drag image
Func DrawDragImage(ByRef $hControl, ByRef $aDrag)
    Local $tPoint, $hDC
    $hDC = _WinAPI_GetWindowDC ($hControl)
    $tPoint = _WinAPI_GetMousePos (True, $hControl)
    _WinAPI_InvalidateRect ($hControl)
    _GUIImageList_Draw ($aDrag, 0, $hDC, DllStructGetData($tPoint, "X"), DllStructGetData($tPoint, "Y"))
    _WinAPI_ReleaseDC ($hControl, $hDC)
EndFunc  ;==>DrawDragImage

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  
Followers 0