Results 1 to 7 of 7

Thread: [2005] SetCursor

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Posts
    384

    [2005] SetCursor

    How does the SetCursor function work in VB 2005??

    I did this :
    Code:
        <DllImport("user32", EntryPoint:="SetCursor", SetLastError:=True, CharSet:=CharSet.Auto)> _
            Private Shared Function SetCursor(ByVal hCursor As IntPtr) As IntPtr
        End Function
    
        Private CursorArray() As Cursor
    'rest of inserting cursors into array omitted
    Then I tried
    Code:
      SetCursor(CursorArray(CurseInt).Handle)
    It does not change my mouse cursor!
    Any ideas?

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [2005] SetCursor

    Should be defined as an integer.

    Code:
    <DllImport("user32", EntryPoint:="SetCursor", CharSet:=CharSet.Auto)> _
    Private Shared Function SetCursor (ByVal hCursor As Integer) As Integer
    End Function
    But you need to load a cursor first to obtain the handle to it for passing to the setcursor function.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    Re: [2005] SetCursor

    Why use the api?
    Code:
    Me.Cursor = New Cursor("Path\to\my\cursor.cur")
    should be enough

    edit : Or just pick one of the standard ones from the Cursors class.
    Last edited by crptcblade; May 8th, 2007 at 11:19 AM.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [2005] SetCursor

    Assuming he wants a default cursor (which I doubt)...
    but he does appear to have an array of cursor files loaded, may be the wrong type though. Doesnt say anything about any errors.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Posts
    384

    Re: [2005] SetCursor

    Hello again!
    I have an array of cursors of type Cursor. I load these cursors into a combobox. I have 2 buttons:
    one button is used to change the cursor of the form only
    the second button is used to change the system's cursor
    I used LoadCursor now like :
    Code:
        <DllImport("user32", EntryPoint:="LoadCursor", CharSet:=CharSet.Auto)> _
            Private Shared Function LoadCursor(ByVal hInstance As Integer, ByVal lpCursorName As String) As Integer
        End Function
    I declare my array of cursors :
    Code:
        Private CurseInt As Integer
        Private CursorArray() As Cursor
    I load the cursors:
    Code:
            ReDim CursorArray(cboCursors.Items.Count)
            CursorArray(0) = Cursors.AppStarting
            CursorArray(1) = Cursors.Arrow
            CursorArray(2) = Cursors.Cross
            CursorArray(3) = Cursors.Default
            CursorArray(4) = Cursors.Hand
            CursorArray(5) = Cursors.Help
            CursorArray(6) = Cursors.HSplit
    'etc.
    Now, I set the selected index of the combobox:
    Code:
        Private Sub cboCursors_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboCursors.SelectedIndexChanged
            If cboCursors.SelectedIndex > -1 Then
                CurseInt = (cboCursors.SelectedIndex)
    
            End If
        End Sub
    Now, I want to change the system cursor:
    Code:
        Private Sub bChangeCE_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bChangeCE.Click
            Dim lHandle As Integer
    
            lHandle = LoadCursor(0, CursorArray(CurseInt).Handle)
    
            SetCursor(lHandle)
    
        End Sub
    When I stepped through my code though, I saw that lHandle remains 0.

    I just want to set the system cursor from my program (temporarily) to a already existing system cursor

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [2005] SetCursor

    Instead of loading them into an array you could relate them to the name of the cursor in the cbo with a select case or something. Then no api or arrays etc.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    Re: [2005] SetCursor

    You are using LoadCursor incorrectly.

    http://msdn2.microsoft.com/en-us/library/ms648391.aspx

    In order to load a system cursor, the hInstance parameter is 0, and the lpCursorName parameter must be one of the values listed on that page.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

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