代码之家  ›  专栏  ›  技术社区  ›  Cheok Yan Cheng

我需要在cFont上调用DeleteObject吗

mfc
  •  4
  • Cheok Yan Cheng  · 技术社区  · 15 年前

    我想知道,在以下情况下是否需要调用DeleteObject?

    CFont* oldFont = label.GetFont();
    LOGFONT oldLogFont;
    oldFont->GetLogFont(&oldLogFont);
    oldLogFont.lfWeight = FW_BOLD;
    CFont newFont;
    newFont.CreateFontIndirectW(&oldLogFont);
    label.SetFont(&newFont, true);
    // Do I need to call oldFont->DeleteObject() or newFont->DeleteObject()?
    

    谢谢。

    1 回复  |  直到 8 年前
        1
  •  3
  •   Gunther Struyf    8 年前

    不,你没有。MFC类是 RAII 类。当对象退出作用域(即解构)时,对象将被适当删除。

    推荐文章