Results 1 to 10 of 10

Thread: .cur from resource file / memory stream

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2004
    Posts
    259

    .cur from resource file / memory stream

    i'm trying to add custom mouse icons to my app.
    but i can't seem to do it.

    currently, everything i find on the internet says this code works:

    Code:
            Dim ms As New System.IO.MemoryStream(My.Resources.MouseCursor)
            Me.Cursor = New Cursor(ms)

    but it gives me an error:

    WITH PNG: (compile error)
    Code:
    Error	2	Overload resolution failed because no accessible 'New' can be called with these arguments:
        'Public Sub New(buffer() As Byte)': Value of type 'System.Drawing.Bitmap' cannot be converted to '1-dimensional array of Byte'.
        'Public Sub New(capacity As Integer)': Value of type 'System.Drawing.Bitmap' cannot be converted to 'Integer'.	E:\Users\John Doe\documents\visual studio 2010\Projects\UN Client\UN Client\Form1.vb	388	13	UNClient
    WITH .CUR: (runtime error)
    Code:
    See the end of this message for details on invoking 
    just-in-time (JIT) debugging instead of this dialog box.
    
    ************** Exception Text **************
    System.ArgumentException: Image format is not valid. The image file may be corrupted.
    Parameter name: stream ---> System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x800A01E1 (CTL_E_INVALIDPICTURE)
       at System.Windows.Forms.UnsafeNativeMethods.IPersistStream.Load(IStream pstm)
       at System.Windows.Forms.Cursor.LoadPicture(IStream stream)
       --- End of inner exception stack trace ---
    if someone could explain to me how to use .cur or .png my.resources files as custom mouse cursors then it would be greatly appreciated.
    Last edited by Waxy; Apr 22nd, 2013 at 12:58 AM.
    ----------------------------------------------------

    Missing the days of GWBasic 1.1
    WaxyStudios.com

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: .cur from resource file / memory stream

    If you want to create a Cursor from a resource then you have to have added a cursor to the resource in the first place, not an image. You need to use an application that can generate CUR files. You can just use regular image files like BMP, JPG or PNG. They are not cursors.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2004
    Posts
    259

    Re: .cur from resource file / memory stream

    jmc - i DO have it added as a resource. and set it to EMBEDED RESOURCE.

    i added them in the formats of .cur and .png and neither work.


    edit:

    Code:
            Dim ms As New System.IO.MemoryStream(My.Resources.rCurAttack)
    
            Me.Cursor = New Cursor(ms)
    rCurAttack is a real .cur file added in via the resources tab. properties changed to "Embedded Resource"

    it produces the runtime error.
    Last edited by Waxy; Apr 22nd, 2013 at 01:02 AM.
    ----------------------------------------------------

    Missing the days of GWBasic 1.1
    WaxyStudios.com

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: .cur from resource file / memory stream

    Quote Originally Posted by Waxy View Post
    jmc - i DO have it added as a resource. and set it to EMBEDED RESOURCE.

    i added them in the formats of .cur and .png and neither work.


    edit:

    Code:
            Dim ms As New System.IO.MemoryStream(My.Resources.rCurAttack)
    
            Me.Cursor = New Cursor(ms)
    rCurAttack is a real .cur file added in via the resources tab. properties changed to "Embedded Resource"

    it produces the runtime error.
    And what is the data type of My.Resources.rCurAttack? Could it be that it's already type Cursor?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2004
    Posts
    259

    Re: .cur from resource file / memory stream

    it doesn't recognize it as a cursor.

    Code:
     Me.Cursor = My.Resources.rCurAttack
    Code:
    Error	1	Value of type '1-dimensional array of Byte' cannot be converted to 'System.Windows.Forms.Cursor'.	E:\Users\John Doe\documents\visual studio 2010\Projects\UN Client\UN Client\Form1.vb	391	21	UNClient
    that's why i was trying some tutorials and came out with that example poping up over and over again on the magic google.

    are only certain cursor formats recognized? it's a 32x32 cursor.


    EDIT:

    attached: the cursor .cur and .png as zip
    cursors..zip
    Last edited by Waxy; Apr 22nd, 2013 at 01:16 AM.
    ----------------------------------------------------

    Missing the days of GWBasic 1.1
    WaxyStudios.com

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: .cur from resource file / memory stream

    OK then, so what happens when you execute the code that you posted in post #3?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2004
    Posts
    259

    Re: .cur from resource file / memory stream

    #3 produces run time error:
    Code:
    See the end of this message for details on invoking 
    just-in-time (JIT) debugging instead of this dialog box.
    
    ************** Exception Text **************
    System.ArgumentException: Image format is not valid. The image file may be corrupted.
    Parameter name: stream ---> System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x800A01E1 (CTL_E_INVALIDPICTURE)
       at System.Windows.Forms.UnsafeNativeMethods.IPersistStream.Load(IStream pstm)
       at System.Windows.Forms.Cursor.LoadPicture(IStream stream)
       --- End of inner exception stack trace ---
    i just got done converting it to 24 bit (down from 32) and it produces the same error.
    ----------------------------------------------------

    Missing the days of GWBasic 1.1
    WaxyStudios.com

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: .cur from resource file / memory stream

    This is a bit of a guess but try setting the Position of the MemoryStream to zero before creating the Cursor.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2004
    Posts
    259

    Re: .cur from resource file / memory stream

    Code:
      Dim ms As New System.IO.MemoryStream(My.Resources.rCurAttack)
            ms.Position = 0
            Me.Cursor = New Cursor(ms)
    error is the same.

    cursor is attached in #5 (32 bit version)
    ----------------------------------------------------

    Missing the days of GWBasic 1.1
    WaxyStudios.com

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2004
    Posts
    259

    Re: .cur from resource file / memory stream

    Found a solution that works.
    it doesn't explain what's wrong with the .CUR file or code, but it does give me a working solution:
    Use-Icons-for-cursors-not-CUR

    not the slick result i wanted, but it does work.
    ----------------------------------------------------

    Missing the days of GWBasic 1.1
    WaxyStudios.com

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