Jump to content
mdwerne

Drag and Drop Files only? No folders...

Recommended Posts

mdwerne

Hi,

I have a test interface that I'd like to use as the basis for a GUI I'm starting work on.
**Credit to Melba23 for the starting framework below: 

How would I take this interface and modify it so that only files are accepted in the Drag and Drop edit box, not folders. In other words, if I drag the Windows folder on top of the edit box, nothing is displayed, but if I take the contents of the Windows directory and drop it in the edit box, all the files (including their paths) are listed, but none of the folders. Make sense?

Here is "my" sample GUI:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GuiEdit.au3>

$hGUI = GUICreate("Accept only files in this window, no folders", 500, 400, Default, Default, Default, $WS_EX_ACCEPTFILES)

$hEdit = GUICtrlCreateEdit("", 10, 10, 480, 380)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
$hEdit_Handle = GUICtrlGetHandle(-1)

GUISetState(@SW_SHOW)

GUICtrlSetData($hEdit, "")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_DROPPED
            $file = @GUI_DragFile
            ConsoleWrite($file & @CRLF)
            Sleep(2000) ; This only here you you can see the drop has taken place
            _GUICtrlEdit_ReplaceSel($hEdit_Handle, "")
    EndSwitch
WEnd

Thanks for your time and suggestions,
-Mike

Share this post


Link to post
Share on other sites
Bilgus

Hmm How about this?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>
#include <Array.au3>

Global $aFiles[1] = [0]
$hGUI = GUICreate("Accept only files in this window, no folders", 500, 400, Default, Default, Default, $WS_EX_ACCEPTFILES)

$hEdit = GUICtrlCreateEdit("", 10, 10, 480, 380)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
$hEdit_Handle = GUICtrlGetHandle(-1)

GUISetState(@SW_SHOW)

GUICtrlSetData($hEdit, "")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_DROPPED

            For $i = 0 To _GUICtrlEdit_GetLineCount($hEdit_Handle)
                $file = _GUICtrlEdit_GetLine($hEdit_Handle, $i)
                ConsoleWrite($file & @CRLF)
                If FileGetAttrib($file) = "D" Then
                    ConsoleWrite($file & " is a Directory" & @CRLF)
                ElseIf $file <> "" Then
                    _ArrayAdd($aFiles, $file)
                EndIf
            Next
            $aFiles[0] = UBound($aFiles) - 1
            _ArrayDisplay($aFiles)
            Sleep(2000) ; This only here you you can see the drop has taken place
            _GUICtrlEdit_ReplaceSel($hEdit_Handle, "")
    EndSwitch
WEnd

 

Share this post


Link to post
Share on other sites
mikell

You might also use _WinAPI_DragQueryFileEx  (with flag 1 - files only)

  • Like 1

Share this post


Link to post
Share on other sites
Bilgus

Yeah I imagine thats faster I suppose it depends how many files he has to drop/ how often and If he wants to subclass his control..

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

×