Compartir a través de


CFont::FromHandle

Devuelve un puntero a un objeto de CFont cuando se especifica un identificador de HFONT a un objeto de fuente de Windows GDI.

static CFont* PASCAL FromHandle( 
   HFONT hFont  
);

Parámetros

  • hFont
    Un identificador de HFONT a una fuente de Windows.

Valor devuelto

un puntero a un objeto de CFont si correctamente; si no NULL.

Comentarios

Si un objeto de CFont no ya está asociado al identificador, se crea y se adjunta un objeto temporal de CFont . Este objeto temporal de CFont sólo es válido hasta la próxima vez que la aplicación tenga tiempo de inactividad en el bucle de eventos, momento en el que todos los objetos gráficos temporales se eliminan. Otra manera de indicar es que el objeto temporal sólo es válido durante el procesamiento de un mensaje de ventana.

Ejemplo

// The code fragment shows how to create a font object using 
// Windows API CreateFontIndirect(), convert the HFONT to a  
// CFont* before selecting the font object into a DC (device  
// context) for text drawing, and finally delete the font object. 

// Initialize a CFont object with the characteristics given  
// in a LOGFONT structure.
LOGFONT lf;

// clear out structure
memset(&lf, 0, sizeof(LOGFONT));     
// request a 12-pixel-height font
lf.lfHeight = 12;           
// request a face name "Arial"
_tcsncpy_s(lf.lfFaceName, LF_FACESIZE, _T("Arial"), 7);
// create the font
HFONT hfont = ::CreateFontIndirect(&lf);  

// Convert the HFONT to CFont*.
CFont* pfont = CFont::FromHandle(hfont);

// Do something with the font just created...
CClientDC dc(this);
CFont* def_font = dc.SelectObject(pfont);
dc.TextOut(5, 5, _T("Hello"), 5);
dc.SelectObject(def_font);

// Done with the font. Delete the font object.
::DeleteObject(hfont);

Requisitos

encabezado: afxwin.h

Vea también

Referencia

CFont Class

Gráfico de jerarquías