Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Drag and Drop files & folders into Active Window

Author
Message
Burning Feet Man
18
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 28th May 2013 13:06
I've been wondering about the simplicity of some apps, how either a simple file, folder, or a collection of files & folders can be dragged and dropped into an application. This functionality has been around for decades with Windows, but in searching on these forums I couldn't find anyone who reported success on this functionality within their DBPro app.

In digging about online, I believe such functionality is possible via accessing the Windows Shell Functions;

Shell32.dll

Specifically calling on these functions;

DragAcceptFiles
DragFinish
DragQueryFile
DragQueryPoint

Has anyone here dabbled in such witchcraft? Further to this, is anyone here willing to hold my hand on this adventure? I have a basic grasp (clutching at straws?) of how to operate simple mouse & screen functions from User32.DLL, such as polling the position of the mouse cursor on the entire desktop, whether it's inside or outside the active DBPro application.

To give an idea of my coding ability, here is an example of me preparing some memblocks for the passing User32.DLL data, specifically active game window size.

TLDR; me at maximum retard.



So what I'm trying to ask is that, if I stare at my code long enough, will I eventually be able to drag & drop file(s) & folders(s) from Windows explorer into my active DBPro window (or anywhere on the desktop really) which result in a text dump of those selected file names & directories into DBpro string array?

Cheers in advanced,
BFM

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 28th May 2013 13:37 Edited at: 28th May 2013 13:59
I'm sure I've seen it done very simply with DBPro. I'll see if I can locate it.

Edit

Can't find it .

But you could try something like this.



If you drag and drop a file onto the compiled exe you'll see what happens. It should be obvious how to edit this snippet to get the actual filename rather than the full path - then you can open it etc.

Not sure whether that is what you are trying to do though.
Burning Feet Man
18
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 28th May 2013 14:18
Yup, I found that in my searches. Although I haven't compiled/double checked it, I assumed that the selected file is simply added to the cl$() string upon app launch. This has very limited scope and unfortunately doesn't fit into what I have in mind.

What I'm going to try and do over the coming weeks (edit: years knowing me) is;
The user launches my DBpro app. They select several files in Windows Explorer, then drag the files (or folder(s)) over & drop them on the DBpro app. The DBpro app then records the location of each file. No harm comes to the files, nothing changes, with the exception of the app being told the directory, file name and extension (possibly dates & file size too).

And that's basically it.

Since you didn't flag a red flag at my interest in Shell32.dll, I'm guessing that I'm ok to use this in a similar fashion to User32.dll? Although I never actually stopped to check if User32.Dll has the functionality I'm looking for either...

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 28th May 2013 15:09
Quote: "And that's basically it."


Yes, I feared as much. I've no idea how to do that. Sorry.

Quote: "Since you didn't flag a red flag at my interest in Shell32.dll, I'm guessing that I'm ok to use this in a similar fashion to User32.dll?"


It would be unwise to deduce that from my silence on the matter. My ignorance of such matters has no limits unfortunately.

I'll be interested to see what you come up with. Sounds useful.
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 28th May 2013 15:25 Edited at: 28th May 2013 15:26
This a vague solution but the path should lead to what you are after; as you mentioned the Shell API. You will not get this to work without some elbow grease as I have not seen any helper commands in any plugin that deals with this.

You need to handle the windows messages. Windows messages are a series of events and parameters used to make all the windows controls communicate with each other. How you go about this is unknown to me; you can try using Matrix1 message callbacks, BBB GUI events or Styx message queues, but how you get the file name from the drop message is unknown to me. Try asking Brendy Boy in the BBB GUI WIP.

You will need to locate how to do this in the MSDN or somewhere; most people just make use of the Windows Forms or WPF drop event using .NET; but in DBPRO it is not that simple.

The Drag Drop window message (WMPROFILE)
Drag finish message
How to catch files dropped from explorer (C++)

MonoCoder
20
Years of Service
User Offline
Joined: 4th Dec 2005
Location: england
Posted: 28th May 2013 15:35 Edited at: 28th May 2013 16:45
Here's a basic solution that uses a bit of IanM's Matrix1Utils.



Not tried to break it yet, but if you run it, open up a folder, select some files and drop them onto the window, it will give you the full path to each. As a bonus, image files will be loaded and pasted.


edit [updated code a little, just to deemphasise images and delete once drawn]:
- you can probably mess up this particular piece of code by dropping files twice in quick succession, the second overwriting the still-in-use hDrop pointer. You'll need a queue or seperate current/next-to-handle pointers.
- tried bringing files in from a few different contexts (explorer window, start menu, quick launch toolbar, another program's open file dialog, photo gallery, etc. - all working as you'd expect, though I was half expecting to run into some little DBP eccentricity (if you're interested, shortcuts return the .lnk's themselves, not the actual file they point to)
- tried to test if DragFinish "releases memory that the system allocated for use in transferring file names to the application" properly. It does not seem to; if you drag and drop large quantities of files over and over you can start to accumulate a small memory leak that, while not even registering in the task manager graph, might be worth seeking a solution for if you expect your program to be receiving thousands of files this way.

(note: I'm using vista 32-bit, in case you find discrepancies.)
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 28th May 2013 15:51
Looks like an excellent start.
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 28th May 2013 17:31
That looks good

Burning Feet Man
18
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 28th May 2013 22:59
I can already hear all the map editor makers out their salivating! I can't thank you enough for this. The talent on these forums is truly amazing!

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
GIDustin
18
Years of Service
User Offline
Joined: 30th May 2008
Location:
Posted: 28th May 2013 23:52
This looks interesting. If anyone here uses GMail, you know you can drag files onto a message to attach them. Somehow, gmail knows when you are dragging a file because it displays a "drop zone" so you know where you are going. I would imagine map editors could have several of these drop zones.

So, using the demo code above, how would you highlight multiple drop zones while files are being dragged? And, once the files are dropped into one of the zones, how would you determine which drop zone was targeted? As an added bonus, place a border around the drop zone currently under the mouse as a confirmation while dragging.

I can see a DragQueryPoint function where you can find out where files were dropped, but so far I cannot find any windows messages similar to DragStart or DragStop...
Burning Feet Man
18
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 29th May 2013 13:48
Yup, I've already started coding "Drop Zones" in my application. The easiest solution I've found is that after you declare your zones (width, height, x,y) is to then track the mouse x & y using calls to User32.DLL;

Temp = Call Dll(Const_user32, "GetCursorPos", Mouse_Pointer_Global)

Pull that X & Y data out of memory every application loop. No matter where the mouse is, nor what it's doing, your DBpro app will always be tracking it. The same can not be said for the much beloved MouseX() & MouseY(), these are next to useless now that we're interacting the application with Windows.

I will try to post code sooner than later.

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
Burning Feet Man
18
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 10th Jun 2013 13:40 Edited at: 28th Jul 2013 05:02
Hi MonoCoder,

I've been looking into your code more & more lately, and I would like to know more about the technique behind your method. I think, at this stage I understand what's going on with your code, but am curious about the very first line;

#constant WM_DROPFILES 0x233

How do you know the Hex value to set this constant at? I can see this value is then called in the function WndProc(), but not as a DBPro function, but rather;

Set Message Callback

I am new to this command, in reading it appears to be a specifically tailored command for the DBPro app to accept data from external DLL files, without then need to call on a command each sync?

I suppose to show you where I'm coming from, this is how I handle User32.dll, keep in mind I'm still a novice at this;

From what I'm reading in your Drag & Drop example, you technique looks much simpler... but if only I could understand where you pulled that magical Hex figure from... it might make more sense! Please, do tell.

EDIT: I should have googled this earlier, rather than dwelling on the unknown.

Below is the list of hex that I was curious about;

List of Windows Messages



Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
Burning Feet Man
18
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 29th Jul 2013 09:28 Edited at: 2nd Aug 2013 13:44
Tinkering around with some ideas. I've started reading up on DropFiles. I think that command would let the user trigger an event from the DBPro app, which allows them to drag and drop a file from DBpro App into Windows Explorer... I think. Has anyone tinkered with DropFiles yet?

http://msdn.microsoft.com/en-us/library/windows/desktop/bb773269%28v=vs.85%29.aspx

And a lot of reading here;

http://msdn.microsoft.com/en-us/library/windows/desktop/bb776902%28v=vs.85%29.aspx

Annnnd here!

http://msdn.microsoft.com/en-us/library/windows/desktop/ms688421%28v=vs.85%29.aspx

Ahh, this should help too!

http://msdn.microsoft.com/en-us/library/windows/desktop/bb776905%28v=vs.85%29.aspx

EDIT: Here's some good theory too;

http://www.codeproject.com/Articles/840/How-to-Implement-Drag-and-Drop-Between-Your-Progra

Looks like I'll need to get my DBPro app to call IDataObject with CF_HDROP data.

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia

Login to post a reply

Server time is: 2026-07-06 17:09:49
Your offset time is: 2026-07-06 17:09:49