a paradox in mfc head file?

problem code:

      pMetaFileDC->SelectObject(newPen);


when debug, it causes an assertion.  the source is:


      { ASSERT(m_hDC == m_hAttribDC); // ASSERT a simple CDC object
           return (hObject != NULL) ::SelectObject(m_hDC, hObject) : NULL; }

ok, then i write this:

      pDoc->pMetaFileDC->SetAttribDC(pDoc->pMetaFileDC->GetSafeHdc());

but this fuciton do not work as supposed. and the assertion remains.

look into the  source code:

      void CMetaFileDC::SetAttribDC(HDC hDC)  // Set the Attribute DC
     {
              if (hDC != m_hDC)
                CDC::SetAttribDC(hDC);
            if (m_hDC == m_hAttribDC)   // if we somehow got to this, correct it
               ReleaseAttribDC();
      }

i am really confused! what am i supposed to do

in addition, if i do nothing but use the  release vision, i find it works quite well without any problem.  

      
      



Answer this question

a paradox in mfc head file?

  • Tazwng

    Seams that you just declared he meta file dc but never createdon.
    Did you call CMetaFileDC::Create

  • Ed Hintz

    can anybody help me
  • Russell177576

    Copy&Paste from another topic.

    Hi,

    This is a bug in your code.

    pMetaFileDC->SelectObject(newPen);

    should be
    pMetaFileDC->SelectObject(&newPen);

    then you will call into

    _AFXWIN_INLINE CGdiObject* CDC::SelectObject(CGdiObject* pObject)

    not into

    _AFXWIN_INLINE HGDIOBJ CDC::SelectObject(HGDIOBJ hObject)


    Thanks,
    Nikola
    VC++



  • a paradox in mfc head file?