CFont vs. HFONT for rotated text
Mats Mеnhav -- manhav@connectum.skurup.se Thursday, May 23, 1996 -- [ From: Mats Manhav * EMC.Ver #2.5.02 ] -- Env: MSVC 4.1, NT 4.0 (1234) I wanted to build an application using rotated text. In MSDN I found some sample code that accomplished this. I took the code and built it into my MFC app. The sample code used HFONT but since I use MFC I replaced these by a CFont instead. However the text did not get rotated when I used the CFont. When I changed to using HFONT directly it worked alright. What is really going on here that makes the CFont not rotating the text. Mats Here is the "CFont" code I used: -------------------------------- class Mypage : public CPropertyPage { ... CFont * m_RotatedFont; ... } void Mypage::OnPaint() { CPaintDC dc(this); // device context for painting if (!m_RotatedFont) { CFont *olFont = dc.GetCurrentFont(); LOGFONT lf; olFont->GetLogFont(&lf); strcpy(lf.lfFaceName, "Arial"); lf.lfHeight = 13; lf.lfEscapement = 600; m_RotatedFont = new CFont; m_RotatedFont->CreateFontIndirect(&lf); } CClientRect rect(this); dc.SelectObject(&m_RotatedFont); dc.TextOut(rect.left+2, rect.bottom/2, "TimeZone1", 9); } Here is the "HFONT" code I used: -------------------------------- class Mypage : public CPropertyPage { ... HFONT m_RotatedFont; ... } void Mypage::OnPaint() { CPaintDC dc(this); // device context for painting if (!m_RotatedFont) { CFont *olFont = dc.GetCurrentFont(); LOGFONT lf; olFont->GetLogFont(&lf); strcpy(lf.lfFaceName, "Arial"); lf.lfHeight = 13; lf.lfEscapement = 600; m_RotatedFont = CreateFontIndirect(&lf); } CClientRect rect(this); SelectObject(dc.m_hDC, m_RotatedFont); dc.TextOut(rect.left+2, rect.bottom/2, "TimeZone1", 9); } -- ========================================================================== Mats Mеnhav (Mats Manhav for 7-bit people) email:manhav@connectum.skurup.se WWW: http://connectum.skurup.se/~manhav FAX: (int) 46 (0) 414 243 05 Phone: (int) 46 (0) 414 243 05 ==========================================================================
Mike Martonfi -- mikem@abelcomputers.com Thursday, May 30, 1996 m_RotatedFont is a pointer to a CFont, yet you do a = dc.SelectObject(&m_RotatedFont). The correct call should be = dc.SelectObject(m_RotatedFont); --------------------- Mike Martonfi mikem@abelcomputers.com
| Вернуться в корень Архива |