Jump to content

Need help with "Drag and Drop"


Recommended Posts

Hi everybody,

I'm trying to make a program that displays a MessageBox after some files are dropped onto the gui.

Can anybody help me please ?

I already have the following code but it seems that "SpecialEvents" is NOT run when some files are dropped into the gui. :whistle:

Thank you,

Peter

CODE
#include <GUIConstants.au3>

Opt("GUICoordMode",2)

Opt("GUIResizeMode", 1)

Opt("GUIOnEventMode", 1)

$parent1 = GUICreate("Parent1", 320,320, @DesktopWidth/2-10, @DesktopHeight/2-45, -1, $WS_EX_ACCEPTFILES)

GUICtrlSetState($parent1,$GUI_DROPACCEPTED)

GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")

GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")

GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")

GUISetOnEvent($GUI_EVENT_DROPPED, "SpecialEvents")

GUISetState(@SW_SHOW)

; Just idle around

While 1

Sleep(10)

Wend

Func SpecialEvents()

Select

Case @GUI_CTRLID = $GUI_EVENT_CLOSE

MsgBox(0, "Close Pressed", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)

Exit

Case @GUI_CTRLID = $GUI_EVENT_MINIMIZE

MsgBox(0, "Window Minimized", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)

Case @GUI_CTRLID = $GUI_EVENT_RESTORE

MsgBox(0, "Window Restored", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)

Case @GUI_CTRLID = $GUI_EVENT_DROPPED

MsgBox(0, "Files dropped", " @GUI_DRAGID = " & @GUI_DRAGID & " @GUI_DROPID = " & @GUI_DROPID & " @GUI_DRAGFILE = " & @GUI_DRAGFILE)

EndSelect

EndFunc

Link to comment
Share on other sites

Yeh it doesn't work for me either mate...

I think the GUI event code is broken. I see the cursor change to a drop icon over the Window control which accepts files (a TreeViewControl) but no event is triggered.... :-(

HELP!!

Bob Wya

Link to comment
Share on other sites

First, GUICtrlSetState is for setting the state of a control, not a gui.

I pilfered this from lazycat:

;pilfered from lazycat

#include <GUIConstants.au3>

Global $WM_DROPFILES = 0x233
Global $gaDropFiles[1], $str = ""

### Koda GUI section start ###
$hGUI = GUICreate("Test", 400, 200, 219, 178, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_TOPMOST))
$hList = GUICtrlCreateList("", 5, 5, 390, 190)
GUICtrlSetState (-1, $GUI_DROPACCEPTED)
GUISetState(@SW_SHOW)
### Koda GUI section end   ###

GUIRegisterMsg ($WM_DROPFILES, "WM_DROPFILES_FUNC")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_DROPPED
            $str = ""
            For $i = 0 To UBound($gaDropFiles) - 1
                MsgBox(0, '', $gaDropFiles[$i])  ; i just changed this part.  this is where the file paths get spit out
            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

Your code works great ! Thanx Xcal ! (and lazycat offcourse)

After seen the code, I was wondering if I could use "@GUI_DRAGFILE" instead to see the file(s)

It seems to work fine if only 1 file is dropped in the editbox but it does not work if more then 1 file is dropped in the editbox. Maybe something to investigate further by the developpers ? (Or maybe I used not the right code)

Peter

----------------------------------------------------------------------------------------------------------

#include <GUIConstants.au3>

Global $WM_DROPFILES = 0x233
Global $gaDropFiles[1], $str = ""

### Koda GUI section start ###
$hGUI = GUICreate("Test", 400, 200, 219, 178, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_TOPMOST))
$hList = GUICtrlCreateList("", 5, 5, 390, 190)
GUICtrlSetState (-1, $GUI_DROPACCEPTED)
GUISetState(@SW_SHOW)
### Koda GUI section end   ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_DROPPED
            $str = ""
            MsgBox(4096,"",@GUI_DRAGFILE)
    EndSwitch
WEnd
Edited by Lemmens Peter
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...