Click to See Complete Forum and Search --> : Once again - PLEASE !! - Programatically setting the font size of a dialog


Rick Ullett
September 9th, 1999, 07:07 AM
This question has been posted at least three times
(including one from me earlier) since I've been participating in the forum. But,... I haven't as
of yet seen a successful response. I promise to
try all suggested solutions and respond with a comment on the success or failure.


I know this is the same question posted earlier, but it didn't ever get a satisfactory solution.

I did try to do a similar approach to the one listed below in an override of the OnPaint funtion, as suggested to me in my earlier posting.
As I replied to that attempt, it "seems" like it should work - it just doesn't. (Please see my
response posted 8/31/99 on this issue for my
attempt on the OnPaint override.)

So, I'll try again:

I have a SDI application that is used by users with various screen resolutions. I use a default font set up in the resource editor for many dialog boxes used by the task.
(EX: 10 pt. MS Sans Serif). This works fine on the higher resolution screens but in 800x600 or 640x480 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 OnSetFont:

LOGFONT d_lf;
CFont newFont;
BOOL font_ok;

// Pick up the existing dialog font

pfont -> GetObject(sizeof(d_lf),&d_lf);

// Change the font size

d_lf.lfHeight = -13;

// Create a new font with the new height
font_ok = newFont.CreateFontIndirect(&d_lf);

// Call the standard OnSetFont with the newly
// created font.
CDialog::OnSetFont(&newFont);

This has no apparent affect. I have tried the same thing in the OnInitDialog function also to no avail. I have also played with the value for the new height, or switching to a new font family , but again without success. What I want to do is to set the default font before displaying the dialog box. Does anyone know how this can be done?

I do not want to adjust the size of each control in a dialog individually. I also don't want to create "copies" of the same dialog at various point sizes. These alternatives make the code too ugly, and difficult to support.

Thanks in advance to anyone who can help.

Wayne Fuller
September 9th, 1999, 07:23 AM
There is a good article on this website that you should find helpful. It is at http://www.codeguru.com/dialog/ChangeDefaultDialogFont.shtml . It talks about just what you need. Check it out. It allows you to change the dialog font via the dialog template at runtime. It would be easy to just change the font for every control to a bigger size, but then the dialog box would remain the same and you may lose some things on the dialog. This article does it through the template so that the dialog actually will "grow" to the size of the font. Works great.

Rick Ullett
September 9th, 1999, 12:25 PM
Wayne:

Thank you very - very much. You were right. The
article described just what I needed.

ALM
September 9th, 1999, 12:44 PM
Thanks for the tip!

I had also asked this question a week or so ago and no one had answered it. I'm really glad you did!

Alvaro