CClientDC 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 CClientDC Class.

Takes care of calling the Windows functions GetDC at construction time and ReleaseDC at destruction time.

class CClientDC : public CDC  

Public Constructors

NameDescription
CClientDC::CClientDCConstructs a CClientDC object connected to the CWnd.

Protected Data Members

NameDescription
CClientDC::m_hWndThe HWND of the window for which this CClientDC is valid.

This means that the device context associated with a CClientDC object is the client area of a window.

For more information on CClientDC, see Device Contexts.

CObject

CDC

CClientDC

Header: afxwin.h

Constructs a CClientDC object that accesses the client area of the CWnd pointed to by pWnd.

explicit CClientDC(CWnd* pWnd);

Parameters

pWnd
The window whose client area the device context object will access.

Remarks

The constructor calls the Windows function GetDC.

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

void CDCView::DrawInClientDC(CDC* pDC)
{
   UNREFERENCED_PARAMETER(pDC);

   CClientDC clientDC(this);

   clientDC.TextOut(10, 10, CString(_T("I used a client DC!")));
}

The HWND of the CWnd pointer used to construct the CClientDC object.

HWND m_hWnd;  

Remarks

m_hWnd is a protected variable.

Example

See the example for CClientDC::CClientDC.

MFC Sample MDI
CDC Class
Hierarchy Chart
CDC Class

Show: