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

谁说我不能喝 提交于 2020-01-06 08:42:20

问题


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?


回答1:


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.



回答2:


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
}


来源:https://stackoverflow.com/questions/54451041/is-it-possible-to-distinguish-between-attachments-added-with-drag-and-drop-and-v

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!