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. Managed C++/CLI
  4. Cursor, converting code from vb.net to c++

Cursor, converting code from vb.net to c++

Scheduled Pinned Locked Moved Managed C++/CLI
csharpc++graphicsworkspace
2 Posts 1 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.
  • A Offline
    A Offline
    Andreoli Carlo
    wrote on last edited by
    #1

    hello i'm trying to convert this piece of code from vb

    Private Structure IconInfo
    Public fIcon As Boolean
    Public xHotspot As Int32
    Public yHotspot As Int32
    Public hbmMask As IntPtr
    Public hbmColor As IntPtr
    End Structure

    <DllImport("user32.dll", EntryPoint:="CreateIconIndirect")> \_
    Private Shared Function CreateIconIndirect(ByVal iconInfo As IntPtr) As IntPtr
    End Function
    
    <DllImport("user32.dll", CharSet:=CharSet.Auto)> \_
    Public Shared Function DestroyIcon(ByVal handle As IntPtr) As Boolean
    End Function
    
    <DllImport("gdi32.dll")> \_
    Public Shared Function DeleteObject(ByVal hObject As IntPtr) As Boolean
    End Function
    
    Public Function CreateCursor(ByVal bmp As Bitmap) As Cursor
    
        'Setup the Cursors IconInfo
        Dim tmp As New IconInfo
        tmp.xHotspot = \_gHotSpotPt.X
        tmp.yHotspot = \_gHotSpotPt.Y
        tmp.fIcon = False
        If \_gBlackBitBack Then
            tmp.hbmMask = bmp.GetHbitmap(Color.FromArgb(0, 0, 0, 0))
            tmp.hbmColor = bmp.GetHbitmap(Color.FromArgb(0, 0, 0, 0))
        Else
            tmp.hbmMask = bmp.GetHbitmap()
            tmp.hbmColor = bmp.GetHbitmap()
        End If
    
        'Create the Pointer for the Cursor Icon
        Dim pnt As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(tmp))
        Marshal.StructureToPtr(tmp, pnt, True)
        Dim curPtr As IntPtr = CreateIconIndirect(pnt)
    
        'Save the image of the cursor with the \_gBlackBitBack effect
        'Not really needed for normal use.
        'I use it to create a screen shot with the gCursor included
        \_gCursorImage = Icon.FromHandle(curPtr).ToBitmap
    
        'Clean Up
        DestroyIcon(pnt)
        DeleteObject(tmp.hbmMask)
        DeleteObject(tmp.hbmColor)
    
        Return New Cursor(curPtr)
    End Function
    

    By now i traslate the all thing into:

    public struct IconInfo
    {
    bool fIcon;
    int xHotspot;
    int yHotspot;
    System::IntPtr hbmMask;
    System::IntPtr hbmColor;
    };

    \[System::Runtime::InteropServices::DllImport("user32.dll, EntryPoint:=CreateIconIndirect")\]
    System::IntPtr CreateIconIndirect(System::IntPtr iconInfo);
    
    \[System::Runtime::InteropServices::DllImport("user32.dll, CharSet:=CharSet.Auto")\]
    bool  DestroyIcon(System::IntPtr handle);
    
    \[System::Runtime::InteropServices::DllImport("gdi32.dll")\]
    bool DeleteObject(System::IntPtr handl);
    

    System::Windows::Forms::Cursor ^CreateCurs

    A 1 Reply Last reply
    0
    • A Andreoli Carlo

      hello i'm trying to convert this piece of code from vb

      Private Structure IconInfo
      Public fIcon As Boolean
      Public xHotspot As Int32
      Public yHotspot As Int32
      Public hbmMask As IntPtr
      Public hbmColor As IntPtr
      End Structure

      <DllImport("user32.dll", EntryPoint:="CreateIconIndirect")> \_
      Private Shared Function CreateIconIndirect(ByVal iconInfo As IntPtr) As IntPtr
      End Function
      
      <DllImport("user32.dll", CharSet:=CharSet.Auto)> \_
      Public Shared Function DestroyIcon(ByVal handle As IntPtr) As Boolean
      End Function
      
      <DllImport("gdi32.dll")> \_
      Public Shared Function DeleteObject(ByVal hObject As IntPtr) As Boolean
      End Function
      
      Public Function CreateCursor(ByVal bmp As Bitmap) As Cursor
      
          'Setup the Cursors IconInfo
          Dim tmp As New IconInfo
          tmp.xHotspot = \_gHotSpotPt.X
          tmp.yHotspot = \_gHotSpotPt.Y
          tmp.fIcon = False
          If \_gBlackBitBack Then
              tmp.hbmMask = bmp.GetHbitmap(Color.FromArgb(0, 0, 0, 0))
              tmp.hbmColor = bmp.GetHbitmap(Color.FromArgb(0, 0, 0, 0))
          Else
              tmp.hbmMask = bmp.GetHbitmap()
              tmp.hbmColor = bmp.GetHbitmap()
          End If
      
          'Create the Pointer for the Cursor Icon
          Dim pnt As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(tmp))
          Marshal.StructureToPtr(tmp, pnt, True)
          Dim curPtr As IntPtr = CreateIconIndirect(pnt)
      
          'Save the image of the cursor with the \_gBlackBitBack effect
          'Not really needed for normal use.
          'I use it to create a screen shot with the gCursor included
          \_gCursorImage = Icon.FromHandle(curPtr).ToBitmap
      
          'Clean Up
          DestroyIcon(pnt)
          DeleteObject(tmp.hbmMask)
          DeleteObject(tmp.hbmColor)
      
          Return New Cursor(curPtr)
      End Function
      

      By now i traslate the all thing into:

      public struct IconInfo
      {
      bool fIcon;
      int xHotspot;
      int yHotspot;
      System::IntPtr hbmMask;
      System::IntPtr hbmColor;
      };

      \[System::Runtime::InteropServices::DllImport("user32.dll, EntryPoint:=CreateIconIndirect")\]
      System::IntPtr CreateIconIndirect(System::IntPtr iconInfo);
      
      \[System::Runtime::InteropServices::DllImport("user32.dll, CharSet:=CharSet.Auto")\]
      bool  DestroyIcon(System::IntPtr handle);
      
      \[System::Runtime::InteropServices::DllImport("gdi32.dll")\]
      bool DeleteObject(System::IntPtr handl);
      

      System::Windows::Forms::Cursor ^CreateCurs

      A Offline
      A Offline
      Andreoli Carlo
      wrote on last edited by
      #2

      ok i get it if you wanna know

      value class IconInfo
      {
      public:
      bool fIcon;
      Int32 xHotspot;
      Int32 yHotspot;
      IntPtr hbmMask;
      IntPtr hbmColor;
      };

      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