CWaitCursor::CWaitCursor
若要显示等待光标,请在执行较长操作的代码之前声明 CWaitCursor 对象。
CWaitCursor( );
备注
构造函数自动导致等待光标显示。
当对象超出范围(在 CWaitCursor 对象声明)的块的末尾,此析构函数中设置光标到以前的光标。 换言之,对象会自动执行必要的清理。
可以利用该条件析构函数调用结束时可能是函数结束之前)的块(用于在只有部分的等待光标激活您的功能。 此方法在下面的第二个示例演示。
备注
由于其构造函数和析构函数如何工作,CWaitCursor 对象始终声明为局部变量--它们不声明为全局变量,也不是它们分配了 new。
示例
// The following example illustrates the most common case
// of displaying the wait cursor during some lengthy
// processing.
void LengthyFunction()
{
// perhaps you display a dialog box before displaying a
// wait cursor
CWaitCursor wait; // display wait cursor
// do some lengthy processing
Sleep(1000);
} // destructor automatically removes the wait cursor
// This example shows using a CWaitCursor object inside a block
// so the wait cursor is displayed only while the program is
// performing a lengthy operation.
void ConditionalFunction()
{
if (SomeCondition)
{
CWaitCursor wait; // display wait cursor in this block only
// do some lengthy processing
Sleep(1000);
} // at this point, the destructor removes the wait cursor
else
{
// no wait cursor--only quick processing
}
}
要求
Header: afxwin.h