在看看MFC上说的: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.
explicit CPaintDC(
CWnd* pWnd
);
Parameters
pWnd
Points to the CWnd object to which the CPaintDC object belongs.
{
ASSERT_VALID(pWnd);
ASSERT(::IsWindow(pWnd->m_hWnd)); if (!Attach(::BeginPaint(m_hWnd = pWnd->m_hWnd, &m_ps)))
AfxThrowResourceException();
}传入的参数必须是有效的窗口指针,所以由类向导生成的都是CPaintDC dc(this), 而非空指针