CFont font = CreateFont(......);
用后用释放资源吗??

解决方案 »

  1.   

    要的,GDI资源用完后都要释放
      

  2.   


    // The code fragment shows how to create a font object,
    // select the font object into a DC (device context) for text
    // drawing, and finally delete the font object.// Initializes a CFont object with the specified characteristics. 
    CFont font;
    VERIFY(font.CreateFont(
       12,                        // nHeight
       0,                         // nWidth
       0,                         // nEscapement
       0,                         // nOrientation
       FW_NORMAL,                 // nWeight
       FALSE,                     // bItalic
       FALSE,                     // bUnderline
       0,                         // cStrikeOut
       ANSI_CHARSET,              // nCharSet
       OUT_DEFAULT_PRECIS,        // nOutPrecision
       CLIP_DEFAULT_PRECIS,       // nClipPrecision
       DEFAULT_QUALITY,           // nQuality
       DEFAULT_PITCH | FF_SWISS,  // nPitchAndFamily
       _T("Arial")));                 // lpszFacename// Do something with the font just created...
    CClientDC dc(this);  
    CFont* def_font = dc.SelectObject(&font);
    dc.TextOut(5, 5, _T("Hello"), 5);
    dc.SelectObject(def_font);// Done with the font.  Delete the font object.
    font.DeleteObject(); 
      

  3.   

    貌似不用CFont的析构函数会做这些个事情的。
      

  4.   

    MFC封装的确是不用特别担心这些问题
    不过最好还是养成用完就释放的习惯
      

  5.   

    谢谢大家啊.还有一个问题
             CFont *Font1;
    CFont *Font2; 
    LOGFONT lf;  
    Font1 =new CFont;
    Font2 =new CFont;
    Font1->CreatePointFont(200,L"华文隶书");
    Font2->CreatePointFont(200,L"华文隶书");

    Font1->GetLogFont(&lf);
    Font2->GetLogFont(&lf);
    Font1->DeleteObject();
    Font2->DeleteObject();
    Font1->CreateFontIndirect(&lf);
    Font2->CreateFontIndirect(&lf);
            m_StaticName.SetFont(Font1,true);
    m_StaticWish.SetFont(Font2,true);
    Font1,改不了字体,可以改大小,Font2就什么都能改.为什么