Results 1 to 3 of 3
  1. #1

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    In the PHP compiler

    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:
    1. Option Explicit
    3. Private Const IDC_HAND = 32649&
    4. Private Const IDC_ARROW = 32512&
    5. Private Declare Function LoadCursor Lib "user32" Alias "LoadCursorA" (ByVal _
    6.     hInstance As Long, ByVal lpCursorName As Long) As Long
    7. Private Declare Function SetCursor Lib "user32" (ByVal hCursor As Long) As Long
    9. Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, _
    10.     Y As Single)
    11.     SetCursor LoadCursor(0, IDC_HAND)
    12. 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 04:17 PM.
    My Flickr Stream Ľ

    My Sites Ľ Blog ē Twitter ē Flickr

  2. #2
    Addicted Member
    Join Date
    Jun 2009

    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:
    1. 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:
    1. If Not HandActive Then
    2.     HandActive = True
    3.     Call SetSystemCursor(LoadCursor(0, IDC_HAND), OCR_NORMAL)
    4. 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:
    1. Call SetSystemCursor(LoadCursor(0, IDC_HAND), OCR_NORMAL)
    2. 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).

  3. #3
    Addicted Member
    Join Date
    Jun 2009

    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


Click Here to Expand Forum to Full Width