Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fonts in dialog box 1

Status
Not open for further replies.

timmay3141

Programmer
Dec 3, 2002
468
US
I have a dialog box and I'm using various Greek letters in static text. The following code works fine in most cases, but when I put it in the OnInitDialog function it doesn't work at all. Instead, I get abnormally large and bold letters instead of the Greek characters I should get. Here's the code I'm using to do try this. m_Coord1, 2, and 3 are CStatic controls mapped to text on the dialog box.

BOOL CCoordsDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// TODO: Add extra initialization here
CFont fnGreek;
CFont fnNormal;

CDC* pDC = GetDC();

//fnGreek.CreatePointFont(100, "Math1", pDC);
fnNormal.CreatePointFont(80, "MS Sans Serif", pDC);

fnGreek.CreateFont(20, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, SYMBOL_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Times New Roman");

m_Coord1.SetFont(&fnNormal);
m_Coord2.SetFont(&fnGreek);
m_Coord3.SetFont(&fnNormal);

m_Coord1.SetWindowText("r ="); // Normal letter r
m_Coord2.SetWindowText("q ="); // Greek letter theta
m_Coord3.SetWindowText("z ="); // Normal letter z

fnGreek.DeleteObject();
fnNormal.DeleteObject();

ReleaseDC(pDC);
UpdateData(FALSE);

return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}

I commented out the CreatePointFont line for fnGreek, because I thought CreateFont might work correctly where CreatePointFont does not. It doesn't work any better though. I should also note that q is not theta in this new font (I don't know what character to use for theta in the symbols for Times). I also might be trying to use the symbols of Times incorrectly, because my book gives absolutely no clue as to how this is done, it simply says you can use SYMBOL_CHARSET instead of ASCII_CHARSET. So, if you could tell my why this isn't working, I would appreciate it.
 
I made a typo there. I wrote ASCII_CHARSET when I meant ANSI_CHARSET.
 
look at what your doing.

1) creat font
2) set font
3) destroy font

how do you expect the window to use a font resource that you have already released?

make your fonts member variables of a class that gives them the correct scope (lifetime). In your case perhaps "CCoordsDlg".

hope that helps
-pete
 
Oh man, how did I miss that. Thanks a lot for pointing this out. I never catch my stupid mistakes.
 
I'm trying to change the font for a EditBox in a dialog. I'm using your code, and the font member variables are moved to the dialog class. But I can still not use
myEditBox.SetFont(&myFont);
 
>> But I can still not use

Your getting a compile error? post it and the relevant code

-pete
[sub]I just can't seem to get back my IntelliSense[/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top