Jump to content

Drag and Drop GUI


Recommended Posts

I'm making a script that will allow a user to drag and drop files to my GUI and then after they're done with the files, will put the file names in a script.

Can someone help me on creating the Drag-and-drop window and the function to take the filenames of the dropped files? Thanx.

Link to comment
Share on other sites

I think he mean a bit different thing. Here is an example of Drag'n'Drop GUI, similar to famous OggDrop:

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global Const $WM_DROPFILES = 0x233
Global $gaDropFiles[1]

#Region ### START Koda GUI section ### Form=
$hGUI = GUICreate("", 137, 131, -1, -1, BitOR($WS_DLGFRAME,$WS_POPUP,$WS_CLIPSIBLINGS), BitOR($WS_EX_ACCEPTFILES,$WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
GUISetBkColor(0xFFFFFF)
$hList = GUICtrlCreateLabel("Drop files here", 0, 0, 135, 121, BitOR($SS_CENTER,$SS_CENTERIMAGE), $GUI_WS_EX_PARENTDRAG)
GUICtrlSetState ($hList, $GUI_DROPACCEPTED)
$hContext = GUICtrlCreateContextMenu($hList)
$hExit = GUICtrlCreateMenuItem("Exit", $hContext)
#EndRegion ### END Koda GUI section ###

GUIRegisterMsg ($WM_DROPFILES, "WM_DROPFILES_FUNC")
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $hExit
            Exit
        Case $GUI_EVENT_DROPPED
            For $i = 0 To UBound($gaDropFiles) - 1
                ConsoleWrite($gaDropFiles[$i] & @CR)
            Next
    EndSwitch
WEnd

Func WM_DROPFILES_FUNC($hWnd, $msgID, $wParam, $lParam)
    Local $nSize, $pFileName
    Local $nAmt = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", 0xFFFFFFFF, "ptr", 0, "int", 255)
    For $i = 0 To $nAmt[0] - 1
        $nSize = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0) 
        $nSize = $nSize[0] + 1
        $pFileName = DllStructCreate("char[" & $nSize & "]")
        DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", DllStructGetPtr($pFileName), "int", $nSize)
        ReDim $gaDropFiles[$i+1]
        $gaDropFiles[$i] = DllStructGetData($pFileName, 1)
        $pFileName = 0
    Next
EndFunc
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...