This documentation is archived and is not being maintained.


Prepares CWnd for painting and fills a PAINTSTRUCT data structure with information about the painting.

CDC* BeginPaint( 


Points to the PAINTSTRUCT structure that is to receive painting information.

Identifies the device context for CWnd. The pointer may be temporary and should not be stored beyond the scope of EndPaint.

The paint structure contains a RECT data structure that has the smallest rectangle that completely encloses the update region and a flag that specifies whether the background has been erased.

The update region is set by the Invalidate, InvalidateRect, or InvalidateRgn member functions and by the system after it sizes, moves, creates, scrolls, or performs any other operation that affects the client area. If the update region is marked for erasing, BeginPaint sends an WM_ONERASEBKGND message.

Do not call the BeginPaint member function except in response to a WM_PAINT message. Each call to the BeginPaint member function must have a matching call to the EndPaint member function. If the caret is in the area to be painted, the BeginPaint member function automatically hides the caret to prevent it from being erased.

// Use BeginPaint and EndPaint when responding to WM_PAINT message 
// An alternative method is to use CPaintDC in place of  
// BeginPaint and EndPaint 
void CMdiView::OnPaint() 
   CDC* pDC = BeginPaint(&ps);

   pDC->Rectangle(CRect(0, 0, 100, 100));


   // Do not call CView::OnPaint() for painting messages

Header: afxwin.h