darkjohn20 Posted May 15, 2010 Posted May 15, 2010 (edited) 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 May 15, 2010 by darkjohn20
Malkey Posted May 16, 2010 Posted May 16, 2010 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now