Platforms to show: All Mac Windows Linux Cross-Platform

/Win/Drag and Drop/File Drag Multi


Required plugins for this example: MBS Main Plugin, MBS Picture Plugin, 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 Drag Multi

This example is the version from Sun, 17th Mar 2012.

Project "File Drag Multi.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
EventHandler Sub Open() dim file100 as FolderItem = createtestfile(100) dim file200 as FolderItem = createtestfile(200) dim file500 as FolderItem = createtestfile(500) dim filetext as FolderItem = CreateTextFile("test.txt", "Hello World"+EndOfLine+"Just a test file.") files.Append file100 files.Append file200 files.Append file500 files.Append filetext End EventHandler
Function CreateTestFile(n as integer) As FolderItem dim logo as Picture = logoMBS(n) dim file as FolderItem = SpecialFolder.Temporary.Child("test"+str(n)+".jpg") file.SaveAsJPEG logo Return file End Function
Function CreateTextFile(filename as string, content as string) As FolderItem dim file as FolderItem = SpecialFolder.Temporary.Child(filename) dim t as TextOutputStream = file.CreateTextFile if t<>Nil then t.Write content end if Return file End Function
Property files() As FolderItem
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 FileDragWindow Inherits Window
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control Canvas1 Inherits Canvas
ControlInstance Canvas1 Inherits Canvas
EventHandler Function MouseDown(X As Integer, Y As Integer) As Boolean DragStarted = false Return true End EventHandler
EventHandler Sub MouseDrag(X As Integer, Y As Integer) if UBound(app.files)>=0 and DragStarted = false then DragStarted = true // avoid a new drag if the user pressed Escape key and is still dragging dropsource = new FileDragSource dim data as new WinDataObjectMBS(app.files) dim DragImage as new Picture(me.Width, me.Height, 32) drawicons DragImage.Graphics, &c000001 data.AddDragImage DragImage, DragImage.Width, DragImage.Height, x, y, &c000001 dim okeffect as integer = dropsource.DROPEFFECT_COPY // we allow only copy dim effect as integer = 0 dim result as integer = dropsource.DoDragDrop(data, okeffect, effect) // this is for debugging so we can look on results in DebugView: System.DebugLog "Result: "+str(Result) System.DebugLog "Effect: "+str(effect) if result = dropsource.DRAGDROP_S_DROP then System.DebugLog "Dropped" if BitwiseAnd(Effect, dropsource.DROPEFFECT_COPY) = dropsource.DROPEFFECT_COPY then System.DebugLog "Copied" elseif BitwiseAnd(Effect, dropsource.DROPEFFECT_MOVE) = dropsource.DROPEFFECT_MOVE then System.DebugLog "Moved" elseif BitwiseAnd(Effect, dropsource.DROPEFFECT_LINK) = dropsource.DROPEFFECT_LINK then System.DebugLog "Linked" else System.DebugLog "Unknown effect." end if elseif result = dropsource.DRAGDROP_S_CANCEL then System.DebugLog "Cancel" else System.DebugLog "Other result." end if end if End EventHandler
EventHandler Sub Paint(g As Graphics) drawicons g, &cFFFFFF End EventHandler
End Control
EventHandler Sub Open() // We make our window a drop target to have the drag image visible within our application w = new FileDropTarget dim e as integer = w.AttachToWindow(Self) System.DebugLog "AttachToWindow: "+str(e) End EventHandler
Sub drawicons(g as Graphics, bgcolor as color) g.ForeColor = bgcolor g.FillRect 0,0,g.Width,g.Height dim u as integer = UBound(app.files) for i as integer = 0 to u dim x as integer = i mod 2 dim y as integer = i \ 2 dim icon as Picture = app.files(i).IconMBS(32) g.DrawPicture icon, x*50+50, y*50+50 next End Sub
Property DragStarted As Boolean
Property dropsource As FileDragSource
Property w As FileDropTarget
End Class
Class FileDragSource Inherits WindowsDragSourceMBS
EventHandler Function GiveFeedback(Effect as integer) As integer Return DRAGDROP_S_USEDEFAULTCURSORS End EventHandler
EventHandler Function QueryContinueDrag(EscapePressed as boolean, KeyState as integer) As integer System.DebugLog CurrentMethodName+" EscapePressed: "+str(EscapePressed)+" KeyState: "+str(KeyState) if EscapePressed then Return DRAGDROP_S_CANCEL end if if Bitwise.BitAnd(KeyState, MK_LBUTTON)=0 then return DRAGDROP_S_DROP end if Return S_OK End EventHandler
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 // deny drop effect = DROPEFFECT_NONE 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 // deny drop effect = DROPEFFECT_NONE 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 // deny drop effect = DROPEFFECT_NONE Return S_OK End EventHandler
End Class
End Project

See also:

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


The biggest plugin in space...