我才学,别见笑,显示文字要用到LOGFONT。能否不用CFontDialog初始化LOGFONT。在OnDraw()里,
可以pDC->GetCurrentFont()->GetLogFont(&lpLogFont)这样初始化,但在构造函数里为什么不行?谁能说详细些?谢谢!

解决方案 »

  1.   

    Example// 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 characteristics given 
    // in a LOGFONT structure.
    CFont font;
    LOGFONT lf;
    memset(&lf, 0, sizeof(LOGFONT));       // zero out structure
    lf.lfHeight = 12;                      // request a 12-pixel-height font
    strcpy(lf.lfFaceName, "Arial");        // request a face name "Arial"
    VERIFY(font.CreateFontIndirect(&lf));  // create the font// Do something with the font just created...
    CClientDC dc(this);
    CFont* def_font = dc.SelectObject(&font);
    dc.TextOut(5, 5, "Hello", 5);
    dc.SelectObject(def_font);// Done with the font. Delete the font object.
    font.DeleteObject();