Displaying a Notification String

The PaintSuspended function draws a notification string in the client area whenever the application is suspended—for example, when it is in the background or is handling an error.

static void 
PaintSuspended(HWND hwnd, HDC hdc) 
{ 
    HPEN     hOldPen; 
    HBRUSH   hOldBrush; 
    COLORREF crOldTextColor; 
    int      oldMode; 
    int      x; 
    int      y; 
    SIZE     size; 
    RECT     rect; 
    int      nStrLen; 
 
    // Black background. 
 
    hOldPen   = SelectObject(hdc, GetStockObject(NULL_PEN)); 
    hOldBrush = SelectObject(hdc, GetStockObject(BLACK_BRUSH)); 
 
    // White text. 
 
    oldMode = SetBkMode(hdc, TRANSPARENT); 
    crOldTextColor = SetTextColor(hdc, RGB(255, 255, 255)); 
 
    GetClientRect(hwnd, &rect); 
 
    // Clear the client area. 
 
    Rectangle(hdc, rect.left, rect.top, rect.right + 1, rect.bottom + 1); 
 
    // Draw the string centered in the client area. 
 
    nStrLen = strlen(PAUSED_STRING); 
    GetTextExtentPoint32(hdc, PAUSED_STRING, nStrLen, &size); 
    x = (rect.right  - size.cx) / 2; 
    y = (rect.bottom - size.cy) / 2; 
    TextOut(hdc, x, y, PAUSED_STRING, nStrLen); 
 
    SetTextColor(hdc, crOldTextColor); 
    SetBkMode(hdc, oldMode); 
 
    SelectObject(hdc, hOldBrush); 
    SelectObject(hdc, hOldPen); 
}