共用方式為


CCmdTarget::BeginWaitCursor

當您預期會有一個命令會使用可觀的時間間隔加入至執行時,請呼叫這個函式會顯示游標為沙漏。

void BeginWaitCursor( );

備註

架構會呼叫這個函式會顯示使用者應用程式忙碌中,例如,當 CDocument 物件載入或將本身儲存至檔案時。

因為其他動作,例如管理 OnSetCursor ,可以變更游標, BeginWaitCursor 的動作不一定是單一訊息處理常式的有效的外部。

呼叫還原先前的游標的 EndWaitCursor

範例

// The following example illustrates the most common case
// of displaying the hourglass cursor during some lengthy
// processing of a command handler implemented in some
// CCmdTarget-derived class, such as a document or view.
void CMyView::OnBeginSleepEnd()
{
   BeginWaitCursor(); // display the hourglass cursor
   // do some lengthy processing
   Sleep(3000);
   EndWaitCursor(); // remove the hourglass cursor
}

// The next example illustrates RestoreWaitCursor.
void CMyView::OnBeginDlgRestore()
{
   BeginWaitCursor(); // display the hourglass cursor
   // do some lengthy processing
   // The dialog box will normally change the cursor to
   // the standard arrow cursor, and leave the cursor in
   // as the standard arrow cursor when the dialog box is
   // closed.
   CFileDialog dlg(TRUE);
   dlg.DoModal();

   // It is necessary to call RestoreWaitCursor here in order
   // to change the cursor back to the hourglass cursor.
   RestoreWaitCursor();
   // do some more lengthy processing
   Sleep(3000);
   EndWaitCursor(); // remove the hourglass cursor
}

// In the above example, the dialog was clearly invoked between
// the pair of calls to BeginWaitCursor and EndWaitCursor.
// Sometimes it may not be clear whether the dialog is invoked 
// in between a pair of calls to BeginWaitCursor and EndWaitCursor.
// It is permissable to call RestoreWaitCursor, even if 
// BeginWaitCursor was not previously called.  This case is 
// illustrated below, where CMyView::AnotherFunction does not
// need to know whether it was called in the context of an
// hourglass cursor.
void CMyView::OnDlgRestore()
{
   // some processing ...
   CFileDialog dlg(TRUE);
   dlg.DoModal();
   RestoreWaitCursor();

   // some more processing ...
}

// If the dialog is invoked from a member function of
// some non-CCmdTarget, then you can call CWinApp::DoWaitCursor
// with a 0 parameter value to restore the hourglass cursor.
void CMyObject::OnDlgDoWait()
{
   CFileDialog dlg(TRUE);
   dlg.DoModal();
   AfxGetApp()->DoWaitCursor(0); // same as CCmdTarget::RestoreWaitCursor   
}

需求

Header: afxwin.h

請參閱

參考

CCmdTarget 類別

階層架構圖

CWaitCursor 類別

CCmdTarget::EndWaitCursor

CCmdTarget::RestoreWaitCursor

CWinApp::DoWaitCursor