在陳述式的情況下,使用標籤
之後出現的標籤案例關鍵字也不能出現在外的switch陳述式。(這項限制也適用於預設關鍵字。) 下列程式碼片段顯示正確的使用方式案例標籤:
// Sample Microsoft Windows message processing loop.
switch( msg )
{
case WM_TIMER: // Process timer event.
SetClassWord( hWnd, GCW_HICON, ahIcon[nIcon++] );
ShowWindow( hWnd, SW_SHOWNA );
nIcon %= 14;
Yield();
break;
case WM_PAINT:
// Obtain a handle to the device context.
// BeginPaint will send WM_ERASEBKGND if appropriate.
memset( &ps, 0x00, sizeof(PAINTSTRUCT) );
hDC = BeginPaint( hWnd, &ps );
// Inform Windows that painting is complete.
EndPaint( hWnd, &ps );
break;
case WM_CLOSE:
// Close this window and all child windows.
KillTimer( hWnd, TIMER1 );
DestroyWindow( hWnd );
if ( hWnd == hWndMain )
PostQuitMessage( 0 ); // Quit the application.
break;
default:
// This choice is taken for all messages not specifically
// covered by a case statement.
return DefWindowProc( hWnd, Message, wParam, lParam );
break;
}