-
Mar 4th, 2007, 02:16 PM
#1
Thread Starter
Frenzied Member
Classic VB - How can I show the 'link select' (hyperlink) mouse cursor?
Within the VB6 IDE you can very easily change the mouse pointer, and there are many different choices you have with this.
Some applications have links to internet based resources such as websites; however VB6 does not have the option to change the mouse pointer to the link select cursor (that’s the hyperlink hand).
Developers should not rely on the standard arrow pointer as this doesn’t highlight the fact that there is a link present.
To fix this many developers opt for the "Custom Mouse Pointer" option, adding an image that will look like the link select mouse pointer.
The mouse pointer may look sufficient on the machine it’s being developed on, but what about when it is distributed? Other users may have different themes, and a big example of this is Windows Vista. The link select mouse pointer is slightly improved; using shadows to make it more realistic, if that’s even possible, having the old style black and white hand icon will make your application look out of place, negating the end users theme.
The solution is even simpler than having a custom image, just use the code below.
VB Code:
Option Explicit
Private Const IDC_HAND = 32649&
Private Const IDC_ARROW = 32512&
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 Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, _
Y As Single)
SetCursor LoadCursor(0, IDC_HAND)
End Sub
The code above was shown in RhinoBulls post back in 2006, and shows an easier method of invoking the Link Select cursor.
I Love My Vans
Last edited by I_Love_My_Vans; Mar 4th, 2007 at 05:17 PM.
-
Jun 30th, 2009, 06:26 AM
#2
Addicted Member
Re: Classic VB - How can I show the 'link select' (hyperlink) mouse cursor?
This code is easy. However, it causes flickering on Vista and 7, while on XP it is hard to notice.
I have found another way, which does not involve (almost) any MouseMove event.
vb Code:
Private Declare Function SetSystemCursor Lib "user32" (ByVal hcur As Long, ByVal id As Long) As Long
Put this code in MouseMove event and it will execute only once:
vb Code:
If Not HandActive Then
HandActive = True
Call SetSystemCursor(LoadCursor(0, IDC_HAND), OCR_NORMAL)
End If
This code changes (as the function name indicates) the primary cursor permanently.
In order to restore it, we have to call the same function again, using the same parameters.
vb Code:
Call SetSystemCursor(LoadCursor(0, IDC_HAND), OCR_NORMAL)
HandActive = False
There are 2 ways to "undo" the hand cursor:
1. Subclass the control and capture WM_MOUSELEAVE (most reliable).
2. Put the "undo" code in the form's MouseMove event (checking if HandActive is true).
-
Jun 30th, 2009, 06:31 AM
#3
Addicted Member
Re: Classic VB - How can I show the 'link select' (hyperlink) mouse cursor?
I forgot!
In the case of a label, since there is no hWnd and we cannot subclass it, we must call GetCursorPos along with ScreenToClient functions and check if the cursor is inside/outside the label.
Again, this is the most reliable method, instead of using form's MouseMove event.
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
|