[COM] Help with the IDropSource and IDropTarget interfaces

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

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

24 Aug 2015, 09:12

Oh, that is unfortunate! Just me's implementation is so close to being the perfect one. One can only hope someone, by sheer luck or by vast experience (really unfortunate that 'Sean' seems no longer active), manages to get the OLE data source modification needed for the source helper right.
User avatar
lifeweaver
Posts: 144
Joined: 10 May 2014, 05:57
GitHub: lifeweaver
Location: OH

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

05 Oct 2015, 14:24

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

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

27 May 2016, 13:42

jballi wrote:...A few "real life" examples wouldn't hurt. Thanks for sharing.
Here is a "real life" example of Just Me`s D&D interface. Download the needed scripts from Github https://github.com/AHK-just-me/DoDragDr ... er/sources or copy from earlier posts in this thread and place:

DoDragDrop.ahk
IDataObject.ahk
IDropSource.ahk
IDropTarget.ahk
IEnumFORMATETC.ahk

in the same folder as this GUI script below. Set your folder you want to display in that script.

Copy the non-working IDragSourceHelper.ahk from earlier in thread and place it with the others.

Now D&D from the windows explorer to the AHK GUI, notice how source drag icon shows up when start dragging a file. If using Shift or Ctrl + Lefltclick drag we get to know if its a Copy or Move operation just below the source drag icon. If not holding down Shift or Ctrl while drag, when drag icon/cursor leaves the shell window then user gets to know if it is a move or copy D&D. That is what the IDragSourceHelper does for the shell. Dragging from the AHK GUI it differentiate between copy and move operations, but the drag symbol is hardly visible and no source icon. Getting the IDragSourceHelper to work when doing D&D operations from an AHK GUI would be amazing :D Could this be solved?

Regards
zcooler

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

qwerty12
Posts: 355
Joined: 04 Mar 2016, 04:33
GitHub: qwerty12

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

27 May 2016, 21:11

just me wrote:Nobody can contribute?


Hi just me,

zcooler pointed me to this thread elsewhere. There's a lot I've not done, but this should be enough to get IDragSourceHelper::FromBitmap working using the file represented by the clipboard, as per your example, just me. S_FAIL was being returned because the IDropSource's vtable wasn't being properly created.

Here's the files I've modified (minor modifications to everything but IDropSource.ahk), based on the files from just me's GitHub and with replacement/addition of the files in JM's post above the one I quoted.

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



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



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



Thanks to zcooler for his DnD interface test program, which I used to actually test what I was changing. A version I changed slightly to make it easier for me to test:

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






To those reading: this isn't complete. IDataSource needs to be implemented to move arbitrary things. Currently this is limited to what's on the clipboard (I test by Ctrl-Cing a file before running Untitled.ahk). Also, currently, with IDragSourceHelper, you get this:
Image

With Drag & Drop Images and Drop Descriptions for MFC Applications, you get this:
Image

The CodeProject project has code for setting up a DROPDESCRIPTION and for also using the new cursors. This is far as I'll go because:

  • I don't write GUI AHK programs, so I'm already at a disadvantage for best practices etc., especially when compared to the contributors of this thread alone
  • Writing easily reusable code isn't my jam, either...
  • just me actually appears to know how the clipboard stuff works, unlike me
  • I'm hella sleep deprived
  • I really want to watch this week's Orphan Black
Last edited by qwerty12 on 28 May 2016, 08:30, edited 2 times in total.
zcooler
Posts: 380
Joined: 11 Jan 2014, 04:59

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

28 May 2016, 05:41

Wow, this is great stuff :D Very impressing qwerty12 :mrgreen:

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

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

09 Feb 2017, 11:37

Hi qwerty12!

I had hopes Just Me would jump on this and finish off the nicest AHK D&D interface up to date, but he doesnt seem to be motivated to do so. This COM stuff is something of a beast, makes my head spinn of dizyness and I get nowhere. Few folks seem to understand this stuff and since you are one of those I wanna hear with ya if you might be interested to have an another go at it?

To clarify for others that might wanna have a go, your alterations of Just Me`s interface works if Ctrl-C (Copy to clipboard) the file in the Explorer and then drag the same file from the AHK app. Then the dragimage pops-up alright. Although its the file icon showing instead of (if a movie file) the thumbnail. Also getting the DROPDESCRIPTION and the new cursors working along with the little counter image (white digit on a blue background) that pops-up if there are multiple files being D&D would be fantastic.

Regards
zcooler
qwerty12
Posts: 355
Joined: 04 Mar 2016, 04:33
GitHub: qwerty12

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

09 Feb 2017, 13:58

Hey zcooler,

I have to be honest here; GUI stuff doesn't interest me, which is why this isn't really holding my attention. I don't know the first thing about making a GUI in AHK and that suits me because I don't have a need for GUI scripts personally.

zcooler wrote:Few folks seem to understand this stuff and since you are one of those I wanna hear with ya if you might be interested to have an another go at it?


I'm not one of them, either. I knew nothing of COM before AutoHotkey, and even then what I know even now are only the basics. Another issue is that I'm not a programmer, so I'm really not good at producing reusable code. Tell you what, a personal project of mine is to write a simple shell extension in C (can't stand C++, ATL or MFC and all that bollox). If I finish that, I'll try to have a go at this as then I'll be in a far better state to understand more of what's going on. But, still, asking somebody other than me would be your best course of action, so I'll happily sit aside if someone else who has a penchant for seeing pretty images with their drag operations wants to do it.
zcooler
Posts: 380
Joined: 11 Jan 2014, 04:59

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

09 Feb 2017, 15:08

Hey qwerty12,
Thanks for the swift and honest answer. I understand your position, Im in it myself ;) Its not mainly about pretty images, but more about the tiny AHK drag&drop cursors and lack of dropdescription which makes it hard to even visually detect if a Drag operation is carried through at all in a styled TreeView GUI. Well, this was unfortunate, the D&D interface seem to remain unfinished.

:wave:
just me
Posts: 4288
Joined: 02 Oct 2013, 08:51
Location: Germany

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

12 Feb 2017, 05:18

Hi querty12,

I missed your post from May 2016 but now noticed your last answer. Sorry, and thanks for your contribution!

Now I tried your changes in my test environment with no success at first. Then I noticed the key phrase:
IDataSource needs to be implemented to move arbitrary things. Currently this is limited to what's on the clipboard (I test by Ctrl-Cing a file before running Untitled.ahk).
And after copying a file to the clipboard in the shell the drag image was shown.

After analyzing your changes I found that even my original code (at least my local version) actually shows the drag image on suitable applications. The E_FAIL returned by IDragSourceHelper.InitializeFromBitmap seems to be caused by the limits of the data object returned from OleGetClipboard().

Some remarks:
  • IDropSource VTBL:
    S_FAIL was being returned because the IDropSource's vtable wasn't being properly created.
    The way I did it might look strange, but it is actually working when used like I do it in DoDragDrop().
  • IDropSource_Free():
    Assuming VTBL is kept static (which I'm doing because of possible scope issues, and the freeing ones that arise from that), this wouldn't work well if multiple IDropSources are present.
    I agree that 'freeing' the VTBL is useless. But it's rather impractical to have more than one IDropSource which would mean more than one DoDragDrop() running at the same time in AHK v1.1. ;)
  • IDropSource_QueryInterface():
    This method is'nt called for IID_IUnknown and even not for IID_IDropSource in this scenario.

GUI stuff doesn't interest me, which is why this isn't really holding my attention.
I'm not really interested in the 'visual effects' provided by IDragSourceHelper. I just wanted to know why it wasn't working. IDropSource seems to be working with suitable applications. When used by an AHK script, everyone will know what he's currently dragging.

Thanks again,
just me
Except as noted otherwise all of my code is tested on Win 10 Pro (x64) using the current AHK version.
qwerty12
Posts: 355
Joined: 04 Mar 2016, 04:33
GitHub: qwerty12

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

12 Feb 2017, 14:01

Hi just me,

just me wrote:I missed your post from May 2016 but now noticed your last answer. Sorry, and thanks for your contribution!


Thanks :-) But thanks to you for the immense work you put into this (the only experience I have with this sort of thing is my quick implementation of the IMMNotificationClient interface - I know I wouldn't have been able to come up with something as clean as this)

After analyzing your changes I found that even my original code (at least my local version) actually shows the drag image on suitable applications. The E_FAIL returned by IDragSourceHelper.InitializeFromBitmap seems to be caused by the limits of the data object returned from OleGetClipboard().


OK, that's good, my changes weren't much and, it seems, unnecessary. :| Despite what I told zcooler, I did actually spend a couple of nights again on this to no avail...

The way I did it might look strange, but it is actually working when used like I do it in DoDragDrop()


You're absolutely right. Back then, I was thinking in one dimension: you create one struct for the vtable and another struct for the object itself, which holds just the pointer to the vtable. This time, when I downloaded all the code again (from your Git repository, this post, zcooler's demo and my changes), I realised now (with a bit more experience - I'm really not a programmer! :-)) after looking over the differences at every step of doing that the superior method you were using to construct the vtable and actually kept your code the same instead of changing it:

  • One struct is used to hold both the vtable and the pointer to the vtable that would ordinarily, by convention, be in a separate struct. But the code that gets a pointer to the COM object isn't going to look beyond the beginning of the struct, reading at most A_PtrSize bytes for the vtable pointer. Said vtable pointer points to the first COM function, like usual
  • (Methods.Length() + 2) confused me - I mean, I understood why +1 would be needed for the extra pointer, but an additional +1 atop that and zeroing of the struct (when it was going to get filled with pointers right after that) seemed unneeded. So I changed it, watched AutoHotkey crash sometimes after I dragged a file and then when I looked at IDropSource_Free(), I understood everything :oops:

I agree that 'freeing' the VTBL is useless. But it's rather impractical to have more than one IDropSource which would mean more than one DoDragDrop() running at the same time in AHK v1.1. ;)


Sorry, I was talking rubbish. In My Attempt Mk2 I got rid of that inane comment and kept your code there the same.

This method is'nt called for IID_IUnknown and even not for IID_IDropSource in this scenario.


Thanks. I still ended up changing that one blindly. I should've checked, but I just wanted to be sure, I guess, that it wasn't the little things :\

I'm not really interested in the 'visual effects' provided by IDragSourceHelper. I just wanted to know why it wasn't working. IDropSource seems to be working with suitable applications. When used by an AHK script, everyone will know what he's currently dragging.


Does this mean you're working on this again? I'm evidently not the right person for this and zcooler will be happy to hear that :-)

Best regards,
qwerty12
zcooler
Posts: 380
Joined: 11 Jan 2014, 04:59

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

12 Feb 2017, 17:17

just me wrote:I'm not really interested in the 'visual effects' provided by IDragSourceHelper. I just wanted to know why it wasn't working. IDropSource seems to be working with suitable applications. When used by an AHK script, everyone will know what he's currently dragging.
Yes of course, everyone will know what he's currently dragging when used by an AHK script. In the AHK script im using the COM D&D interface with, sometimes the Drag operation never gets initialized at all and then it's hard to visually detect it with the default AHK cursor. The small square under the mouse cursor is the only sign when a Move Drag operation is initiated. That square easily gets masked by the underlying TV row. Like this:
2017-02-12_22-19-01.png


If sitting a few meters from the TV/Monitor (HTPC system) you ought to have quite sharp vision to even see it and often I have to drag the cursor to an empty part of the treeview to make sure the Drag operation has been initialized alright.
That is why I think the 'visual effects' provided by the IDragSourceHelper, with DropDescriptions, would silverline this already fantastic D&D interface.

qwerty12 wrote:I'm evidently not the right person for this and zcooler will be happy to hear that :-)
Not only me, the whole AHK community would be very happy to be using a D&D interface that completely measures up with the MS Shell counterpart ;)

:wave:
just me
Posts: 4288
Joined: 02 Oct 2013, 08:51
Location: Germany

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

13 Feb 2017, 04:41

Hi querty12,

don't worry. I didn't want to blame you. Though I am a programmer it's still very COMplicated stuff for me. I think that every further step would require a fully featured implementation of the IDataObject interface. That's still far beyond my skills.

Best regards!

just me
Except as noted otherwise all of my code is tested on Win 10 Pro (x64) using the current AHK version.
just me
Posts: 4288
Joined: 02 Oct 2013, 08:51
Location: Germany

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

13 Feb 2017, 05:02

Hi zcooler,

I know which application you are talking about. And I already tried to explain you why it's 'unstable' sometimes.

You cannot use a drag image or a drop description in this case. But it's easy to use user-defined cursors while dragging. I'll update the GitHub repository as soon as I'm ready. Might be better than nothing. ;)

Regards,

just me
Except as noted otherwise all of my code is tested on Win 10 Pro (x64) using the current AHK version.
zcooler
Posts: 380
Joined: 11 Jan 2014, 04:59

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

13 Feb 2017, 12:41

Greetings Oh Great One :D

just me wrote:I know which application you are talking about. And I already tried to explain you why it's 'unstable' sometimes.
Sorry Just me, our discussions about this script/app have been so plentyful I cannot remember em all. It was quite some time ago also. A very long break from AHK doesnt make things clearer either. Took up golfing instead ;) To not stray too much off topic I can only say its not unstable, more like a smaller quirk. Im aware how to aviod a drag operation initialization failure with my script now. Key is "slow dragging". To be clear (for others that are interested in using Just me`s COM D&D interface) this is an AHK related quirk in my script and has nothing to do with the COM D&D interface or the Demo I posted above.

just me wrote:You cannot use a drag image or a drop description in this case.
Yes that is obvious, no drag image or a drop description (upon pressing SHIFT or Ctrl when dragging within source window/folder as the Shell) when a drag operation initialization fails or are you referring to something else?

just me wrote:But it's easy to use user-defined cursors while dragging. I'll update the GitHub repository as soon as I'm ready. Might be better than nothing. ;)
That is fantastic news, Just me :mrgreen:

Best regards
zcooler
just me
Posts: 4288
Joined: 02 Oct 2013, 08:51
Location: Germany

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

14 Feb 2017, 10:45

Ok, updated package available on GitHub.
Except as noted otherwise all of my code is tested on Win 10 Pro (x64) using the current AHK version.
zcooler
Posts: 380
Joined: 11 Jan 2014, 04:59

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

14 Feb 2017, 11:42

Greetings Just me,
Wow, you move swift like the wind :mrgreen: Maybe adding user-defined cursors was just as easy as you were stating earlier...well easy for you, but really hard for the rest of us ;)

I kept the IDC_CROSS for DROPEFFECT_COPY which also is used on the DROPESCRIPTION in the Shell (to display adding/copy).
I exchanged the UpArrow to IDC_SIZEALL Four-pointed white arrow pointing north, south, east, and west for DROPEFFECT_MOVE operations. The Shell DROPESCRIPTION uses a black rightpointed arrow here, but that one wasnt available amongst the Win10 cursors. Although white cursors are preferrable cuz the contrast/visibility is better on top of black text.

Pretty nice additions indeed :clap: It is now easier to see the drag initialization even though I will keep on dreaming about those cool drag images displaying movie and series thumbnails ;) Maybe some day :lol:
Thank you, Just me :)

Best regards
zcooler
just me
Posts: 4288
Joined: 02 Oct 2013, 08:51
Location: Germany

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

14 Feb 2017, 16:17

It's not restricted to available system cursors. You also could create your own cursors and use (e.g.) LoadCursorFromFile().
Except as noted otherwise all of my code is tested on Win 10 Pro (x64) using the current AHK version.
just me
Posts: 4288
Joined: 02 Oct 2013, 08:51
Location: Germany

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

17 Mar 2017, 11:23

Well, I finally found a simple solution providing basic support for drag images with an AHK drop source on Win Vista+. It's a combination of SHDoDragDrop() - API and SHCreateDataObject() - Win Vista+.

SHDoDragDrop - API wrote:As of Windows Vista, if a drag image is not already stored in the data object pdtobj and a drag image cannot be obtained from the window specified by hwnd, the Shell provides a generic drag image. A drag image can fail to be obtained from the specified window either because hwnd is NULL or the specified window does not support the DI_GETDRAGIMAGE message.
But using it passing a data object retrieved by OleGetClipboard() it doesn't. Apparently, this data object lacks a sufficient implementation of IDataObject.SetData() needed to add a drag image.

On Win Vista+ SHCreateDataObject() is able to create the sufficient data object and to embed the contents of the data object returned by OleGetClipboard(). So SHDoDragDrop() - API is able to use a user-defined drag image or to create a default image on demand. There are three options:
  1. If you pass NULL in the HWND parameter or if the window/control specified by the passed HWND doesn't create a drag image a default (blank) drag image and a textual drop description will be used.
  2. If the windoe/control specified by the passed HWND creates a drag image (e.g. ListView and TreeView controls are able to do it), this drag image will be used in combination with a 'modern' drag cursor.
  3. If you pass a handle of a bitmap (HBITMAP) in DragImage SHDoDragDrop() - AHK tries to create an own drag image. On success, it will be used in combination with a 'modern' drag cursor.

I've added/updated the sources on GitHub.

Changes:
  • Added SHDataObject.ahk
  • Added SHDoDragDrop.ahk
  • Added SHDoDragDrop_sample.ahk
  • Changed IDataObject.ahk (added some auxiliary functions).
  • Changed IDropTarget.ahk to respect the 'preferred drop effect'
Except as noted otherwise all of my code is tested on Win 10 Pro (x64) using the current AHK version.
zcooler
Posts: 380
Joined: 11 Jan 2014, 04:59

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

17 Mar 2017, 13:53

OHHHH JEEEZ....a test blowout coming up during the weekend :dance:
zcooler
Posts: 380
Joined: 11 Jan 2014, 04:59

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

18 Mar 2017, 06:37

SWEET MOTHER OF GOD :shock: That is a huge breakthrough and you are fantastic, Just me :bravo: Truely ROCKSTAR level stuff :mrgreen:

In a broader D&D interface implementation perspective into my app it is no problem to retrieve the icon associated with the file which is usually used as the DragImage. However I have no idea how to retrieve thumbnail paths for media files programatically. The shell D&D interface do prioritize thumbnail dragimages before icons. Well, I will have to investigate that one since it is not within scope of your D&D interface.

Chockingly well done, Just me :superhappy: Praise the Just me :lol: ;)

Best regards
zcooler :wave:

Return to “Ask For Help”

Who is online

Users browsing this forum: Capn Odin, dumbo, Spawnova, Yahoo [Bot] and 26 guests