+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Valued Forum Contributor
    Join Date
    05-15-2009
    Location
    gold coast
    MS-Off Ver
    Excel 2007
    Posts
    797

    WINAPI_HandCursor Call

    Hello.
    I have the following in a module
    Code:
    Public Const WINAPI_HandCursor = 32649&
    Public Declare Function SetCursor Lib "user32" (ByVal hCursor As Long) As Long
    Public Declare Function GetCursor Lib "user32" () As Long
    Public Declare Function LoadCursor Lib "user32" Alias "LoadCursorA" (ByVal hInstance As Long, ByVal lpCursorName As Long) As Long
    
    ' Remember the handle for the Hand cursor
    Public HandCursor As Long
    
    Public Sub SetHandCursor()
        On Error Resume Next
    
        ' Load the cursor only once
        If HandCursor = 0 Then
            HandCursor = LoadCursor(0, WINAPI_HandCursor)
    
        ' Only update the cursor if it isn't our current cursor
        ElseIf GetCursor() = HandCursor Then
            Exit Sub
        End If
    
        ' Finally, set the cursor to the Hand
        SetCursor HandCursor
    End Sub
    And in the userform there is Image1 and i dont know how to In a MouseOver event call SetHandCursor()

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,493

    Re: WINAPI_HandCursor Call

    Hello D_Rennie,

    You don't need to use the API for this. The Image Control has 2 properties MouseIcon and MousePointer. Set the MouseIcon property to the cursor or icon file you want to use, and the MousePointer property to fmMousePointerCustom (99).
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Valued Forum Contributor
    Join Date
    05-15-2009
    Location
    gold coast
    MS-Off Ver
    Excel 2007
    Posts
    797

    Re: WINAPI_HandCursor Call

    Thankyou Leith Ross I stumbled with that though didnt see the connection with the mouse icon.
    I had success loading 8bit .ico files are these the only types to use. you wouldnt know of a good site to get them would you.
    if i set it like this, and then you ran the userform would you get a error cos it looks for the file ??
    A lot easer thankyou.

  4. #4
    Forum Moderator dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003 & 2007
    Posts
    3,661

    Smile Re: WINAPI_HandCursor Call

    Good morning D_Rennie

    Are you trying to simulate a hyperlink in a userform here?
    If so, John Walkenbach has an article about doing that here, with an example workbook for download here.

    HTH

    DominicB
    Now available : Ultimate Add-In 2007
    Integrates directly into the Office Excel Ribbon


    Download Ultimate Add-In v1.52 from www.dom-and-lis.co.uk
    90+ Utilities, 200+ Sub utilities last updated 25th April 2008
    Free!!

  5. #5
    Forum Moderator dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003 & 2007
    Posts
    3,661

    Smile Re: WINAPI_HandCursor Call

    Hi D_Rennie
    Quote Originally Posted by D_Rennie View Post
    if i set it like this, and then you ran the userform would you get a error cos it looks for the file ??
    Just to answer this specific question - no, the image is saved embedded in the file. Once you've saved the file you can remove the original image.

    HTH

    DominicB
    Now available : Ultimate Add-In 2007
    Integrates directly into the Office Excel Ribbon


    Download Ultimate Add-In v1.52 from www.dom-and-lis.co.uk
    90+ Utilities, 200+ Sub utilities last updated 25th April 2008
    Free!!

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,493

    Re: WINAPI_HandCursor Call

    Hello D_Rennie,

    You can load the icon or cursor file from a file or you can insert the icon or cursor using the Property Page in the Visual Basic Editor. This will save it as resource file in your VBA project. I have included the "hand" cursor file for you.

    While in the Visual Basic Editor
    1. Display the UserForm
    2. Click on the Image Control
    3. Press F4 to display the Properties Page
    4. Click to the cell to the right of MouseIcon to browse for the file
    5. Select the file and click Open
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  7. #7
    Valued Forum Contributor
    Join Date
    05-15-2009
    Location
    gold coast
    MS-Off Ver
    Excel 2007
    Posts
    797

    Re: WINAPI_HandCursor Call

    dominicb. Just playing with the icons. though thankyou ill keep that for the future.
    Leith Ross. cheers for putting up the file.

    Thankyou both very much.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0