Function: Change Mouse Cursor

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • TJ_Tigger
    Indigo Rose Customer
    • Sep 2002
    • 3159

    Function: Change Mouse Cursor

    Attached is a project that includes two functions that allow you to change the mouse cursor within your project. These functions call on functions within the user32.dll on the windows system.

    Here is an example of how to use the functions

    Code:
    --[[
    Use this function with one of the following codes
    to set the mouse to busy or other type of cursor 
    
    **********************************************************************************
    ** IDC_APPSTARTING 	= 32650                                                     **
    ** The application starting cursor (arrow and hourglass).  						**
    ** IDC_ARROW 		= 32512                                                     **
    ** The regular arrow pointer cursor.  											**
    ** IDC_CROSS 		= 32515                                                     **
    ** The cross cursor.  														 	**
    ** IDC_IBEAM 		= 32513                                                     **
    ** The I-shaped beam cursor (text editing cursor).  							**
    ** IDC_ICON 		= 32641                                                     **
    ** Win NT only: An empty cursor.  												**
    ** IDC_NO 			= 32648                                                     **
    ** The "no" symbol cursor (circle with a slash).  								**
    ** IDC_SIZE 		= 32640                                                     **
    ** Win NT only: The four-pointed resize/move arrow.  							**
    ** IDC_SIZEALL 		= 32646                                                     **
    ** The four-pointed resize/move arrow. 											**
    ** IDC_SIZENESW 	= 32643                                                     **
    ** The double-pointed resize arrow pointing to the upper-right and lower-left. 	**
    ** IDC_SIZENS 		= 32645                                                     **
    ** The double-pointed resize arrow pointing up and down. 						**
    ** IDC_SIZENWSE 	= 32642                                                     **
    ** The double-pointed resize arrow pointing to the upper-left and lower-right.  **
    ** IDC_SIZEWE 		= 32644                                                     **
    ** The double-pointed resize arrow pointing left and right.  					**
    ** IDC_UPARROW 		= 32516                                                     **
    ** The up-arrow cursor. 														**
    ** IDC_WAIT 		= 32514                                                     **
    ** The wait cursor (hourglass).                                                 **
    **********************************************************************************
    ]]--
    --Example:
    resetCursor = SetCursor(32514);
    --do something here
    ReturnCursor(resetCursor)
    Here are the two functions. The first function requires that you use one of the above codes to change the cursor, such as to the hourglass (32514). It will also return the default arrow key that was used before you changed the cursor. This value will be used in the second function.

    Code:
    function SetCursor(cursor)
    	-- Get current cursor 
    	local holdCursor = DLL.CallFunction(_SystemFolder.."\\User32.dll", "GetCursor", "", DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL); 
    	
    	-- Load hourglasscursor 
    	local hCursor = DLL.CallFunction(_SystemFolder.."\\User32.dll", "LoadCursorA", "0, "..cursor, DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL);
    	
    	-- Display loaded cursor 
    	local retVal = DLL.CallFunction(_SystemFolder.."\\User32.dll", "SetCursor", hCursor, DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL);
    
    	--return the holdCursor 
    	return holdCursor;
    	
    end
    The second function is used to change the cursor back to it's original state. In the example above it uses the returned value from the first function.

    Code:
    function ReturnCursor(resCursor)
    	-- Display original cursor 
    	local retVal = DLL.CallFunction(_SystemFolder.."\\User32.dll", "SetCursor", resCursor, DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL);
    end
    There are limitations to this function. If you move the mouse outside the AMS window it reverts to the normal arrow. If you mouse over anothe object within the AMS window it reverts to the normal arrow again. I hope you find this useful for your projects.

    Here is a sample project.
    Attached Files
    TJ-Tigger
    "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
    "Draco dormiens nunquam titillandus."
    Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine
  • manwai
    Forum Member
    • Jul 2004
    • 5

    #2
    Set cursor

    Hi

    Ive bin trying to use the setCursor coding that you suggested but the screen keeps displaying that the setCursor contains a nil value. Have you any idea how i can fix this because I really need to show the hourglass icon when the button is pressed and is waiting for the next page to be displayed.

    Thanks

    Comment

    • TJ_Tigger
      Indigo Rose Customer
      • Sep 2002
      • 3159

      #3
      Can you show me the code that gives this error?

      Make sure that when you use the function you specify a number to set the cursor to.

      resetCursor = SetCursor(32514);--this changes the cursor to wait
      --do something here
      ReturnCursor(resetCursor):
      TJ-Tigger
      "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
      "Draco dormiens nunquam titillandus."
      Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

      Comment

      • manwai
        Forum Member
        • Jul 2004
        • 5

        #4
        Set Cursor

        OK,

        Sorted out the error message that I was getting, but the method still does not work.

        What I'm trying to do is show the hourglass on a button click. The button click also does a page.jump.

        Then I'm trying to revert the cursor back to the arrow. I'm trying the revert the cursor on the Show event of the page.

        Any ideas?

        Comment

        • TJ_Tigger
          Indigo Rose Customer
          • Sep 2002
          • 3159

          #5
          I have not tried to change the cursor during a page jump. Are you receiving an error of does it just not work?
          TJ-Tigger
          "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
          "Draco dormiens nunquam titillandus."
          Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

          Comment

          • sofia
            Forum Member
            • Sep 2004
            • 1

            #6
            set cursor

            Hi im having the same problem with the page jump. No error message appears it just does not work. Any possible suggestions on how to fix this.

            Comment

            • gbdor
              Forum Member
              • May 2006
              • 75

              #7
              hi

              freinds
              i want when mouse entered in mroject ( over mouse on project ) then cursor change
              how?

              Comment

              Working...
              X