다음을 통해 공유


CWaitCursor 클래스

사용자가 장기 작업을 수행하는 동안 대기 커서를 표시하는 한 가지 방법(일반적으로 모래시계로 표시됨)을 제공합니다.

구문

class CWaitCursor

멤버

공용 생성자

속성 설명
CWaitCursor::CWaitCursor 개체를 CWaitCursor 생성하고 대기 커서를 표시합니다.

공용 메서드

이름 설명
CWaitCursor::Restore 변경된 후 대기 커서를 복원합니다.

설명

CWaitCursor 에는 기본 클래스가 없습니다.

좋은 Windows 프로그래밍 방법을 사용하려면 상당한 시간이 걸리는 작업을 수행할 때마다 대기 커서를 표시해야 합니다.

대기 커서를 표시하려면 긴 작업을 수행하는 코드 앞에 변수를 정의 CWaitCursor 하기만 하면 됩니다. 개체의 생성자가 자동으로 대기 커서를 표시합니다.

개체가 범위를 벗어나면(개체가 선언된 CWaitCursor 블록의 끝에 있음) 소멸자는 커서를 이전 커서로 설정합니다. 즉, 개체는 필요한 클린 자동으로 수행합니다.

참고 항목

생성자와 소멸자가 작동하는 CWaitCursor 방식 때문에 개체는 항상 지역 변수로 선언되며 전역 변수로 선언되지도 않고 할당되지 new도 않습니다.

메시지 상자 또는 대화 상자 표시와 같이 커서가 변경될 수 있는 작업을 수행하는 경우 멤버 복원 함수를 호출하여 대기 커서를 복원합니다. 대기 커서가 현재 표시되는 경우에도 호출 Restore 해도 됩니다.

대기 커서를 표시하는 또 다른 방법은 CCmdTarget::BeginWaitCursor, CCmdTarget::EndWaitCursor 및 CCmdTarget::RestoreWaitCursor의 조합을 사용하는 것입니다. 그러나 CWaitCursor 긴 작업을 완료할 때 커서를 이전 커서로 설정할 필요가 없으므로 사용하기가 더 쉽습니다.

참고 항목

MFC는 CWinApp::D oWaitCursor 가상 함수를 사용하여 커서를 설정하고 복원합니다. 사용자 지정 동작을 제공하도록 이 함수를 재정의할 수 있습니다.

상속 계층 구조

CWaitCursor

요구 사항

헤더: afxwin.h

예시

BOOL SomeLengthyProcess()
{
   CWaitCursor wait;
   //Do the lengthy processing.
   Sleep(1000);

   AfxMessageBox(_T("Some result")); //This changes the cursor.
   wait.Restore();                   //Restore the Wait cursor.
   //Continue Processing.
   Sleep(1000);

   //The destructor changes the cursor back to Regular cursor.
   return TRUE;
}

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
   }
}

CWaitCursor::Restore

대기 커서를 복원하려면 대기 커서를 다른 커서로 변경할 수 있는 메시지 상자 또는 대화 상자 표시와 같은 작업을 수행한 후 이 함수를 호출합니다.

void Restore();

설명

대기 커서가 현재 표시되는 경우에도 호출 Restore 해도 괜찮습니다.

개체가 선언된 함수가 아닌 다른 함수에서 CWaitCursor 대기 커서를 복원해야 하는 경우 CCmdTarget::RestoreWaitCursor를 호출할 수 있습니다.

예시

// This example illustrates performing an operation
// which changes the wait cursor. You should call
// CWaitCursor::Restore to restore the wait
// cursor after an operation which changes the cursor.
void AnotherLengthyFunction()
{
   CWaitCursor wait; // display wait cursor

   // do some lengthy processing
   Sleep(1000);

   // The dialog box will normally change the cursor to
   // the standard arrow cursor.
   CFileDialog dlg(TRUE);
   dlg.DoModal();

   // It is necessary to call Restore here in order
   // to change the cursor back to the wait cursor.
   wait.Restore();

   // do some more lengthy processing
   Sleep(1000);

   // destructor automatically removes the wait cursor
}

// If the wait cursor is changed by a function called by
// the function which created the wait cursor, you
// can call CCmdTarget::RestoreWaitCursor to restore
// the wait cursor.
void CalledFunction()
{
   CFileDialog dlg(TRUE);
   dlg.DoModal();

   // Since CWinApp is derived from CCmdTarget, we can use a
   // pointer to our application object to make the call to
   // CCmdTarget::RestoreWaitCursor.
   AfxGetApp()->RestoreWaitCursor();

   // Yet more lengthy processing...
   Sleep(1000);
}

참고 항목

계층 구조 차트
CCmdTarget::BeginWaitCursor
CCmdTarget::EndWaitCursor
CCmdTarget::RestoreWaitCursor
CWinApp::D oWaitCursor
Visual C++를 사용하여 MFC에서 창에 대한 마우스 포인터 변경