View Full Version : Function: Change Mouse Cursor

07-20-2004, 03:10 PM
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

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). **
************************************************** ********************************
resetCursor = SetCursor(32514);
--do something here

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.

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;


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.

function ReturnCursor(resCursor)
-- Display original cursor
local retVal = DLL.CallFunction(_SystemFolder.."\\User32.dll", "SetCursor", resCursor, DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL);

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.

09-24-2004, 07:28 AM

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.


09-24-2004, 08:22 AM
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

09-24-2004, 08:43 AM

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?

09-24-2004, 01:29 PM
I have not tried to change the cursor during a page jump. Are you receiving an error of does it just not work?

09-27-2004, 04:59 AM
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.

07-26-2006, 05:57 PM
i want when mouse entered in mroject ( over mouse on project ) then cursor change