Mar 7, 2009

An application-wide hourglass

When your users are waiting for your application to complete some task, it's nice to show them the hourglass mousepointer as an indication. You can easily set the mousepointer property of the active form, but when the user moves the mouse outside of it, the mousepointer changes to the arrowhead again and that's not how it should be.
The following code changes the mousepointer for all the forms in your application.
Put the code in a .PRG file and (very important!) name it MAUSER, because that was what Richard and I named it originally.
The reason for that is, that at the moment we were thinking about how to name this function, our friend Maurits walked in the room and 'Maus' is what we call him for short. Also 'maus' is the German word for mouse.

Activating and deactivating the hourglass is as simple as putting =MAUSER(.T.) and =MAUSER(.F.) around the piece of code that takes a while to execute.


PARAMETERS lZetAan

LOCAL nFormTeller

FOR nFormTeller = 1 TO _Screen.FormCount
_Screen.Forms(nFormTeller).SetAll("MousePointer",IIF(lZetAan,11,0))
_Screen.Forms(nFormTeller).MousePointer = IIF(lZetAan,11,0)
NEXT
_Screen.SetAll("MousePointer",IIF(lZetAan,11,0))

_Screen.MousePointer = IIF(lZetAan,11,0)
IF TYPE("_Screen.Activeform.Name") = "C"
_Screen.Activeform.SetAll("MousePointer",IIF(lZetAan,11,0))
ENDIF

No comments: