Search code examples
c#outlookoutlook-addinemail-attachments

Is it possible to distinguish between attachments added with drag and drop and via the attachment menu button


I have an outlook add-in that handles email attachments. I have my own ribbon button to add attachments but I would like to catch attachments added via drag and drop while ignoring attachments added using the standard attachment button.

It is easy enough to implement a ItemEvents_10_BeforeAttachmentAddEventHandler() but I know of no way to distinguish between attachments added with drag and drop and via the attachment menu button.

Is this possible?

Is it possible to handle the drag and drop event directly my self?


Solution

  • OOM won't help you here. In theory, you can overwrite the Outlook drag/drop handler.

    1. Get the Inspector's window handle using the IOleWindow interface (you can cast Inspector object to IOleWindow).
    2. Get the existing drag/drop handler using GetProp(hwnd, "OleDropTargetInterface") Windows API - cast the returned value to IDropTarget interface. You probably need to experiment with which child window of the inspector is the drag/drop target you want.
    3. Call RevokeDragDrop / RegisterDragDrop passing your own implementation of IDropTarget. That implementation can then (after doing what you need to do) call the original IDropTarget interface to let Outlook proceed with the default behavior.