Jump to content

Drag&Drop onto Picture?


Recommended Posts

I want to be able to drag and drop a file onto a picture in my GUI, and then have some action be taken.

This is my current script:

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

Opt("GUIOnEventMode", 1)

$fPIC = "Test.bmp"

$hGUI = GUICreate("Drag&Drop", 300, 200)
GUISetOnEvent($GUI_EVENT_CLOSE, "_SpecialEvent")
GUISetOnEvent($GUI_EVENT_DROPPED, "_SpecialEvent")
$hPIC = GUICtrlCreatePic($fPIC, 0, 0, 50, 50, "", $WS_EX_ACCEPTFILES)
GUICtrlSetState($hPIC, $GUI_DROPACCEPTED)
GUISetState(@SW_SHOW)

While 1
    Sleep(100)
WEnd

Func _SpecialEvent()
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
            Exit
        Case @GUI_CtrlId = $GUI_EVENT_DROPPED
            ConsoleWrite("File Dropped!" & @CRLF)
    EndSelect
EndFunc

For some reason, it doesn't detect a file drop? Is some easy thing I'm missing?

Edited by darkjohn20
Link to comment
Share on other sites

This works.

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

Opt("GUIOnEventMode", 1)

Local $fPIC = "" ; "Test.bmp"

Local $hGUI = GUICreate("Drag&Drop", 300, 200, 10, 10, -1, $WS_EX_ACCEPTFILES)
Global $hPIC = GUICtrlCreatePic($fPIC, 5, 5, 290, 190);, "", $WS_EX_ACCEPTFILES)
GUICtrlSetState($hPIC, $GUI_DROPACCEPTED)
GUISetOnEvent($GUI_EVENT_CLOSE, "_SpecialEvent")
GUISetOnEvent($GUI_EVENT_DROPPED, "_SpecialEvent")
GUISetState(@SW_SHOW)

While 1
    Sleep(100)
WEnd

Func _SpecialEvent()
    Local $DFile
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
            Exit
        Case @GUI_CtrlId = $GUI_EVENT_DROPPED
            $DFile = @GUI_DragFile
            ConsoleWrite("Dropped File - " & $DFile & @CRLF)
            If StringRight($DFile, 3) = "jpg" Or StringRight($DFile, 3) = "bmp" Then GUICtrlSetImage($hPIC, $DFile)
    EndSelect
EndFunc ;==>_SpecialEvent
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...