Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2003
    Posts
    81

    Unanswered: Image with a hand cursor?

    OK, tricky one...

    I have an image which is actually going to act as a button. Now because I want it to be obvious that it's clickable, I wanted to make the cursor change to the hand icon (ala hyperlink) when the cursor rolls over the image.

    Now, I can make this happen by simply adding something in the hyperlink properties of the image, but I don't want it to open a hyperlink, I want it to execute an event procedure which does something.

    So when I have the event procedure and the hyperlink active, it does both. How do I make it not open a hyperlink, but still keep the hand effect when you move over it??????????

    Cheers,

  2. #2
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Don't have a clue where I got this, but it works for me. It saves the orignal pointer and returns it after you roll off of the control. Go to Modules, select New and start a new module (name it mod_Mouse_Pointers) by copy/pasting or typing in the following:


    Option Compare Database
    Option Explicit


    Declare Function SetClassLong Lib "user32" Alias "SetClassLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

    '================================================= ======================
    ' Globals for cursor handling
    Global Const GCL_HCURSOR = (-12)
    Global hSwapCursor As Long
    Global hAniCursor As Long

    '================================================= ======================

    Public Const IDC_ARROW = 32512&

    Public Const IDC_IBEAM = 32513&
    Public Const IDC_WAIT = 32514&
    Public Const IDC_CROSS = 32515&
    Public Const IDC_UPARROW = 32516&

    ' Public Const IDC_SIZE = 32640& ' Doesn't appear to work correctly
    Public Const IDC_ICON = 32641&
    Public Const IDC_SIZENWSE = 32642&
    Public Const IDC_SIZENESW = 32643&
    Public Const IDC_SIZEWE = 32644&
    Public Const IDC_SIZENS = 32645&
    Public Const IDC_SIZEALL = 32646&
    Public Const IDC_NO = 32648&
    Public Const IDC_HAND = 32649&
    Public Const IDC_APPSTARTING = 32650&

    Declare Function LoadCursorBynum Lib "user32" Alias "LoadCursorA" _
    (ByVal hInstance As Long, ByVal lpCursorName As Long) As Long

    Declare Function LoadCursorFromFile Lib "user32" Alias _
    "LoadCursorFromFileA" (ByVal lpFileName As String) As Long

    Declare Function SetCursor Lib "user32" _
    (ByVal hCursor As Long) As Long
    '
    Public Function Arrow_Pointer()
    Screen.MousePointer = 1
    End Function

    Function ChangeCursor(strPathToCursor As String)

    On Error GoTo Error_On_ChangeCursor

    ' Example :
    ' ChangeCursor ("C:\Program Files\Microsoft Office\Office\Hand.cur")

    If Dir(strPathToCursor) <> "" Then
    Dim lngRet As Long
    lngRet = LoadCursorFromFile(strPathToCursor)
    lngRet = SetCursor(lngRet)
    End If

    Exit_ChangeCursor:

    Exit Function

    Error_On_ChangeCursor:

    Resume Exit_ChangeCursor

    End Function

    Public Function Default_Pointer()
    Screen.MousePointer = 0
    End Function

    Public Function IBeam_Pointer()
    Screen.MousePointer = 3
    End Function

    Function MouseCursor(CursorType As Long)

    ' Example: =MouseCursor(32512) ' using Public Constants from above

    Dim lngRet As Long
    lngRet = LoadCursorBynum(0&, CursorType)
    lngRet = SetCursor(lngRet)
    End Function

    Public Function Replace_Cursor(PathToFile As String)

    ' Return handle from animated cursor

    ' Original - hAniCursor = LoadCursorFromFile("C:\WINDOWS\CURSORS\GLOBE.ANI")

    hAniCursor = LoadCursorFromFile(PathToFile)
    ' Swap current mouse pointer with new animated cursor :
    hSwapCursor = SetClassLong(Screen.ActiveForm.hwnd, GCL_HCURSOR, hAniCursor)


    End Function

    Public Function Restore_Cursor()

    ' Remove animated cursorand replace with saved index :

    hSwapCursor = SetClassLong(Screen.ActiveForm.hwnd, GCL_HCURSOR, hSwapCursor)

    End Function


    ################################################## ####################
    Now in the Properties for the control select OnMouseMove and enter:

    =MouseCursor(32649)

    Hope this helps!
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    Join Date
    Oct 2003
    Posts
    81
    Thanks! That works great!

  4. #4
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Yeah, I use it on all my apps! Just wish I knew who to credit and thank! I always include author info when I have it. This came to me about third hand. Glad it helped.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    Join Date
    Nov 2003
    Posts
    1,487
    I know this post is allready resolved, but ya know, I sort of could'nt resist this one........

    This is not as difficult as you think. You can even add sound effects when the button is clicked. To do this though, you will need to dabble into the code end of things. It's a little more work but for small apps, sometimes the effects are worth it (download the attached sample below).

    To do this effectively we need to make some API calls. To use the bare bones code to display the hand mouse pointer, copy and past the following code into a DB code module.

    Code:
    'API's use to handle cursor changes.
    Declare Function LoadCursorBynum Lib "user32" Alias "LoadCursorA" _
    (ByVal hInstance As Long, ByVal lpCursorName As Long) As Long
     
    Declare Function SetCursor Lib "user32" _
    (ByVal hCursor As Long) As Long
     
    Public Function ShowHand()
       'Set the mouse pointer.
       Dim lngRet As Long
       lngRet = LoadCursorBynum(0&, 32649&)
       lngRet = SetCursor(lngRet)
    End Function
    That's it. To use this code simply enter the line below directly into the On Mouse Move event of every control you would like to display a hand cursor when the mouse pointer is passed over it. When the mouse pointer falls off the Control then is automatically changes back to the arrow pointer. Simply enter the line =ShowHand() into the property box for the OnMouseMove event located under the Events tab of the properties window. For example:

    On Dbl Click ....................
    On Mouse Down.............
    On Mouse Move ............. =ShowHand()
    On Mouse Up .................

    Thats it, simple as that.

    If you want a lot more flexability with creating buttons, different buttons with home made effects, adding sounds etc., then download the attched small sample below. This is the second time I have posted this sample here. The sample contains no additional controls outside of the MS Access ToolBox. All the buttons are, so to speak, home made

    .
    Attached Files Attached Files
    Last edited by CyberLynx; 09-23-05 at 09:07.
    Environment:
    Self Taught In ALL Environments.....And It Shows!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •