[COM] Help with the IDropSource and IDropTarget interfaces

Get help with using AutoHotkey and its commands and hotkeys
zcooler
Posts: 389
Joined: 11 Jan 2014, 04:59

Re: [COM] Help with the IDropSource and IDropTarget interfaces

18 Mar 2017, 11:52

Hi Just me,
Initial DragImage D&D implementation tries in my big app did get abrupted by a couple of errormsg followed by a nasty crash of AHK_H when dropping a file (with dragimage) at a in-treeview folder. To rule out any implicating factors in my script I tried to implement it into the demo I posted above, with same crashing result. Dont know if it might be an AHK_H bug or some of the COM coding.

The two error msgboxes says:
---------------------------
AutoHotkey
---------------------------
Error: CONTINUABLE EXCEPTION_ACCESS_VIOLATION

Mouse and Keyboard hooks have been disabled.

- Press yes to exit thread and continue execution.
- Press no to continue thread (debug).
- Press cancel to exit application.

Exception was caused in thread id: 9352
Line: 14
LineFile: F:\TV\test\MediaLauncher\IDataObject.ahk
---------------------------
Ja Nej Avbryt
---------------------------
---------------------------
AutoHotkey
---------------------------
Error: CONTINUABLE EXCEPTION_ACCESS_VIOLATION

Mouse and Keyboard hooks have been disabled.

- Press yes to exit thread and continue execution.
- Press no to continue thread (debug).
- Press cancel to exit application.

Exception was caused in thread id: 9352
Line: 51
LineFile: F:\TV\test\MediaLauncher\SHDoDragDrop.ahk
---------------------------
Ja Nej Avbryt
---------------------------


Regards
zcooler
just me
Posts: 4865
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [COM] Help with the IDropSource and IDropTarget interfaces

19 Mar 2017, 09:09

It seems to be a problem only occurring if the drag initiator and the drop target belong to the same thread. In this case, the pointer to the data object seems to be invalid when SHDoDragDrop returns, and the script crashes in AHK 1.1, too.

It might be related to 'unsave' thread interruption caused by RegisterCallback(), but I'm just guessing. It's a pitty.
Remaining with AHK 1.1.25.02 until v2 will become beta.
zcooler
Posts: 389
Joined: 11 Jan 2014, 04:59

Re: [COM] Help with the IDropSource and IDropTarget interfaces

19 Mar 2017, 09:41

just me wrote:It's a pitty.
Just me, much kudos for the very nice try and the huge amount of time you must have spent on this mega complex "kick-ass" D&D interface. One cannot win em all ;) Hats off to you, Sir :salute:
just me
Posts: 4865
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [COM] Help with the IDropSource and IDropTarget interfaces

19 Mar 2017, 10:08

Silly me! It seems to be a bug implemented since the first version of IDropTarget but without observable consequences until now. Remove the line
from IDropTarget.Drop(...) and try again, please.
Remaining with AHK 1.1.25.02 until v2 will become beta.
zcooler
Posts: 389
Joined: 11 Jan 2014, 04:59

Re: [COM] Help with the IDropSource and IDropTarget interfaces

19 Mar 2017, 10:48

OHHH YES, now we are talking niiicee DragImages :mrgreen: Sooo, very cool :lol:
Hmm...Im not there yet but just to make sure for future references and while the great author is spending time on it :) I do wonder if the SHDoDragDrop() might accept md5 hash tags as DragImage (which the windows explorer thumbnails are stored in I think anyway (in the windows thumbnail cache folder .db files))?

These thumbnails are located in encrypted .db files and there is no way to access em what I know of. Trying to load the hash didnt work. Any better ideas?

Found some code for md5 hash generating:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Best regards
zcooler :wave:
zcooler
Posts: 389
Joined: 11 Jan 2014, 04:59

Re: [COM] Help with the IDropSource and IDropTarget interfaces

19 Mar 2017, 12:12

Hi again just me :)

Tested quite extensively multiple ways to pass system assocciated icons to SHDoDragDrop(), which are loaded/added into the treeview GUI script, but everything I tried failed. The system's icons for the extensions are added using the default size SYSSMALL, so I could pick up which icon belongs to which extension on the fly, but when trying to pass them as a DragImage it doesnt work. Well, i dont wanna pass them as DragImages, instead I do wanna display the Icon blended into the otherwise empty DragImage, like the explorer way, but that doesnt seem to be possible, yes?

Regards
zcooler
just me
Posts: 4865
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [COM] Help with the IDropSource and IDropTarget interfaces

20 Mar 2017, 03:56

Hi zcooler,

Code: [Select all] [Download] (SHDoDragDrop.ahk)GeSHi © Codebox Plus

;     DragImage            -  SHDoDragDrop (API) uses a default drag image if no other option is available. You may pass:
; - a HWND of a window or control which will create an own drag image in response to the
; DI_GETDRAGIMAGE message (e.g. ListViews and TreeViews support this message).
; - a HBITMAP handle of a bitmap to be used as the drag image.

  1. You cannot pass anything else than a HWND or HBITMAP handle.
  2. You cannot pass a handle to be combined with the shell's default drag image. It will be replaced.
zcooler wrote:Well, i dont wanna pass them as DragImages, instead I do wanna display the Icon blended into the otherwise empty DragImage, like the explorer way, but that doesnt seem to be possible, yes?
It might be possible, but afaik you'd have to do it by yourself. ;)
Remaining with AHK 1.1.25.02 until v2 will become beta.
just me
Posts: 4865
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [COM] Help with the IDropSource and IDropTarget interfaces

20 Mar 2017, 11:55

You might want to try this function:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

It returnes a HBITMAP handle on success which can be passed to SHDoDragDrop() as a drag image. But it still won't look like 'the explorer way,'. ;)
Remaining with AHK 1.1.25.02 until v2 will become beta.
zcooler
Posts: 389
Joined: 11 Jan 2014, 04:59

Re: [COM] Help with the IDropSource and IDropTarget interfaces

21 Mar 2017, 14:24

just me wrote:You might want to try this function:
Yes, much obliged, Just me :D It returns most thumbnails and icons on the fly, but I had problems to get the video thumbnails. Turns out my explorer thumbnail generator for video files (not all video format thumbnails are supported by default in the explorer) didnt create the thumbnails as long as using the "detailed listview". I had to change it to either "medium sized icon" or "large sized icons" for all video folders and then the thumbnails are created in the explorer and turns up as dragimages using SHDoDragDrop() in the ahk app (before this move only the icon was returned for these video files). I have to find a new explorer thumnail generator cuz the old one does not create new thumbnails for recently added recordings, despite having large sized icons set for the folder. You have to browse the videofolder in the explorer in order to start thumbnail generation for the new files in there :( Took some time to figure it out.

just me wrote:It returns a HBITMAP handle on success which can be passed to SHDoDragDrop() as a drag image. But it still won't look like 'the explorer way,'. ;)
Well, it is pretty close though...but without the fancy stuff the explorer thumbnail generator adds (picture framing and minimized file extension icon) when creating the thumbnail ;) Unfortunately when using thumbnails and icons as dragimages, the drop-effect description text is lost. While the bluish drag-image without any content (passing NULL as drag source object) does have the drop-effect description text. Maybe you could explain in more detail why it is not possible to put the thumbnails and icons inside the bluish drag-image? That information could be very helpful for savvy folks in here who might wanna take a crack at filling the bluish drag-images with content, with working drop-effect description text.

Regards
zcooler
just me
Posts: 4865
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [COM] Help with the IDropSource and IDropTarget interfaces

22 Mar 2017, 07:06

Hi zcooler,

Maybe you could explain in more detail why it is not possible to put the thumbnails and icons inside the bluish drag-image?
Because the shell will use either the bluish default drag image or the passed drag image. It should be possible to combine them, but the shell simply doesn't. If you want to have a default style drag image with additional content you have to create an appopriate bitmap and pass its handle.
Remaining with AHK 1.1.25.02 until v2 will become beta.
zcooler
Posts: 389
Joined: 11 Jan 2014, 04:59

Re: [COM] Help with the IDropSource and IDropTarget interfaces

22 Mar 2017, 08:11

just me wrote:Hi zcooler,

Maybe you could explain in more detail why it is not possible to put the thumbnails and icons inside the bluish drag-image?
Because the shell will use either the bluish default drag image or the passed drag image. It should be possible to combine them, but the shell simply doesn't. If you want to have a default style drag image with additional content you have to create an appopriate bitmap and pass its handle.
Moin Just me,
Yes, it is obvious its not possible to combine them, had hoped for more technical COM details what happens when trying to combine according to MS regulations (maybe MS documentation about how to do here is non-existant), but its fine without them. No, I wont even try to create an appropiate bitmap and pass its handle, cuz the drop-effect description text wont work for those anyway (it might be interesting to do this at first when/if combining works). I will use the bluish empty default drag image all the time, with drop-effect description text working, cuz together they provide the best visible proof a drag operation has been initialized correctly (that was all along the main objective for me with these drag images, when starting posting about it in this thread). The fancy image stuff is just "icing on the cake". You will never know someone might, on a fine day, find a loophole and in that way manage to succeed with combining.

Thanks for your great work, Just me :wave:

Best regards
zcooler
User avatar
jeeswg
Posts: 3000
Joined: 19 Dec 2016, 01:58
Location: UK

Re: [COM] Help with the IDropSource and IDropTarget interfaces

14 Aug 2017, 11:54

Has anyone used this to emulate a drag-and-drop of a file into an external program?

E.g. this is a very small program for which WM_DROPFILES doesn't work, but where drag-and-drop does work, and where GetProp with OleDropTargetInterface does work:
Spek – Free Acoustic Spectrum Analyzer / Spectrogram Viewer
http://spek.cc/

Link:
Sending WM_DROPFILES with C++ and WinAPI to third-party application - Stack Overflow
https://stackoverflow.com/questions/22271857/sending-wm-dropfiles-with-c-and-winapi-to-third-party-application

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


If an HWND has an IDropTarget, you can wrap your DROPFILES data with an IDataObject and pass it to the IDropTarget::Drop() method. If Drop() accepts the data, do not post a WM_DROPFILES message. The trick, however, is that the IDropTarget* pointer returned by GetProp() is relative to the process that owns the HWND, so you would have to marshal it into your process, or else inject your code into the HWND's process, in order to actually use the interface pointer.


Initial code:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



[some clipboard/hDrop functions that may be useful:]
GUI COMMANDS: COMPLETE RETHINK (latest: get/set system fonts, ComboBox choose string notify) - Page 2 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=25893&p=144342#p144342

C:\Program Files (x86)\Windows Kits\8.1\Include\um\oleidl.h contains IDropTargetVtbl.
User avatar
jeeswg
Posts: 3000
Joined: 19 Dec 2016, 01:58
Location: UK

Re: [COM] Help with the IDropSource and IDropTarget interfaces

20 Aug 2017, 00:37

Has anybody succeeded, using the library functions (in this thread) and/or additional code, in creating an IDataObject consisting of one file path (or multiple file paths), that could be used to simulate a drag-and-drop into a window. Thanks.

Btw some further links re. what I'm trying to do:
IDataObject::SetData method (COM)
https://msdn.microsoft.com/en-us/library/windows/desktop/ms686626(v=vs.85).aspx
IDropTarget::Drop method (COM)
https://msdn.microsoft.com/en-us/library/windows/desktop/ms687242(v=vs.85).aspx
RegisterDragDrop function (COM)
https://msdn.microsoft.com/en-us/library/windows/desktop/ms678405(v=vs.85).aspx

[EDIT:] Another useful link:
SendTo mail recipient - CodeProject
https://www.codeproject.com/Articles/3839/SendTo-mail-recipient
Last edited by jeeswg on 20 Aug 2017, 11:09, edited 1 time in total.
User avatar
jeeswg
Posts: 3000
Joined: 19 Dec 2016, 01:58
Location: UK

Re: [COM] Help with the IDropSource and IDropTarget interfaces

20 Aug 2017, 10:57

I'm trying to put this code into IDropTarget_Sample.ahk to achieve a drag-and-drop programmatically, but the code isn't working, if anyone is able to fix this. Thanks for reading.

For IDropTarget_Sample.ahk see:
GitHub - AHK-just-me/DoDragDrop
https://github.com/AHK-just-me/DoDragDrop

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



[post 1700]

==================================================

[EDIT:]
just me wrote:IDropTarget

Hi just me, I'm referencing you in case you were interested in this.

The idea is to drag-and-drop programmatically (instead of by physically dragging and dropping) and is based on:
Sending WM_DROPFILES with C++ and WinAPI to third-party application - Stack Overflow
https://stackoverflow.com/questions/22271857/sending-wm-dropfiles-with-c-and-winapi-to-third-party-application

For the programs listed below, WM_DROPFILES doesn't work, however, GetProp with OleDropTargetInterface returns a value, so drag-and-drop may be possible via IDropTarget:
- SPEK
- Explorer
- Adobe Reader
- Internet Explorer/Firefox/Chrome
- LibreOffice Writer/LibreOffice Calc

So this could be a useful general technique for dragging and dropping into programs. I'm starting off by trying to do a drag-and-drop within an AHK script, and then I would like to try to do a drag-and-drop to an external program via dll injection via InjectAhkDll. Cheers.
User avatar
jeeswg
Posts: 3000
Joined: 19 Dec 2016, 01:58
Location: UK

Re: [COM] Help with the IDropSource and IDropTarget interfaces

08 Dec 2017, 09:27

I've managed to get the code working, to achieve a drag-and-drop programmatically. You add it to the bottom of IDropTarget_Sample.ahk.

Note: I had to replace:
#Include IDropTarget2.ahk
with:
#Include IDropTarget.ahk

Download the zip here:
GitHub - AHK-just-me/DoDragDrop
https://github.com/AHK-just-me/DoDragDrop

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



I tried to use the same code to drag-and-drop to an external program, namely the very small program spek.exe, but it didn't work. In case it's possible to fix this script, and drag-and-drop to external programs using AutoHotkeyMini.dll.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

zcooler
Posts: 389
Joined: 11 Jan 2014, 04:59

Re: [COM] Help with the IDropSource and IDropTarget interfaces

08 Dec 2017, 10:02

jeeswg wrote:I tried to use the same code to drag-and-drop to an external program, namely the very small program spek.exe, but it didn't work. In case it's possible to fix this script, and drag-and-drop to external programs using AutoHotkeyMini.dll.
Yes, getting that to work would be amazing.

zcooler wrote:
just me wrote:
Maybe you could explain in more detail why it is not possible to put the thumbnails and icons inside the bluish drag-image?
Because the shell will use either the bluish default drag image or the passed drag image. It should be possible to combine them, but the shell simply doesn't. If you want to have a default style drag image with additional content you have to create an appopriate bitmap and pass its handle.
Pretty much on the same interest level getting this to work. However there are still no COM programmers using AHK, so I guess this one will remain unsolved eternally...
zcooler
Posts: 389
Joined: 11 Jan 2014, 04:59

Re: [COM] Help with the IDropSource and IDropTarget interfaces

11 Dec 2017, 06:14

zcooler wrote:
just me wrote:
Maybe you could explain in more detail why it is not possible to put the thumbnails and icons inside the bluish drag-image?
Because the shell will use either the bluish default drag image or the passed drag image. It should be possible to combine them, but the shell simply doesn't. If you want to have a default style drag image with additional content you have to create an appopriate bitmap and pass its handle.
Although this is too complex for me to grasp I was googeling how to do the "combining". There are no explicit instructions how to do it but merely clues on it. Maybe there is someone who wants to try to find something that works.

Raymond Chen (COM guru) replies to this question:
You use the IDragSourceHelper2::InitializeFromBitmap method, passing a custom bitmap. – Raymond Chen Sep 29 '12 at 18:44

Ok but how do I get a bitmap from the shell that looks like the one from Windows Explorer? Note also that explorer handles separately dragging one item vs several items (files or folders) by providing appropriate overlay drag image. – matori82 Sep 29 '12 at 18:49

SHGetFileInfo is one way. There are others. It wasn't clear to me whether the question was "How do I get this effect?" or "How do I get the bitmap so I can plug it into this effect that I know how to do?" – Raymond Chen Sep 29 '12 at 18:51
in this stockoverflow thread https://stackoverflow.com/questions/126 ... or-vista-7
Probably there are pointers to each "thumbnail" for media files or "Icon" for other files which could be retrieved from SHGetFileInfo. Dont know if just me tried that?

Here is a link which explains things more in detail (.NET), still no clear instructions though, but good info on how it all works and problematic parts and how to workaround them.
https://blogs.msdn.microsoft.com/adamro ... et-part-3/

The IDragSourceHelper2 interface has to be invoked and I dont know if just me did this either.

SHGetFileInfo function seems to be very promising if checking out what it has to offer.

Return to “Ask For Help”

Who is online

Users browsing this forum: boiler and 40 guests