CFont font;
font.createfont(......);
如果再font.createfont(......);一次,会有错误,
如何删除第一次创建的结果?

解决方案 »

  1.   

    see the link below, useful :http://www.codeproject.com/gdi/#Fonts
      

  2.   

    ResInitializes a CFont object with the specified characteristics. The font can subsequently be selected as the font for any device context. The CreateFont function does not create a new Windows GDI font. It merely selects the closest match from the fonts available in the GDI’s pool of physical fonts. Applications can use the default settings for most of these parameters when creating a logical font. The parameters that should always be given specific values are nHeight and lpszFacename. If nHeight and lpszFacename are not set by the application, the logical font that is created is device-dependent.When you finish with the CFont object created by the CreateFont function, first select the font out of the device context, then delete the CFont object.Do u understand ? :)
      

  3.   

    how to delete ?which function?please!
      

  4.   

    give u a simple example :....
    CFont myFont1,myFont2....;
    CFont *pOldFont;myFont1.CreateFont(......);
    pOldFont=pDC->SelectObject(&myFont1);
    pDC->TextOut(0,0,"this is font1!");myFont2.CreateFont(...);
    pDC->SelectObject(&myFont2);
    //use font2 below//finally u'd restore the old font ...pDC->SelectObject(pOldFont);
    ......
      

  5.   

    deleteobject,i see ,thx,give fen
      

  6.   

    CFont* pfont = new CFont;
    pfont->createfont(......);
    ....
    delete pfont;
    pfont = new CFont;
    pfont->createfont(......);
    ....或者
    CFont font;
    font.createfont(......);
    font.Detach();
    font.createfont(......);
    ...
      

  7.   

    CFont *pcFont = new CFont;
    pcFont->CreateFont(...);
    delete pcFont;
    pcFont = new CFont;
    pcFont->CreateFont(...);
      

  8.   

    OnDraw(CDC* pDC)
    {
    CPen pen1,pen2;
    pen1.CreatePen(PS_SOLID,2,RGB(128,128,128));//创建对象
    pen2.CreatePen(PS_SOLID,2,RGB(128,128,0));//创建对象
    CPen* pPenOld=(CPen*)pDC->SelectObject(&pen1);//选择对象进DC
    drawWithPen1...
    (CPen*)pDC->SelectObject(&pen2);//选择对象进DC
    drawWithPen2...
    pen1.DeleteObject();//再次创建前先销毁
    pen1.CreatePen(PS_SOLID,2,RGB(0,0,0));//再次创建对象
    (CPen*)pDC->SelectObject(&pen1);//选择对象进DC
    drawWithPen1...
    pDC->SelectObject(pOldPen);//恢复
    }