问题
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.
- Get the Inspector's window handle using the
IOleWindow
interface (you can castInspector
object toIOleWindow
). - Get the existing drag/drop handler using
GetProp(hwnd, "OleDropTargetInterface")
Windows API - cast the returned value toIDropTarget
interface. You probably need to experiment with which child window of the inspector is the drag/drop target you want. - Call
RevokeDragDrop
/RegisterDragDrop
passing your own implementation ofIDropTarget
. That implementation can then (after doing what you need to do) call the originalIDropTarget
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