
simple question -- Set font for CEdit control
The real problem is, as pointed out below, the fact that your CFont is
destroyed on exit, deleting the font. You can get around this by doing
{
CFont font;
font.CreateFontIndirect(...);
c_Edit.SetFont(&font);
font.Detach();
}
The Detach operation dissociates the HFONT (the underlying Windows
object) from the CFont (the C++ wrapper for the HFONT) so when the
wrapper is destroyed, the font is not. However, note that you now have
a "resource leak", in that if you then set the font again, the only
reference to the HFONT is lost and the font space is lost until your
program exits. Therefore, you probably need to do something like
{
CFont font;
c_Edit.GetFont(&font);
font.DeleteObject();
font.CreateFontIndirect(...);
c_Edit.SetFont(&font);
font.Detach();
}
Note, by the way, that it is silly to use the "m_" prefix for a local
variable; this is supposed to be used only for member variables of a
class, not local variables. Personally, I think the m_ prefix is a bit
of gratuitous nonsense, and I only use it for member variables that
are initialized by the caller of a dialog, but if you are going to use
it, it should be used in a fashion consistent with its intended usage.
joe
On 10 Sep 1999 18:08:11 PDT, "Cecil A. Galbraith"
Quote:
>It appears that you are creating the CFont instance in a function, so that
>the font will die as soon as the function exits. Move the:
> CFont m_Font;
>line to th header for this file and you might get better results...
>Cecil