|
-
May 8th, 2007, 10:56 AM
#1
Thread Starter
Hyperactive Member
[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?
-
May 8th, 2007, 11:11 AM
#2
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
May 8th, 2007, 11:15 AM
#3
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
-
May 8th, 2007, 11:26 AM
#4
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
May 8th, 2007, 11:46 AM
#5
Thread Starter
Hyperactive Member
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
-
May 8th, 2007, 12:12 PM
#6
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
May 8th, 2007, 01:07 PM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|