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.
class CPaintDC : public CDC
Name | Description |
---|---|
CPaintDC::CPaintDC | Constructs a CPaintDC connected to the specified CWnd. |
Name | Description |
---|---|
CPaintDC::m_ps | Contains the PAINTSTRUCT used to paint the client area. |
Name | Description |
---|---|
CPaintDC::m_hWnd | The HWND to which this CPaintDC object is attached. |
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.
CPaintDC
Header: afxwin.h
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);
pWnd
Points to the CWnd
object to which the CPaintDC
object belongs.
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.
// Get a dc for a CWnd pointer.
CPaintDC dc(pWnd);
// Get a dc for a HWND.
CPaintDC dc2(CWnd::FromHandle(hWnd));
The HWND
to which this CPaintDC
object is attached.
HWND m_hWnd;
m_hWnd
is a protected variable of type HWND
.
// 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);
m_ps
is a public member variable of type PAINTSTRUCT.
PAINTSTRUCT m_ps;
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
.
See the example for CPaintDC::m_hWnd.