The text is not on a control.
It is on the main dialog as a static text on the screen tha I can change.
Also, not all fonts elsewhere need to be resized.
I just need this message text aprox 3x normal size.
"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
See below...
On Mon, 23 Feb 2009 13:53:39 -0500, "Ed" <ed@ed.com> wrote:
Hi,
I have the folowing routine to display some text when a button is clicked
using a larger font.
The problem is that when you have another window overlap it, the text
reverts to default font.
How do I make the larger font permanent?
void CMyDlg::OnSelect1()
{
GetDlgItem(IDC_TEXT1)->SetWindowText("Test text");
****
First: when creating controls, give them meaningful names.
Second: forget you ever heard of GetDlgItem. Consider it obsolete. True,
it is used in
extremely rare and exotic circumstances, which you do not have here.
Learn to create
control variables
****
CStatic *lpLabel=(CStatic *)GetDlgItem(IDC_TEXT1);
CFont LabelFont;
****
And as soon as you leave this function, the CFont::~CFont method deletes
the font, and you
are left with an invalid font handle. You need to make this a member
variable.
Generally, you create a font when the control first comes into existence,
for example, in
the PreSubclassWindow method of your CStatic subclass, or in the
OnInitDialog of your
dialog or OnInitialUpdate of your CFormView. The font variable is a
member variable of
your subclass, or if you do it in OnInitialUpdate/OnInitDialog, a member
variable of your
dialog class.
*****
LabelFont.CreateFont(18,18,0,0,FW_BOLD,FALSE,FALSE,0,DEFAULT_CHARSET,OUT_CHARACTER_PRECIS,CLIP_CHARACTER_PRECIS,
DEFAULT_QUALITY, DEFAULT_PITCH,NULL);
lpLabel->SetFont(&LabelFont,TRUE);
***
Note that by creating this each time you click the button, you leak a new
font each time
you click the button. If you move the declaration of the CFont variable
to your class,
and leave the CreateFont here, the second time you click the button you
will get an
assertion failure because the font already exists.
I notice you do not specify the face name, not a great idea in font
creation. Also, the
choice of 18 is dangerous because on different displays this will produce
different
effects.
I might do something of the following:
OnInitDialog:
CFont * f = c_Text1.GetFont();
ASSERT(f != NULL);
LOGFONT lf;
f->GetLogFont(&lf);
CRect r;
c_Text1.GetWindowRect(&r);
ScreenToClient(&r);
lf.lfHeight = (int) - ((double) r.Height() * 0.75);
lf.lfWeight = FW_BOLD;
LabelFont.CreateFontIndirect(&lf);
c_Text1.SetFont(&LabelFont);
Here I chose to create a font that is 75% of the size of the control, no
matter what size
it ends up being (choose any multiplier you think looks good). The font
is also
consistent with the current font the user is using, just bigger and
bolder. The "font
matching" algorithm that is used by Microsoft is a deeply flawed concept,
which mimics the
horrible design of HP printers (the only important parameters are the face
name, weight
and height; everything else should be treated as useless fluff, but it
doesn't work that
way)
joe
}
Thanks in advance.
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm