閱讀英文

共用方式為


CPaintDC Class

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at CPaintDC Class.

A device-context class derived from CDC.

Syntax

class CPaintDC : public CDC  

Members

Public Constructors

Name Description
CPaintDC::CPaintDC Constructs a CPaintDC connected to the specified CWnd.

Public Data Members

Name Description
CPaintDC::m_ps Contains the PAINTSTRUCT used to paint the client area.

Protected Data Members

Name Description
CPaintDC::m_hWnd The HWND to which this CPaintDC object is attached.

Remarks

It performs a CWnd::BeginPaint at construction time and CWnd::EndPaint at destruction time.

A CPaintDC object can only be used when responding to a WM_PAINT message, usually in your OnPaint message-handler member function.

For more information on using CPaintDC, see Device Contexts.

Inheritance Hierarchy

CObject

CDC

CPaintDC

Requirements

Header: afxwin.h

CPaintDC::CPaintDC

Constructs a CPaintDC object, prepares the application window for painting, and stores the PAINTSTRUCT structure in the m_ps member variable.

explicit CPaintDC(CWnd* pWnd);

Parameters

pWnd
Points to the CWnd object to which the CPaintDC object belongs.

Remarks

An exception (of type CResourceException) is thrown if the Windows GetDC call fails. A device context may not be available if Windows has already allocated all of its available device contexts. Your application competes for the five common display contexts available at any given time under Windows.

Example

      // Get a dc for a CWnd pointer.
      CPaintDC dc(pWnd);

      // Get a dc for a HWND.
      CPaintDC dc2(CWnd::FromHandle(hWnd));

CPaintDC::m_hWnd

The HWND to which this CPaintDC object is attached.

HWND m_hWnd;  

Remarks

m_hWnd is a protected variable of type HWND.

Example

      // Get a dc for a CWnd object pointer.
      CPaintDC dc(pWnd);

      // Send my private massage.
      ::SendMessage(pWnd->m_hWnd, WM_MYMESSAGE, (LPARAM) &dc.m_ps, 0);

CPaintDC::m_ps

m_ps is a public member variable of type PAINTSTRUCT.

PAINTSTRUCT m_ps;  

Remarks

It is the PAINTSTRUCT that is passed to and filled out by CWnd::BeginPaint.

The PAINTSTRUCT contains information that the application uses to paint the client area of the window associated with a CPaintDC object.

Note that you can access the device-context handle through the PAINTSTRUCT. However, you can access the handle more directly through the m_hDC member variable that CPaintDC inherits from CDC.

Example

See the example for CPaintDC::m_hWnd.

See Also

MFC Sample MDI
CDC Class
Hierarchy Chart