Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
MFC
Expand Minimize
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

CWnd::BeginPaint 

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


CDC* BeginPaint(
   LPPAINTSTRUCT lpPaint 
);

Parameters

lpPaint

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 CMyView::OnPaint() 
{
   PAINTSTRUCT ps;
   CDC* pDC = BeginPaint(&ps);

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

   EndPaint(&ps);

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

Community Additions

ADD
Show:
© 2015 Microsoft