Click to See Complete Forum and Search --> : Changing Default Font in a Dialog


Rick VanDeMaat
April 1st, 1999, 07:14 AM
I have a dialog based application that is used by users with various screen

resolutions. I use a default font set up in the resource editor

(10 pt. MS Sans Serif). This works fine on the higher resolution screens but in

800x600 it is too big to fit on the screen. If I use an 8 pt. font, it looks

better in low res but is too small in high res. I have been trying to change the

font on the fly by using the following code in the OnInitDialog;

d_dfont = GetFont();

d_dfont->GetLogFont(&d_lf);

d_dfont = new CFont();

d_lf.lfHeight -= 2;

d_dfont->CreateFontIndirect(&d_lf);

SetFont(d_dfont);

CClientDC dc(this);

dc.SelectObject(d_dfont);

This has no apparent affect. I have tried the same thing in the OnSetFont and

OnPaint functions also to no avail. What I want to do is to test the screen

resolution and then set the default font before displaying the dialog. Does

anyone know how this can be done?

Dazza
April 1st, 1999, 09:26 AM
You can use GetSystemMetrics with SM_CXFULLSCREEN, SM_CYFULLSCREEN to get the size of the screen (I think). As for changing the font, I did something similar for a 16 bit app once, and ended up enumerating all the child windows of the dialog and explicitly setting the font of each. I did this from OnInitDialog, and it worked fine, but whether it's a good way to do it...

Rick VanDeMaat
April 1st, 1999, 10:14 AM
You are right, I have used GetSystemMetrics to determine the screen resolution.

However, I was hoping to avoid having to resize each control individually. It

seems like I should be able to set the default font before the dialog is

displayed and have everything re-size itself accordingly (or is this something

that only happens in the Resource Editor?).

Santhosh Cheeran
April 1st, 1999, 01:00 PM
what about OnCtlColour(), I don't remember exactly , I have changed the color and I think even the font also. I am pretty sure because I remember I was putting a font dialog selecting the font and size and then displaying the text in that font(something similar to word art). invalidate() must call the OnCtlColor(), if you have to do it intermittent in your code. Note that it has got a CDC as an argument.


Good Luck

Rick Ullett
August 3rd, 1999, 12:34 PM
Hello:

My name is Rick Ullett, and I work at the Dayton Power and Light Company. I came across your question regarding re-sizing the point size for a dialog box. Reading your question was like taking the words right out of my mouth.
My attempt to do this in code was also virtually the same as the unsuccessful attempt you listed.

Did you ever find a clean way to do this? The code guru repsonses didn't look that promising.

If you get a chance, I'd sure like to know what you found out.

Thanks in advance,

Rick