Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Calling InitializeFromBitmap fails with exception "The method or operation is not implemented"

Calling InitializeFromBitmap fails with exception "The method or operation is not implemented"

Scheduled Pinned Locked Moved C#
graphicsquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KeesVer
    wrote on last edited by
    #1

    Hello, I have the following code in one of my projects: DragDropHelper Helper = new DragDropHelper(); // See below! IDragSourceHelper Drag = (IDragSourceHelper)Helper; SHDRAGIMAGE tt = new SHDRAGIMAGE(); Bitmap img = new Bitmap(@"C:\Temp\DragImage.bmp"); tt.ptOffset.x = 0; tt.ptOffset.y = 0; tt.sizeDragImage.x = img.Width; tt.sizeDragImage.y = img.Height; tt.hbmpDragImage = img.GetHbitmap(); tt.crColorKey = 0; Drag.InitializeFromBitmap(ref tt, dragObject); Calling InitializeFromBitmap fails with the above mentioned message. Can any one tell me why? In addition, this code is in my project as well: [StructLayout(LayoutKind.Sequential)] public struct POINT { public int x; public int y; } [StructLayout(LayoutKind.Sequential)] public struct SHDRAGIMAGE { public POINT sizeDragImage; public POINT ptOffset; public IntPtr hbmpDragImage; public uint crColorKey; } [ComImport, Guid("DE5BF786-477A-11d2-839D-00C04FD918D0"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] interface IDragSourceHelper { void InitializeFromBitmap( ref SHDRAGIMAGE pshdi, [MarshalAs(UnmanagedType.Interface)] System.Runtime.InteropServices.ComTypes.IDataObject pDataObject); void InitializeFromWindow( IntPtr hwnd, ref POINT point, [MarshalAs(UnmanagedType.Interface)] System.Runtime.InteropServices.ComTypes.IDataObject pDataObject); } [ComImport, Guid("4657278B-411B-11d2-839A-00C04FD918D0"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] interface IDropTargetHelper { void DragEnter(IntPtr hwnd, [MarshalAs(UnmanagedType.Interface)] System.Runtime.InteropServices.ComTypes.IDataObject pDataObject, ref POINT point, DragDropEffects dwEffect); void DragLeave(); void DragOver(ref POINT point, DragDropEffects dwEffect); void Drop([MarshalAs(UnmanagedType.Interface)] System.Runtime.InteropServices.ComTypes.IDataObject pDataObject, ref POINT point, DragDropEffects dwEffect); void Show([MarshalAs(UnmanagedType.Bool)] bool fShow); } [ComImport, Guid("4657278A-411B-11d2-839A-00C04FD918D0")] class DragDropHelper { }

    K 1 Reply Last reply
    0
    • K KeesVer

      Hello, I have the following code in one of my projects: DragDropHelper Helper = new DragDropHelper(); // See below! IDragSourceHelper Drag = (IDragSourceHelper)Helper; SHDRAGIMAGE tt = new SHDRAGIMAGE(); Bitmap img = new Bitmap(@"C:\Temp\DragImage.bmp"); tt.ptOffset.x = 0; tt.ptOffset.y = 0; tt.sizeDragImage.x = img.Width; tt.sizeDragImage.y = img.Height; tt.hbmpDragImage = img.GetHbitmap(); tt.crColorKey = 0; Drag.InitializeFromBitmap(ref tt, dragObject); Calling InitializeFromBitmap fails with the above mentioned message. Can any one tell me why? In addition, this code is in my project as well: [StructLayout(LayoutKind.Sequential)] public struct POINT { public int x; public int y; } [StructLayout(LayoutKind.Sequential)] public struct SHDRAGIMAGE { public POINT sizeDragImage; public POINT ptOffset; public IntPtr hbmpDragImage; public uint crColorKey; } [ComImport, Guid("DE5BF786-477A-11d2-839D-00C04FD918D0"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] interface IDragSourceHelper { void InitializeFromBitmap( ref SHDRAGIMAGE pshdi, [MarshalAs(UnmanagedType.Interface)] System.Runtime.InteropServices.ComTypes.IDataObject pDataObject); void InitializeFromWindow( IntPtr hwnd, ref POINT point, [MarshalAs(UnmanagedType.Interface)] System.Runtime.InteropServices.ComTypes.IDataObject pDataObject); } [ComImport, Guid("4657278B-411B-11d2-839A-00C04FD918D0"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] interface IDropTargetHelper { void DragEnter(IntPtr hwnd, [MarshalAs(UnmanagedType.Interface)] System.Runtime.InteropServices.ComTypes.IDataObject pDataObject, ref POINT point, DragDropEffects dwEffect); void DragLeave(); void DragOver(ref POINT point, DragDropEffects dwEffect); void Drop([MarshalAs(UnmanagedType.Interface)] System.Runtime.InteropServices.ComTypes.IDataObject pDataObject, ref POINT point, DragDropEffects dwEffect); void Show([MarshalAs(UnmanagedType.Bool)] bool fShow); } [ComImport, Guid("4657278A-411B-11d2-839A-00C04FD918D0")] class DragDropHelper { }

      K Offline
      K Offline
      KaptinKrunch
      wrote on last edited by
      #2

      If I've read your code and problem right, the problem became clear. The method or operation is not implemented. Now to be serious, MSDN reports that the minimal dll version is shell32.dll v5.0. Do you meet this requirement? Does marshaling IDragSourceHelper require you to define the GetData() method? Not sure myself.

      Just because we can; does not mean we should.

      K 1 Reply Last reply
      0
      • K KaptinKrunch

        If I've read your code and problem right, the problem became clear. The method or operation is not implemented. Now to be serious, MSDN reports that the minimal dll version is shell32.dll v5.0. Do you meet this requirement? Does marshaling IDragSourceHelper require you to define the GetData() method? Not sure myself.

        Just because we can; does not mean we should.

        K Offline
        K Offline
        KeesVer
        wrote on last edited by
        #3

        Thanks for your reply. Meanwhile I've come a lot further. The problem was that methods SetData and GetData where not implemented. Therefore I created a new DataObject class which re-implements these methods. This is the code I have so far which is working but needs some adjustments here and there. Also I'm not sure whether all allocated objects are released correctly. Regards, Kees public partial class CustomControl1 : Control { DragDropHelper Helper; public CustomControl1() { InitializeComponent(); this.AllowDrop = true; } protected override void OnPaint(PaintEventArgs pe) { Brush B = new SolidBrush(Color.White); pe.Graphics.FillRectangle(B, pe.ClipRectangle); } protected override void OnMouseDown(MouseEventArgs e) { DataFormats.Format ganttbarFormat = DataFormats.GetFormat("Ganttbar"); object ganttbar = new object(); DataObject dragObject = new DataObjectEx(ganttbarFormat.Name, ganttbar); DoDragDrop(dragObject, DragDropEffects.All); } private void UpdateDragImage(System.Runtime.InteropServices.ComTypes.IDataObject dragObject) { if (Helper == null) { Helper = new DragDropHelper(); } IDragSourceHelper Drag = (IDragSourceHelper)Helper; SHDRAGIMAGE tt = new SHDRAGIMAGE(); Bitmap img = new Bitmap(@"C:\Temp\DragImage.bmp"); tt.ptOffset.x = 0; tt.ptOffset.y = 0; tt.sizeDragImage.x = img.Width; tt.sizeDragImage.y = img.Height; tt.hbmpDragImage = img.GetHbitmap(); tt.crColorKey = 0; Drag.InitializeFromBitmap(ref tt, dragObject); } protected override void OnDragOver(DragEventArgs drgevent) { IDropTargetHelper H = (IDropTargetHelper)Helper; POINT p = new POINT(); p.x = drgevent.X; p.y = drgevent.Y; H.DragOver(ref p, DragDropEffects.Copy); drgevent.Effect = DragDropEffects.Copy; } protected override void OnDragDrop(DragEventArgs drgevent) { System.Runtime.InteropServices.ComTypes.IDataObject dragObject = (System.Runtime.InteropServices.ComTypes.IDataObject)drgevent.Data; IDropTargetHelper H = (IDropTargetHelper)Helper; POINT p = new POINT(); p.x = drgevent.X; p.y = drgevent.Y; H.Drop(dragObject, ref p, DragDropEffects.Copy); base.OnDragDrop(drgevent); } protected override void OnDragEnter(DragEventArgs drgevent)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups