Results 1 to 15 of 15

Thread: Cursor Image

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    524

    Cursor Image

    How to make cursor image like this program?

    http://www.filefront.com/14858479/La...%20Builder.rar

    I want to make Launcher like this but i can't make it even with autoupdater ;[

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Cursor Image

    can you post a screenshot?

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    524

    Re: Cursor Image

    on the screenshot don't show mouse cursor

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Cursor Image

    ok. here's how to do it:

    this is the class that contains the CreateCursor function:

    vb Code:
    1. Imports System.Windows.Forms
    2. Imports System.Runtime.InteropServices
    3. Imports System.drawing
    4. ''' <summary>
    5. ''' contains API + local functions for creating
    6. ''' a cursor from a bitmap on the fly
    7. ''' </summary>
    8. ''' <remarks></remarks>
    9. Public Class create
    10.  
    11. #Region "   CreateIconIndirect"
    12.  
    13.     Private Structure IconInfo
    14.         Public fIcon As Boolean
    15.         Public xHotspot As Int32
    16.         Public yHotspot As Int32
    17.         Public hbmMask As IntPtr
    18.         Public hbmColor As IntPtr
    19.     End Structure
    20.  
    21.     <DllImport("user32.dll", EntryPoint:="CreateIconIndirect")> _
    22.     Private Shared Function CreateIconIndirect(ByVal iconInfo As IntPtr) As IntPtr
    23.     End Function
    24.  
    25.     <DllImport("user32.dll", CharSet:=CharSet.Auto)> _
    26.     Public Shared Function DestroyIcon(ByVal handle As IntPtr) As Boolean
    27.     End Function
    28.  
    29.     <DllImport("gdi32.dll")> _
    30.     Public Shared Function DeleteObject(ByVal hObject As IntPtr) As Boolean
    31.     End Function
    32.  
    33.     ''' <summary>
    34.     ''' CreateCursor
    35.     ''' </summary>
    36.     ''' <param name="bmp"></param>
    37.     ''' <returns>custom Cursor</returns>
    38.     ''' <remarks>creates a custom cursor from a bitmap</remarks>
    39.     Public Shared Function CreateCursor(ByVal bmp As Bitmap, ByVal xHotspot As Integer, ByVal yHotspot As Integer) As Cursor
    40.         'Setup the Cursors IconInfo
    41.         Dim tmp As New IconInfo
    42.         tmp.xHotspot = xHotspot
    43.         tmp.yHotspot = yHotspot
    44.         tmp.fIcon = False
    45.         tmp.hbmMask = bmp.GetHbitmap()
    46.         tmp.hbmColor = bmp.GetHbitmap()
    47.  
    48.         'Create the Pointer for the Cursor Icon
    49.         Dim pnt As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(tmp))
    50.         Marshal.StructureToPtr(tmp, pnt, True)
    51.         Dim curPtr As IntPtr = CreateIconIndirect(pnt)
    52.  
    53.         'Clean Up
    54.         DestroyIcon(pnt)
    55.         DeleteObject(tmp.hbmMask)
    56.         DeleteObject(tmp.hbmColor)
    57.  
    58.         Return New Cursor(curPtr)
    59.     End Function
    60.  
    61. #End Region
    62.  
    63. End Class

    to use it:

    vb Code:
    1. me.cursor = CreateCursor(img, xHotspot, yHotspot)

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    524

    Re: Cursor Image

    the first code i must make it .dll ?
    and do i need any picture ?

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Cursor Image

    you just need to add a class + name it 'create', then you can paste the code into it.

    you pass any bitmap to it. if you want transparent areas in the bitmap, use the bitmaps maketransparent method before you call the createcursor function.


    edit: change it from Public class to Friend Class
    Last edited by .paul.; Mar 9th, 2010 at 07:43 PM.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    524

    Re: Cursor Image

    i have problem i make what you sayd but when i start i get error
    Error 1 Name 'CreateCursor' is not declared.

    i make new class with the name that you say insert the text i removed lines 1 2 3 .. and ' and # that are and add in Form1_Load the code and the words are underlined or can you make a full program with that cursor only and share me

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Cursor Image

    can you post the code you tried?

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    524

    Re: Cursor Image

    i have closed the project i don't keep it but can you make 1 program with only cursor that i need i will take a look in the source

  10. #10
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Cursor Image

    here's how to use it:
    Attached Files Attached Files

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    524

    Re: Cursor Image

    thanks i see the code is alot diferent that you show me before

  12. #12
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Cursor Image

    Quote Originally Posted by diablo21 View Post
    thanks i see the code is alot diferent that you show me before
    not really. i just copied + pasted it from this thread. i changed Public Class to Friend Class, as i told you you should. the only thing that is different is when calling the createcursor function, i used create.createcursor

  13. #13
    Frenzied Member
    Join Date
    Jul 2006
    Location
    MI
    Posts
    2,012

    Re: Cursor Image

    paul ... nice demo. I have a few questions:

    1) will this work using an animated gif?

    2) how can I display text instead of an image? ie. I would like the cursor to say "Please wait" while some time consuming process runs.

  14. #14
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Cursor Image

    1/ probably not, but i haven't tried it. edit: it doesn't work with an animated gif

    2/ Dim textSize As SizeF = Me.CreateGraphics().MeasureString("Please wait", Me.Font, Me.Size, Drawing.StringFormat.GenericTypographic)
    Dim img As New Bitmap(CInt(textSize.Width) + 5, CInt(textSize.Height) + 1)
    Dim gr As Graphics = Graphics.FromImage(img)
    gr.Clear(Color.White)
    gr.DrawString("Please wait", Me.Font, Brushes.Black, 0, 0)
    img.MakeTransparent(Color.White)
    Me.Cursor = create.CreateCursor(img, 0, 0)
    Last edited by .paul.; Mar 10th, 2010 at 06:03 PM.

  15. #15
    Frenzied Member
    Join Date
    Jul 2006
    Location
    MI
    Posts
    2,012

    Re: Cursor Image

    Thanks ... works great!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width