如题

解决方案 »

  1.   

    你在绘制整个桌面的图形?如果绘制某个窗口的,NULL应该是那个窗口的指针!如果你确实想绘制整个桌面,那么你应该在调试器里启动程序,看crash时停在哪
      

  2.   

    你Debug下F11进入CPaintDC的构造函数里看看不就很清楚了
      

  3.   

    在看看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. 
      

  4.   

    如果继续调试的话就会发现问题了 看CPaintDC的构造函数CPaintDC::CPaintDC(CWnd* pWnd)
    {
    ASSERT_VALID(pWnd);
    ASSERT(::IsWindow(pWnd->m_hWnd)); if (!Attach(::BeginPaint(m_hWnd = pWnd->m_hWnd, &m_ps)))
    AfxThrowResourceException();
    }传入的参数必须是有效的窗口指针,所以由类向导生成的都是CPaintDC dc(this), 而非空指针