Solved

Changing the Font of a Dialog to resize the Dialog

Posted on 1998-10-06
8
527 Views
Last Modified: 2013-12-03
I want to scale the size of my dialogs dependent of the Systemmetrics. So, I think, I have to change the font of the dialogs to resize automatically the Dialog (made in the resource editor).
But how can I do it? I have tried to use the OnSetFont-function, the SetFont-function etc., but without any effect.
Can you get me the code what I have to do and where (in what message-handler)?
Maybe there is an other (better) option to resize?
0
Comment
Question by:rakok
  • 4
  • 3
8 Comments
 
LVL 1

Expert Comment

by:Fargo
ID: 1323000
How do you specify the font in the CDialog::OnSetFont(CFont *pFont) function. And is that function called, anyway in your project? Did you declared it as virtual?
If the function is called by the framework, you have to attach the font to a GDI font object. Make sure you use CFont::Attach(...) function in implementation of your OnSetFont(...). If you do so, the scenario should work.
I hope I was help
0
 
LVL 1

Accepted Solution

by:
Fargo earned 70 total points
ID: 1323001
And one thing more. CDialog::OnSetFont(...) won't be called when you resize the dialog, so this function will not do the job. Sorry for my comment, because it's meaningless in this case. But take a look what I found...this sure will help you:


"In the Microsoft Windows graphical environment, an application can affect the appearance of a dialog box by specifying the DS_SETFONT style bit. DS_SETFONT is available only when the application creates a dialog box dynamically from a memory-resident dialog box template using the CreateDialogIndirect, CreateDialogIndirectParam, DialogBoxIndirect, or DialogBoxIndirectParam function. The second parameter to each of these functions is the handle to a global memory object that contains a DLGTEMPLATE dialog box template data structure. The dwStyle (first) member of the DLGTEMPLATE structure contains style information for the dialog box.

When an application creates a dialog box using one of these functions, Windows determines whether the template contains a FONTINFO data structure by checking for the DS_FONTSTYLE bit in the dwStyle member of the DLGTEMPLATE structure. If this bit is set, Windows creates a font for the dialog box and its controls based on the information in the FONTINFO structure. Otherwise, Windows uses the default system font to calculate the size of the dialog box and the placement and text of its controls.

If Windows creates a font based on the FONTINFO data structure, it sends a WM_SETFONT message to the dialog box. If Windows uses the system default font, it does not send a WM_SETFONT message. A dialog box can change the font of one or more of its controls by creating a font and sending a WM_SETFONT message with the font handle to the appropriate controls."

This text I found in the MS Knowledge Base. The conclusion of this is that you have to create you dialog using one of these functions:

CreateDialogIndirect(...)
CreateDialogIndirectParam(...)
DialogBoxIndirect(...)
DialogBoxIndirectParam

Fargo
0
 

Author Comment

by:rakok
ID: 1323002
Thanks for your answer so far. My question now is: Can't I use the resource editor to design the dialog boxes and to change the font later? Do I have to use the templates only? Then I must design my dialogs in code... Wonderfull VISUAL C++...

Can you tell me more about this?
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 11

Expert Comment

by:mikeblas
ID: 1323003
Visual C++ is a great product, if you know how to use it. Apparently, you don't.

So far, your question is quite unclear to me. (Wonderful Experts Exchange!) Do you want to change the font in a dialog you're designing? Do you want to change the font on the fly in a dialog box? In all the controls, or just some of the controls? Do you want to change the size of the controls after you change their fonts? Do you want to change their locations, too?

Finally, why?  Why do you want to do this?  Normally, you use the stock dialog font. That makes your application look consistent with other applications and makes your application readily localizable. Why would you want to change the font size at runtime?

B ekiM

0
 
LVL 1

Expert Comment

by:Fargo
ID: 1323004
you can construct the template in the resource section as you did before in the resource editor. Then you can use the function LoadResource(...) with the specific parameters (i suppose you'll read the reference about it). This function loads specific dialog template from the resources into a global memory block, which is needed by the functions I proposed before. The LoadResource() function needs a resource handle, which you can get using the function FindResource(...). All these functions are API ones (not class members).

P.S.
Pay attention to the DLGPROC parameter you have to supply to the CreateIndirectXXX functions. Read what the documentation states about the DialogProc. And yet another thing: don't expect the controls to resize automatically when you change the font. Unfortunately this is something you have to do by yourself.

Fargo
0
 

Author Comment

by:rakok
ID: 1323005
I shall tell my question clearer.
I make an application for an embedded device with Windows CE. This device can have several displays, big and little. However, the ratio between the dialog and the screen must be fixed always. So, the dialog must be bigger when the display is bigger.
On the fly (at starting up the application) I determine with GetSystemMetrics() what the size of the screen is. Then I want to change the size of the dialog. (When I change the size of the dialog font in the resource editor, a good result is given; however this is a fixed size for all screens.)
I thought, maybe I can change the size of the dialogfont when the object is constructed, or in OnInitDialog.
I want to resize all components of the dialog box, the fontsize (for all controls) and the metrics of the controls.

My question is: can I do this in combination with the dialog made in the resource editor (and how!), or do I have to make it in a template in memory, to change DS_SETFONT?

I hope, it's really clear now.
0
 

Author Comment

by:rakok
ID: 1323006
Hello, Fargo

I think it's maybe the right solution. But I need a HMODULE in FindResource, and in Windows CE it can't be NULL.
As described in the comment above, when I change the size of the font in the resource editor, the controls are resized automaticcaly. Is this really not possible when changing the size on the fly?
Can you me give a piece of code where I load a resource of IDD_DIALOG in a Template and then change the size of the Font fo that template, create the dialog and display it?

rakok
0
 

Author Comment

by:rakok
ID: 1323007
Your answer is the best so far. I am waiting for the code, but you get the points. I'll ask this in a new question
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question