关闭

CPen,HFONT用完一定要释放,不然会造成GDI对象的增加,程序崩溃

3745人阅读 评论(2) 收藏 举报
分类:

1.HFONT的释放

    HFONT hFont,hOldFont;    
    LOGFONT lf;
    ::ZeroMemory(&lf, sizeof(LOGFONT));
    lf.lfHeight = m_pGrid->pCell[i][k].lfFont.lfHeight;// nHeight
    lf.lfWidth = 0;        // nWidth
    lf.lfEscapement = 0;      // nEscapement
    lf.lfOrientation = 0;      // nOrientation
    lf.lfWeight = m_pGrid->pCell[i][k].lfFont.lfWeight; // nWeight
    lf.lfItalic = m_pGrid->pCell[i][k].lfFont.lfItalic;// bItalic
    lf.lfUnderline = m_pGrid->pCell[i][k].lfFont.lfUnderline;// bUnderline
    lf.lfStrikeOut = FALSE;     // cStrikeOut
    lf.lfCharSet = DEFAULT_CHARSET;    // nCharSet
    lf.lfOutPrecision = OUT_DEFAULT_PRECIS;  // nOutPrecision
    lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;   // nClipPrecision
    lf.lfQuality = DEFAULT_QUALITY;    // nQuality
    lf.lfPitchAndFamily = DEFAULT_PITCH|FF_SWISS;// nPitchAndFamily
    lstrcpy(lf.lfFaceName,m_pGrid->pCell[i][k].lfFont.lfFaceName);  // lpszFacename 
   

    hFont = ::CreateFontIndirect(&lf);//创建字体
    hOldFont = (HFONT)::SelectObject(hDstDC,hFont);//DC选中字体

    ... ...

    pdc->SelectObject(hOldFont);
    ::DeleteObject(hFont);

 

2.CPen的释放

 CPen pen(PS_SOLID,1,m_GP_clrFrame);
 CPen *pOldPen;
 pOldPen = pdc->SelectObject(&pen);

 ... ...

 pdc->SelectObject(pOldPen);
 pen.DeleteObject();

 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:483565次
    • 积分:5682
    • 等级:
    • 排名:第4556名
    • 原创:96篇
    • 转载:125篇
    • 译文:0篇
    • 评论:77条
    最新评论