Cursor, converting code from vb.net to c++
-
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
-
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
ok i get it if you wanna know
value class IconInfo
{
public:
bool fIcon;
Int32 xHotspot;
Int32 yHotspot;
IntPtr hbmMask;
IntPtr hbmColor;
};