我用ATL做的控件

解决方案 »

  1.   

    使用COleControl::SelectStockFont函数,如添加了库存FONT属性后,在OnDraw中如下  CFont* pOldFont;
       TEXTMETRIC tm;
        const CString& strCaption = InternalGetText();   pOldFont = SelectStockFont( pdc );
       pdc->FillRect(rcBounds, CBrush::FromHandle(
       (HBRUSH )GetStockObject(WHITE_BRUSH)));
       pdc->Ellipse(rcBounds);
       pdc->GetTextMetrics(&tm);
       pdc->SetTextAlign(TA_CENTER | TA_TOP);
       pdc->ExtTextOut((rcBounds.left + rcBounds.right) / 2,
       (rcBounds.top + rcBounds.bottom - tm.tmHeight) / 2,
       ETO_CLIPPED, rcBounds, strCaption, strCaption.GetLength(),
       NULL);   pdc->SelectObject(pOldFont);
      

  2.   

    还有一种方法
     
       {
          IFontDisp* pFontDisp = NULL;
          IFont *pFont = NULL;
          HRESULT hr;      // Get the container's FontDisp interface
          pFontDisp = AmbientFont();
          if (pFontDisp)
          {
             hr = pFontDisp->QueryInterface(IID_IFont, (LPVOID *) &pFont);
             if (FAILED(hr))
             {
                pFontDisp->Release();
                return;
             }
          }      HFONT hFont = NULL;
          if (pFont)
          {
             pFont->get_hFont(&hFont);
           。
          }      pFontDisp->Release();
       }
      

  3.   

    或者使用
    LPFONTDISP GetFont( );
    void SetFont( LPFONTDISP pFontDisp );
    取得IFontDisp指针,调用和上面相同