1.18.2 Wait CursorsWait Cursor
The waitCursor class changes the mouse pointer to the hour glass, or busy indicator. It is a visual cue to indicate that Origin is running a piece of code that may require an amount of time sufficiently large that it will be prevented from responding to other requests. The mouse pointer changes to the busy indicator when an instance of a waitCursor object is created, and changes back to the arrow when the instance is destroyed.
The following example is a function that pretends to do something time consuming. At the beginning, we declare and create a waitCursor instance. During the creation, the mouse pointer will be changed to the busy indicator. When the function exits, the waitCursor instance is automatically destroyed, causing the mouse pointer to be changed back to the arrow.
void myTimeConsumingFunction()
{
waitCursor wc; // declare and show the wait cursor
for( int i = 0; i < 10000; i++ )
{
if( 0 == (i % 100) )
printf("i == %d\n", i);
}
}
The next example is similar to the above example, but adds the ability to exit the function before it finishes its time consuming task. The exiting early ability is accomplished by calling the wait cursor's CheckEsc method. This method returns true if the user has pressed the Esc key, otherwise it returns false.
void myEscapableTimeConsumingFunction()
{
waitCursor wc; // declare and show the wait cursor
for( int i = 0; i < 10000; i++ )
{
if( 0 == (i % 100) )
printf("i == %d\n", i);
if( wc.CheckEsc() )
break; // end loop early
}
}
|