-
[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?
-
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.
-
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.
-
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.
-
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
-
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.
-
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.