News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Drag-n-drop (but without XAML)

Started by NoCforMe, March 15, 2024, 10:26:05 AM

Previous topic - Next topic

NoCforMe

I want to play around with drag and drop.

I do not want to use XAML. I read this article which explains that there apparently is still support for what they call "classic Windows apps" (i.e., non-XAML):
QuoteModern drag and drop is available on all devices that support UWP. It allows data transfer between or within any kind of application, including Classic Windows apps, although this article focuses on the XAML API for modern drag and drop.

Can anyone give me some pointers here? (And yes, JJ, I did "google" first; haven't found anything useful that way.)
Assembly language programming should be fun. That's why I do it.

sinsi

Hope you like COM, you would implement IDropSource, IDropTarget, maybe IDataObject.
I don't know of an easier solution but hope someone can chime in with something...
🍺🍺🍺

fearless

The basic option is to use the WM_DROPFILES event message to handle this. At startup of your app, you can tell windows that you support drag and drop for files with DragAcceptFiles. Then you can call DragQueryFile to get the file that was dropped.

A simple example:

    .ELSEIF eax == WM_DROPFILES
        ; hDrop = (HANDLE) wParam;  // handle of internal drop structure
        Invoke DragQueryFile, wParam, 0, Addr szDragDropFilename, SIZEOF szDragDropFilename
        .IF eax != 0
            ; Open drag and drop file
            Invoke OpenFile, Addr szDragDropFilename
        .ENDIF
        mov eax, 0
        ret

I don't have any other experience about other types of drag and drop, although I'm aware of using an ImageList to drag using:

ImageList_BeginDrag: https://learn.microsoft.com/en-us/windows/win32/api/commctrl/nf-commctrl-imagelist_begindrag
ImageList_EndDrag: https://learn.microsoft.com/en-us/windows/win32/api/commctrl/nf-commctrl-imagelist_enddrag
ImageList_GetDragImage: https://learn.microsoft.com/en-us/windows/win32/api/commctrl/nf-commctrl-imagelist_getdragimage
ImageList_DragEnter: https://learn.microsoft.com/en-us/windows/win32/api/commctrl/nf-commctrl-imagelist_dragenter
ImageList_DragLeave: https://learn.microsoft.com/en-us/windows/win32/api/commctrl/nf-commctrl-imagelist_dragleave
ImageList_DragMove: https://learn.microsoft.com/en-us/windows/win32/api/commctrl/nf-commctrl-imagelist_dragmove
ImageList_DragShowNolock: https://learn.microsoft.com/en-us/windows/win32/api/commctrl/nf-commctrl-imagelist_dragshownolock
ImageList_SetDragCursorImage: https://learn.microsoft.com/en-us/windows/win32/api/commctrl/nf-commctrl-imagelist_setdragcursorimage

Edit: also came across this, which might be useful if implementing drag and drop via COM - RegisterDragDrop: https://learn.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-registerdragdrop

NoCforMe

Thanks, fearless, but I probably should have been clearer. I know about WM_DROPFILES and have used it successfully. What I'm interested in is being able to drag and drop between controls or other program elements, like being able to drag files from, say, a tree control on one side to another control on the other side.

Let me back up just a bit here: I want to implement drag and drop in the simplest way possible (though maybe none of the methods are really simple at all). So if XAML is easier than, say, COM, maybe I should use that instead.

Thing is, since I'm doing this in assembly language, I need a flat interface, not a C++-oriented mess of "methods" and such.

So does anyone here know enough about this to suggest 1) the easiest way of implementing drag and drop and 2) a basic rundown on how one goes about this? It would be much appreciated.
Assembly language programming should be fun. That's why I do it.

fearless

https://www.codeproject.com/Articles/1298/Rearrange-rows-in-a-ListView-control-by-drag-and-d

https://anton.maurovic.com/posts/win32-api-approach-to-windows-drag-and-drop/

https://www.codeguru.com/cplusplus/using-treecontrol-treeview-under-win32-api-no-mfc/

I guess you could use WindowFromPoint or ChildWindowFromPoint to check if the dragged stuff can be dropped onto a supporting control, if not keep cursor as a circle with a line through it or some other cursor or if ok to drop onto it change cursor to something to indicate that it will be allowed.

NoCforMe

Thanks! That should give me enough to chew on for a while.
Assembly language programming should be fun. That's why I do it.

sinsi

Where are theend points of your drag and drop? Dragging from Explorer to your app is very different to dragging within your app.
A "classic windows app" still uses COM for drag and drop, XAML is the modern .net core way (C# et. al.)
🍺🍺🍺

NoCforMe

The drag-n-drop would be within my app, not from Explorer. (Already know how to handle that.)

The links given above by fearless seem to suggest that this can be done without using either COM or XAML (although one of them uses someone's library which may well incorporate COM). I'm still reading through them.
Assembly language programming should be fun. That's why I do it.