PDA

Click to See Complete Forum and Search --> : Changing Windows Cursor


Paul Warren
Apr 26th, 2001, 08:52 AM
Does anyone have an example of using LoadCursor and SetCursor to change the Windows cursor ? I've tried it but the LoadCursor call just returns a handle of 0 which causes the SetCursor to make the cursor disappear. I'm using NT if that makes a difference, and here's the code I use :


' Used to set the cursor to the crosshair on all app's
Private Declare Function LoadCursor Lib "user32" Alias "LoadCursorW" (ByVal hInstance As Long, ByVal lpCursorName As String) As Long
Private Declare Function SetCursor Lib "user32" (ByVal hCursor As Long) As Long

' Crosshair cursor
Private Const IDC_CROSS = 32515&

Private Sub Command1_Click()

Dim hCursor As Long
Dim RetVal As Long

' Change the cursor to a crosshair - returns 0 at the moment !
hCursor = LoadCursor(ByVal 0&, IDC_CROSS)
RetVal = SetCursor(hCursor)

End Sub


Thanks in advance.

Megatron
Apr 26th, 2001, 04:44 PM
You don't really need API For this.

Screen.MousePointer = 99
Screen.MousePointer = LoadPicture(MyCursor.cur)


To hide the Mouse, use the ShowCursor function.

Yonatan
Apr 26th, 2001, 04:55 PM
Actually the MouseIcon property should be used in the 2nd line.
Or if you just want the crosshair:

Screen.MousePointer = vbCrosshair

:rolleyes: < (ignore, I must)

Megatron
Apr 26th, 2001, 05:23 PM
Yes, it should.
(Sorry, I just copied and pasted the line)

Paul Warren
Apr 27th, 2001, 03:08 AM
Cheers guys, I was being particularly dim when I asked. I had API on the brain and didn't think VB might actually do it for me !

Yonatan
Apr 27th, 2001, 05:43 AM
Don't worry - VB usually can't do much by itself anyway :rolleyes: