Is it possible to distinguish between attachments

2019-08-29 23:48发布

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?

2条回答
混吃等死
2楼-- · 2019-08-30 00:20

I may have found a way to distinguish between attachments added with drag and drop and via the attachment menu button without having to overwrite the drag/drop handler.

When attachments are added via drag and drop the Outlook app is not in the foreground so it has no active window.

In my BeforeAttachmentAdd() event handler I perform the following test:

IntPtr hWnd = GetActiveWindow();                
if (hWnd == IntPtr.Zero) {
// Handle drag and drop attachment
}
查看更多
放荡不羁爱自由
3楼-- · 2019-08-30 00:34

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.
查看更多
登录 后发表回答