다음을 통해 공유


CFont::FromHandle

에 대 한 포인터를 반환는 CFont 주어졌을 때 개체는 HFONT Windows GDI 글꼴 개체를 처리 합니다.

static CFont* PASCAL FromHandle( 
   HFONT hFont  
);

매개 변수

  • hFont
    HFONT Windows 글꼴을 처리 합니다.

반환 값

에 대 한 포인터는 CFont 개체를 성공적으로 수행 하는 경우. 그렇지 않으면 NULL.

설명

경우는 CFont 개체는 이미 연결 되지 않은 핸들을 임시 CFont 개체를 만들고 연결 합니다. 이 임시 CFont 개체 다음에 응용 프로그램이 유휴 시간 이벤트 루프에서 수집 하기 전에 모든 임시 그래픽 시간에 개체 삭제에 유효 합니다. 다른 방식으로 말하면 한 창 메시지 처리 중 임시 개체가 잘못 되었습니다입니다.

예제

// 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);

요구 사항

헤더: afxwin.h

참고 항목

참조

CFont 클래스

계층 구조 차트