Ejemplo n.º 1
0
        private static void SetDropTip(IDataObject pdtobj, DROPIMAGETYPE type, string pszMsg, string pszInsert)
        {
            var dd = new DROPDESCRIPTION {
                type = type, szMessage = pszMsg, szInsert = pszInsert
            };
            var hmem = dd.MarshalToPtr(Marshal.AllocHGlobal, out var _);

            try { SetBlob(pdtobj, (short)RegisterClipboardFormat(ShellClipboardFormat.CFSTR_DROPDESCRIPTION), hmem); }
            catch { Marshal.FreeHGlobal(hmem); }
        }
Ejemplo n.º 2
0
        public static void SetDescription(IDataObject dataObject, DropImageType type, string message, string insert)
        {
            var formatETC = new FORMATETC
            {
                cfFormat = (short)RegisterClipboardFormat("DropDescription"),
                dwAspect = DVASPECT.DVASPECT_CONTENT,
                lindex   = -1,
                ptd      = IntPtr.Zero,
                tymed    = TYMED.TYMED_HGLOBAL
            };

            var dropDescription = new DROPDESCRIPTION
            {
                type      = (int)type,
                szMessage = message,
                szInsert  = insert,
            };

            var pointer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DROPDESCRIPTION)));

            try
            {
                Marshal.StructureToPtr(dropDescription, pointer, false);

                var medium = new STGMEDIUM
                {
                    pUnkForRelease = null,
                    tymed          = TYMED.TYMED_HGLOBAL,
                    unionmember    = pointer,
                };

                dataObject.SetData(ref formatETC, ref medium, true);
            }
            catch
            {
                Marshal.FreeHGlobal(pointer);
                // throw;
            }
        }