Page 1 sur 1

Drag & Drop

Posté : mar. 01 août 2017 10:43
par Nicoloquinte
Bonjour , j'espere que ma question est un peut moins exaspérante cette fois-ci :mrgreen:

Et bien voila , j'ai un ensemble de controles simples devant accpter des fichiers en Drag&Drop , jusque la , je m'en sort bien avec $WS_EX_ACCEPTFILES :mrgreen:

mais la ou j'ai un petit problème c'est que j'aimerai inclure cette fonctionnalité a un treeview (liste de fichiers avec dossiers parrents), et donc, quand je glisse un fichier au dessu du treeview , et que je le lache , faire apparitre une Gui avec un champ qui contient le Chemin du dit Fichier

Merci d'avance

Re: Drag & Drop  

Posté : mar. 01 août 2017 18:10
par mikell
Ouala
C'est une compil de 2 exemples du fichier d'aide. J'ai mis une msgbox pour la démo, mais ce n'est pas recommandé de mettre une fonction bloquante à cet endroit... à toi d'aménager le truc 8)
Note que tu peux drag/dropper un ou plusieurs fichiers

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <StaticConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPISys.au3>

OnAutoItExitRegister('OnAutoItExit')


    GUICreate("My GUI with treeview", 350, 215)

    Local $idTreeview = GUICtrlCreateTreeView(6, 6, 100, 150, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
$hTreeview = GuiCtrlGetHandle($idTreeview)
_WinAPI_DragAcceptFiles($hTreeview)

    Local $idGeneralitem = GUICtrlCreateTreeViewItem("General", $idTreeview)
    GUICtrlSetColor(-1, 0x0000C0)
    Local $idDisplayitem = GUICtrlCreateTreeViewItem("Display", $idTreeview)
    GUICtrlSetColor(-1, 0x0000C0)
    Local $idAboutitem = GUICtrlCreateTreeViewItem("About", $idGeneralitem)
    Local $idCompitem = GUICtrlCreateTreeViewItem("Computer", $idGeneralitem)
    GUICtrlCreateTreeViewItem("User", $idGeneralitem)
    GUICtrlCreateTreeViewItem("Resolution", $idDisplayitem)
    GUICtrlCreateTreeViewItem("Other", $idDisplayitem)
    GUICtrlSetState($idGeneralitem, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))
    GUICtrlSetState($idDisplayitem, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))

; Allow WM_DROPFILES to be received from lower privileged processes (Windows Vista or later)
#cs
If IsAdmin() Then
    _WinAPI_ChangeWindowMessageFilterEx($hTreeview, $WM_COPYGLOBALDATA, $MSGFLT_ALLOW)
    _WinAPI_ChangeWindowMessageFilterEx($hTreeview, $WM_DROPFILES, $MSGFLT_ALLOW)
EndIf
#ce

; Register treeview window proc
Global $g_hDll = DllCallbackRegister('_WinProc', 'ptr', 'hwnd;uint;wparam;lparam')
Global $g_pDll = DllCallbackGetPtr($g_hDll)
Global $g_hProc = _WinAPI_SetWindowLong($hTreeview, $GWL_WNDPROC, $g_pDll)

    GUISetState(@SW_SHOW)


    While 1
        $idMsg = GUIGetMsg()
        Select
            Case $idMsg = $GUI_EVENT_CLOSE
                ExitLoop
        EndSelect
    WEnd



Func _WinProc($hWnd, $iMsg, $wParam, $lParam)
    Switch $iMsg
        Case $WM_DROPFILES
             Local $aFileList = _WinAPI_DragQueryFileEx($wParam)
             If not @error  Then
                  Local $list
                  For $i = 1 To $aFileList[0]
                        $list &= $aFileList[$i] & @crlf
                  Next
                  _WinAPI_DragFinish($wParam)
                  Return 0*Msgbox(0,"", StringTrimRight($list, 1))
                ;  Return 0    
             EndIf
    EndSwitch
    Return _WinAPI_CallWindowProc($g_hProc, $hWnd, $iMsg, $wParam, $lParam)
EndFunc   ;==>_WinProc

Func OnAutoItExit()
    _WinAPI_SetWindowLong($hTreeview, $GWL_WNDPROC, $g_hProc)
    DllCallbackFree($g_hDll)
EndFunc
 

Re: Drag & Drop

Posté : mar. 01 août 2017 19:24
par Nicoloquinte
ça ne semble fonctionner qu'en retirant la partie comentée , mais ça parche super bien merci beaucoup Mikell :mrgreen: