Anyone know where I can download an icon image of this mouse pointer? I want to use it in a VB program, but they don't have this one built in. I'm gonna have to use it as a custom mouse pointer, but I don't know where to find it as an icon file.
Option Explicit
Private Declare Function LoadCursor Lib "user32" Alias "LoadCursorA" (ByVal hInstance As Long, ByVal lpCursorName As Long) As Long
Private Declare Function SetCursor Lib "user32" (ByVal hCursor As Long) As Long
Private Const IDC_HAND As Long = &H7F89 '32649
Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
' set mouse pointer to hand
SetCursor LoadCursor(0, IDC_HAND)
End Sub
Well, the hand icons come with VB I believe, it is installed in VB's common\graphics\cursors folder, but I've uploaded them for you if you want to try to use them.
Also, you may want to look at a small project I wrote concerning the Hand icon. It is located on PSC.
Insomnia is just a byproduct of, "It can't be done"
Option Explicit
Private Declare Function LoadCursor Lib "user32" Alias "LoadCursorA" (ByVal hInstance As Long, ByVal lpCursorName As Long) As Long
Private Declare Function SetCursor Lib "user32" (ByVal hCursor As Long) As Long
Private Const IDC_HAND As Long = &H7F89 '32649
Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
' set mouse pointer to hand
SetCursor LoadCursor(0, IDC_HAND)
End Sub
Thanks for this code, it worked perfectly. But what exactly is this doing? I don't understand where it's getting the hand from.
As for how/why the code works: LoadCursor gets a cursor handle from a requested instance such as the system (which is always 0). System has a bunch of predeclared integer values for many of the cursors you see on the system, all those IDC_something constants. You could also load cursors from an attached resource file of your own program, in that case you'd need to pass a String instead of an integer value. This would require a small change into the LoadCursor API call declaration, but since you don't need it now it doesn't matter.
SetCursor then takes the handle that was returned by LoadCursor. As the system cursors are always available, you do not need to free the handle. With resource icons, I think, you need to also free the handle by using DeleteObject API call when the cursor is no longer required.
I don't know whether this confused more than helped but that is somewhat the bare bones explanation.