Udostępnij za pośrednictwem


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.

Return Value

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

Remarks

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.

Example

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

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

   EndPaint(&ps);

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

Requirements

Header: afxwin.h

See Also

Reference

CWnd Class

Hierarchy Chart

CWnd::EndPaint

CWnd::Invalidate

CWnd::InvalidateRgn

BeginPaint

CPaintDC Class

Concepts

CWnd Members