Example: /Win/Drag and Drop/File Drop

Online Documentation   -   Statistics   -   FAQ   -   Plugin Parts (All, Dependencies)   -   Class hierarchy

New in Version 22.2 22.3 22.4 22.5 23.0 23.1 23.2 23.3 23.4 23.5 24.0 24.1

The list of the   topics,   classes,   interfaces,   controls,   modules,   global methods by category,   global methods by name,   screenshots,   licenses   and   examples.

Platforms to show: All Mac Windows Linux Cross-Platform

/Win/Drag and Drop/File Drop


Required plugins for this example: MBS Win Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Win/Drag and Drop/File Drop

This example is the version from Thu, 31th Jul 2019.

Project "File Drop.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
Class FileDropWindow Inherits Window
Control List Inherits Listbox
ControlInstance List Inherits Listbox
End Control
EventHandler Sub Open() w = new FileDropTarget dim e as integer = w.AttachToWindow(Self) System.DebugLog "AttachToWindow: "+str(e) End EventHandler
Property w As FileDropTarget
End Class
Class FileDropTarget Inherits WindowsDropTargetMBS
EventHandler Function DragEnter(dataObject as WinDataObjectMBS, keystate as integer, x as integer, y as integer, byref effect as integer) As integer // does the dataobject contain data we want? allowed = dataObject.hasPaths if allowed then // allow it effect = DROPEFFECT_COPY else // deny effect = DROPEFFECT_NONE end if Return S_OK End EventHandler
EventHandler Function DragLeave() As integer return S_OK End EventHandler
EventHandler Function DragOver(keystate as integer, x as integer, y as integer, byref effect as integer) As integer if allowed then // allow it effect = DROPEFFECT_COPY else // deny effect = DROPEFFECT_NONE end if Return S_OK End EventHandler
EventHandler Function Drop(dataObject as WinDataObjectMBS, keystate as integer, x as integer, y as integer, byref effect as integer) As integer System.DebugLog "Inside drop event "+str(allowed) if allowed then // allow it effect = DROPEFFECT_COPY FileDropWindow.List.DeleteAllRows dim files(-1) as FolderItem = dataObject.GetPaths for each f as FolderItem in files // we got a file you can use like any other file (e.g. copy) FileDropWindow.List.AddRow "Path """+f.NativePath+"""" next dim des(-1) as WindowsFileDescriptorMBS = dataObject.GetFileDescriptors for each d as WindowsFileDescriptorMBS in des // we got file descriptions. Some metadata and the data. No path. dim data as string = dataObject.GetFileContents(0) FileDropWindow.List.AddRow "File """+d.FileName+""" with "+str(lenb(data))+" bytes data." next else // deny effect = DROPEFFECT_NONE end if Return S_OK End EventHandler
Property allowed As Boolean
End Class
End Project

See also:

The items on this page are in the following plugins: MBS Win Plugin.


💬 Ask a question or report a problem