Jump to content

Drag and Drop Files only? No folders...


mdwerne
 Share

Recommended Posts

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

Link to comment
Share on other sites

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

 

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