Re: Problem in Drawing Text with different Fonts & Charset
From: Joseph M. Newcomer (newcomer_at_flounder.com)
Date: 08/27/04
- Next message: Suresh: "XP Look and Feel in Windows 2000 using vc++ 6.0"
- Previous message: David Lowndes: "Re: Cannot view my computer in CFileDialog when initialize COM in MTA"
- In reply to: Marco Hung: "Problem in Drawing Text with different Fonts & Charset"
- Next in thread: Jakir: "Re: Problem in Drawing Text with different Fonts & Charset"
- Reply: Jakir: "Re: Problem in Drawing Text with different Fonts & Charset"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 27 Aug 2004 03:21:11 -0400
(a) did you verify that CreateFont actually succeeded?
VERIFY(newFont.CreateFont(...));
would be a good start. Also, although you say you are selecting the HFONT, you actually
are selecting the CFont *. The code shown should not compile; the correct code should be
CFont * oldFont = CurDC.SelectObject(&newFont);
(b) Why are you calling GetDC? This should only be done in the OnPaint handler, which
already declares a DC for your use, CPaintDC dc(this); But if you need a DC, the correct
format is to do CClientDC dc(this);, not your own GetDC/ReleaseDC.
I've never used any iconographic font, so I'm not sure how to create one. Someone else
will have to jump in with advice on that. I know that the basic Arial font does not have
any glyphs, but the font "Arial Unicode MS" has a huge number of glyphs. But since you do
not verify the font creation worked, there is no way to tell what any of this code means.
But the presence of the GetDC is deeply suspicious, and I suspect you have additional
problems you need to address.
Also, read my essay on using SaveDC/RestoreDC, on my MVP Tips site, to avoid using more
and more variables to hold saved state.
joe
On Fri, 27 Aug 2004 11:47:21 +0800, "Marco Hung" <marco@xmlhk.com> wrote:
>Dear all,
>
>I'm working in a program which will draw some string with both chinese and
>English character in the Window.
>
>I try to use CreateFont() to create a HFONT with Fonts "Arial" and CharSet
>"CHINESEBIG5_CHARSET" and then select the HFONT to the current DC. However
>the text drawing out isn't in Font "Arial" (It seems to be "Times New Roman"
>instead).
>
>After that, I try to use other available fonts on my platform, but the same
>outpur again. No matter what font I'm using, it give the same output!!!
>
>Does anyone know Why and how to fix it?
>
>Here I attached part of my code.
>
>.
>.
>.
>CDC CurDC = GetDC();
>CFont newFont;
>newFont.CreateFont(20, 0, 0, 0, FW_NORMAL, FALSE, FALSE,
> 0, CHINESEBIG5_CHARSET, OUT_DEFAULT_PRECIS,
> CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
> DEFAULT_PITCH, _T("Arial")); // <- No matter what
>font I use, the program will "Times New Roman" to print text!
>CFont oldFont = CurDC.SelectObject(newFont);
>
>// Draw the Text in Screen
>
>CurDC.SelectObject(oldFont );
>ReleaseDC(CurDC);
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
- Next message: Suresh: "XP Look and Feel in Windows 2000 using vc++ 6.0"
- Previous message: David Lowndes: "Re: Cannot view my computer in CFileDialog when initialize COM in MTA"
- In reply to: Marco Hung: "Problem in Drawing Text with different Fonts & Charset"
- Next in thread: Jakir: "Re: Problem in Drawing Text with different Fonts & Charset"
- Reply: Jakir: "Re: Problem in Drawing Text with different Fonts & Charset"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|