Jump to content

Drag and drop not triggering any event (doesn't work in both OnEvent and MessageLoop)


Recommended Posts

MessageLoop:

GUICreate('')
GUICtrlSetState(GUICtrlCreateEdit('Drop Here',0,0,400,400,-1,0x00000010),8)
GUISetState()

While 1
      Switch GUIGetMsg()
        Case -3
             Quit()
        Case -13
             Drop()
      EndSwitch
WEnd

Func Quit()
     Exit
EndFunc

Func Drop()
     MsgBox(0,'','drop')
EndFunc

OnEvent:

Opt('GUIOnEventMode',1)

GUICreate('')
GUICtrlSetState(GUICtrlCreateEdit('Drop Here',0,0,400,400,-1,0x00000010),8)
GUISetOnEvent(-3,Quit)
GUISetOnEvent(-13,Drop)
GUISetState()

While Sleep(1000)
WEnd

Func Quit()
     Exit
EndFunc

Func Drop()
     MsgBox(0,'','drop')
EndFunc

 

Edited by AutoXenon
Link to post
Share on other sites

Helpfile says.:  will only work with 

Quote


 

Extended Style result
$WS_EX_ACCEPTFILES Allow an edit or input control within the created GUI window to receive filenames via drag and drop. The control must have also the $GUI_DROPACCEPTED state set by GUICtrlSetState(). for other controls the drag&drop info can be retrieved with @GUI_DragId, @GUI_DragFile, @GUI_DropId.

Read example for GUICtrlCreateInput.

Link to post
Share on other sites

Please read the code, you'll notice that I've done all that with how I created the controls.

It might occasionally be productive to actually try the code yourself, in my experience.

Edited by AutoXenon
Link to post
Share on other sites
  • Moderators

AutoXenon,

Quote

It might occasionally be productive to actually try the code yourself, in my experience.

Charming - please do try and keep it civil from now on

Now go and look carefully at the example in the Help file for GUICtrlCreateInput and see where the $WS_EX_ACCEPTFILES extended style should be placed (Hint: not where you have it).

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to post
Share on other sites

Charmingly ironic indeed, given the forum's reputation -- I suppose the definition of incivility does not extend to the regular condescending dismissals palpable here -- especially when actively encouraged and perpetrated by the very keepers of civility.

In any case, if you would kindly read the documentation being referred to, GUICtrlCreateEdit/Input/whatever have seven positional arguments. I suppose if you mentally counted using zero-based indexing then that might explain the confusion.

 

If one had indeed attempted to run the code, you may notice that the cursor correctly changes to that corresponding to drag-and-drop, whereas excluding it results in the disabled cursor instead.

 

Edited by AutoXenon
Link to post
Share on other sites
  • Moderators

AutoXenon,

I will try again.

This has nothing at all to do with "seven positional arguments" - whether zero-counted or not. As it stands there is absolutely no point in running your posted code snippet as it is blatantly incorrect to even the most cursory glance.

You are applying the extended style you need to apply to the GUI to the control itself. The example to which you were twice referred makes it quite clear that both the GUI and the control need specific actions; an extended style applied to the GUI, and a specific state set for the control. When this is done, the drag'n'drop works correctly.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to post
Share on other sites

Here's a small script to demonstrate droping to LV (can be easy changed to other controls):

 

#include <File.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
;#include <Array.au3>       ;only for info's

Opt('GUIOnEventMode',1)

Global $hGui = GUICreate('DropTest', 400, 400, @DesktopWidth -404, -1, -1,$WS_EX_ACCEPTFILES)
Global $idLV = GUICtrlCreateListView('Name: |Ext |Path',0,0,400,400)
GUICtrlSetState(-1 ,$GUI_DROPACCEPTED)
GUISetOnEvent($GUI_EVENT_CLOSE,Quit)
GUISetOnEvent($GUI_EVENT_DROPPED, Drop)
GUIRegisterMsg($WM_DROPFILES, "WM_DROPFILES_FUNC")
GUISetState()
Global $aDropFiles[1]

While Sleep(1000)
WEnd

Func Quit()
     Exit
EndFunc

Func Drop()
    Local $szDrive, $szDir, $szFName, $szExt, $split
    ;_ArrayDisplay($aDropFiles)  
    _GUICtrlListView_BeginUpdate($idLV)
    For $i = 0 To UBound($aDropFiles) - 1
        $split = _PathSplit($aDropFiles[$i], $szDrive, $szDir, $szFName, $szExt)
        $szExt = StringUpper($szExt)
        Switch $szExt
            Case ".TXT", ".INI", ".AU3", ".PDF"
                GUICtrlCreateListViewItem($szFName & "|" & StringTrimLeft($szExt, 1) & "|" & $aDropFiles[$i], $idLV)
        EndSwitch
    Next
    _GUICtrlListView_SetColumnWidth($idLV, 0, $LVSCW_AUTOSIZE)
    _GUICtrlListView_EndUpdate($idLV)
MsgBox(0,'','droped')
EndFunc

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 $aDropFiles[$i + 1]
        $aDropFiles[$i] = DllStructGetData($pFileName, 1)
        $pFileName = 0
    Next
EndFunc   ;==>WM_DROPFILES_FUNC

 

Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...