/// <summary>
        /// Notifies the DragDropHelper that the current Control received
        /// a Drop event.
        /// </summary>
        /// <param name="dropHelper">The DragDropHelper instance to notify.</param>
        /// <param name="data">The DataObject containing a drag image.</param>
        /// <param name="cursorOffset">The current cursor's offset relative to the window.</param>
        /// <param name="effect">The accepted drag drop effect.</param>
        public static void Drop(this IDropTargetHelper dropHelper, System.Windows.Forms.IDataObject data, Point cursorOffset,
                                DragDropEffects effect)
        {
            Win32Point pt = cursorOffset.ToWin32Point();

            dropHelper.Drop((ComIDataObject)data, ref pt, (int)effect);
        }
Example #2
0
        public static void DisableDropDescription(this System.Windows.Forms.IDataObject dataObject)
        {
            DropDescription description;

            description.type      = -1;
            description.szMessage = null;
            description.szInsert  = null;
            ((IDataObject)dataObject).SetDropDescription(description);
        }
Example #3
0
        /// <summary>
        /// Sets the drag image as the rendering of a control.
        /// </summary>
        /// <param name="dataObject">The DataObject to set the drag image on.</param>
        /// <param name="control">The Control to render as the drag image.</param>
        /// <param name="cursorOffset">The location of the cursor relative to the control.</param>
        public static void SetDragImage(this System.Windows.Forms.IDataObject dataObject, Control control, Point cursorOffset)
        {
            int width  = control.Width;
            int height = control.Height;

            var bmp = new Bitmap(width, height);

            control.DrawToBitmap(bmp, new Rectangle(0, 0, width, height));

            SetDragImage(dataObject, bmp, cursorOffset);
        }
Example #4
0
        /// <summary>
        /// Sets managed data to a clipboard DataObject.
        /// </summary>
        /// <param name="dataObject">The DataObject to set the data on.</param>
        /// <param name="format">The clipboard format.</param>
        /// <param name="data">The data object.</param>
        /// <remarks>
        /// Because the underlying data store is not storing managed objects, but
        /// unmanaged ones, this function provides intelligent conversion, allowing
        /// you to set unmanaged data into the COM implemented IDataObject.</remarks>
        public static void SetDataEx(this System.Windows.Forms.IDataObject dataObject, string format, object data)
        {
            DataFormats.Format dataFormat = DataFormats.GetFormat(format);

            // Initialize the format structure
            var formatETC = new FORMATETC();

            formatETC.cfFormat = (short)dataFormat.Id;
            formatETC.dwAspect = DVASPECT.DVASPECT_CONTENT;
            formatETC.lindex   = -1;
            formatETC.ptd      = IntPtr.Zero;

            // Try to discover the TYMED from the format and data
            TYMED tymed = GetCompatibleTymed(format, data);

            // If a TYMED was found, we can use the system DataObject
            // to convert our value for us.
            if (tymed != TYMED.TYMED_NULL)
            {
                formatETC.tymed = tymed;

                // Set data on an empty DataObject instance
                var conv = new System.Windows.Forms.DataObject();
                conv.SetData(format, true, data);

                // Now retrieve the data, using the COM interface.
                // This will perform a managed to unmanaged conversion for us.
                STGMEDIUM medium;
                ((IDataObject)conv).GetData(ref formatETC, out medium);
                try {
                    // Now set the data on our data object
                    ((IDataObject)dataObject).SetData(ref formatETC, ref medium, true);
                }
                catch {
                    // On exceptions, release the medium
                    ReleaseStgMedium(ref medium);
                    throw;
                }
            }
            else
            {
                // Since we couldn't determine a TYMED, this data
                // is likely custom managed data, and won't be used
                // by unmanaged code, so we'll use our custom marshaling
                // implemented by our COM IDataObject extensions.

                ((IDataObject)dataObject).SetManagedData(format, data);
            }
        }
Example #5
0
        /// <summary>
        /// Gets managed data from a clipboard DataObject.
        /// </summary>
        /// <param name="dataObject">The DataObject to obtain the data from.</param>
        /// <param name="format">The format for which to get the data in.</param>
        /// <returns>The data object instance.</returns>
        public static object GetDataEx(this System.Windows.Forms.IDataObject dataObject, string format)
        {
            // Get the data
            object data = dataObject.GetData(format, true);

            // If the data is a stream, we'll check to see if it
            // is stamped by us for custom marshaling
            if (data is Stream)
            {
                object data2 = ((IDataObject)dataObject).GetManagedData(format);
                if (data2 != null)
                {
                    return(data2);
                }
            }

            return(data);
        }
        public int DragEnter(IDataObject pDataObj, uint grfKeyState, tagPOINT pt, ref uint pdwEffect)
        {
            _currendDataObject = null;
              if (pDataObj != null)
            _currendDataObject = new DataObject (pDataObj);

              var args = new ExtendedDragEventHandlerArgs (
              _currendDataObject,
              (int) grfKeyState,
              pt.X,
              pt.Y,
              DragDropEffects.All,
              ToWinForms ((NativeDragDropEffects) pdwEffect));
              _extendedTridentWebBrowser.OnDragEnter (args);

              if (args.Handled)
            pdwEffect = (uint) ToNative (args.Effect);

              return HResult.S_OK;
        }
Example #7
0
        /// <summary>
        /// Sets the drag image.
        /// </summary>
        /// <param name="dataObject">The DataObject to set the drag image on.</param>
        /// <param name="image">The drag image.</param>
        /// <param name="cursorOffset">The location of the cursor relative to the image.</param>
        public static void SetDragImage(this System.Windows.Forms.IDataObject dataObject, Image image, Point cursorOffset)
        {
            var shdi = new ShDragImage();

            Win32Size size;

            size.cx            = image.Width;
            size.cy            = image.Height;
            shdi.sizeDragImage = size;

            Win32Point wpt;

            wpt.x         = cursorOffset.X;
            wpt.y         = cursorOffset.Y;
            shdi.ptOffset = wpt;

            shdi.crColorKey = Color.Magenta.ToArgb();

            // This HBITMAP will be managed by the DragDropHelper
            // as soon as we pass it to InitializeFromBitmap. If we fail
            // to make the hand off, we'll delete it to prevent a mem leak.
            IntPtr hbmp = GetHbitmapFromImage(image);

            shdi.hbmpDragImage = hbmp;

            try {
                var sourceHelper = (IDragSourceHelper) new DragDropHelper();

                try {
                    sourceHelper.InitializeFromBitmap(ref shdi, (ComIDataObject)dataObject);
                }
                catch (NotImplementedException ex) {
                    throw new Exception(
                              "A NotImplementedException was caught. This could be because you forgot to construct your DataObject using a DragDropLib.DataObject",
                              ex);
                }
            }
            catch {
                DeleteObject(hbmp);
            }
        }
Example #8
0
        /// <summary>
        /// Sets the drop description for the drag image manager.
        /// </summary>
        /// <param name="dataObject">The DataObject to set.</param>
        /// <param name="type">The type of the drop image.</param>
        /// <param name="format">The format string for the description.</param>
        /// <param name="insert">The parameter for the drop description.</param>
        /// <remarks>
        /// When setting the drop description, the text can be set in two part,
        /// which will be rendered slightly differently to distinguish the description
        /// from the subject. For example, the format can be set as "Move to %1" and
        /// the insert as "Temp". When rendered, the "%1" in format will be replaced
        /// with "Temp", but "Temp" will be rendered slightly different from "Move to ".
        /// </remarks>
        public static void SetDropDescription(this System.Windows.Forms.IDataObject dataObject, DropImageType type,
                                              string format, string insert)
        {
            if (format != null && format.Length > 259)
            {
                throw new ArgumentException("Format string exceeds the maximum allowed length of 259.", "format");
            }
            if (insert != null && insert.Length > 259)
            {
                throw new ArgumentException("Insert string exceeds the maximum allowed length of 259.", "insert");
            }

            // Fill the structure
            DropDescription dd;

            dd.type      = (int)type;
            dd.szMessage = format;
            dd.szInsert  = insert;

            ((IDataObject)dataObject).SetDropDescription(dd);
        }
        /// <summary>
        /// Notifies the DragDropHelper that the specified Control received
        /// a DragEnter event.
        /// </summary>
        /// <param name="dropHelper">The DragDropHelper instance to notify.</param>
        /// <param name="control">The Control the received the DragEnter event.</param>
        /// <param name="data">The DataObject containing a drag image.</param>
        /// <param name="cursorOffset">The current cursor's offset relative to the window.</param>
        /// <param name="effect">The accepted drag drop effect.</param>
        public static void DragEnter(this IDropTargetHelper dropHelper, Control control, System.Windows.Forms.IDataObject data,
                                     Point cursorOffset, DragDropEffects effect)
        {
            IntPtr controlHandle = IntPtr.Zero;

            if (control != null)
            {
                controlHandle = control.Handle;
            }
            Win32Point pt = cursorOffset.ToWin32Point();

            dropHelper.DragEnter(controlHandle, (ComIDataObject)data, ref pt, (int)effect);
        }
 public int DragLeave()
 {
     _currendDataObject = null;
       _extendedTridentWebBrowser.OnDragLeave (new EventArgs());
       return HResult.S_OK;
 }
Example #11
0
        /// <summary>
        /// Capture the next frame from the video feed
        /// </summary>
        public Image GetNextFrame()
        {
            try
            {

                // get the next frame;
                SendMessage(mCapHwnd, WM_CAP_GET_FRAME, 0, 0);

                // copy the frame to the clipboard
                SendMessage(mCapHwnd, WM_CAP_COPY, 0, 0);

                //if (ImageCaptured != null)
                {
                    // get from the clipboard
                    tempObj = Clipboard.GetDataObject();
                    tempImg = (System.Drawing.Bitmap) tempObj.GetData(System.Windows.Forms.DataFormats.Bitmap);

                   // return tempImg.GetThumbnailImage(m_Width, m_Height, null, System.IntPtr.Zero);

                }

            }

            catch (Exception excep)
            {
                //MessageBox.Show("An error ocurred while capturing the video image. The video capture will now be terminated.\r\n\n" + excep.Message);
                //	this.Stop(); // stop the process
            }

            return tempImg;
        }