Beispiel #1
0
        public static int DoDragDropHook(NativeMethods.IDataObject pDataObj, NativeMethods.IDropSource pDropSource, uint dwOKEffects, uint[] pdwEffect)
        {
            try
            {
                log.Info("Drag started");
                if (!DataObjectHelper.GetDataPresent(pDataObj, "FileGroupDescriptorW"))
                {
                    log.Info("No virtual files found -- continuing original drag");
                    return(NativeMethods.DoDragDrop(pDataObj, pDropSource, dwOKEffects, pdwEffect));
                }

                //Start new drag
                log.Info("Virtual files found -- starting new drag adding CF_HDROP format");
                log.InfoFormat("Files: {0}", string.Join(",", DataObjectHelper.GetFilenames(pDataObj)));

                NativeMethods.IDataObject newDataObj = new OutlookDataObject(pDataObj);
                int result = NativeMethods.DoDragDrop(newDataObj, pDropSource, dwOKEffects, pdwEffect);

                //Get result
                log.InfoFormat("DoDragDrop result: {0}", result);
                return(result);
            }
            catch (Exception ex)
            {
                log.Warn("Dragging error", ex);
                return(NativeMethods.DRAGDROP_S_CANCEL);
            }
        }
        public static int DoDragDropHook(NativeMethods.IDataObject pDataObj, IntPtr pDropSource, uint dwOKEffects, out uint pdwEffect)
        {
            try
            {
                log.Info("Drag started");
                if (!DataObjectHelper.GetDataPresent(pDataObj, "FileGroupDescriptorW") && !DataObjectHelper.GetDataPresent(pDataObj, "FileGroupDescriptor"))
                {
                    log.Info("No virtual files found -- continuing original drag");
                    return(NativeMethods.DoDragDrop(pDataObj, pDropSource, dwOKEffects, out pdwEffect));
                }

                //Start new drag
                log.Info("Virtual files found -- starting new drag adding CF_HDROP format");
                log.InfoFormat("Files: {0}", string.Join(",", DataObjectHelper.GetFilenames(pDataObj)));

                OutlookDataObject newDataObj = new OutlookDataObject(pDataObj);
                int result = NativeMethods.DoDragDrop(newDataObj, pDropSource, dwOKEffects, out pdwEffect);

                //If files were dropped and drop effect was "move", then override to "copy" so original item is not deleted
                if (newDataObj.FilesDropped && pdwEffect == NativeMethods.DROPEFFECT_MOVE)
                {
                    pdwEffect = NativeMethods.DROPEFFECT_COPY;
                }

                //Get result
                log.InfoFormat("DoDragDrop effect: {0} result: {1}", pdwEffect, result);
                return(result);
            }
            catch (Exception ex)
            {
                log.Warn("Dragging error", ex);
                pdwEffect = NativeMethods.DROPEFFECT_NONE;
                return(NativeMethods.DRAGDROP_S_CANCEL);
            }
        }