• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 591
  • Last Modified:

Changing the Font of a Dialog to resize the Dialog

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
rakok
Asked:
rakok
  • 4
  • 3
1 Solution
 
FargoCommented:
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
 
FargoCommented:
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
 
rakokAuthor Commented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
mikeblasCommented:
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
 
FargoCommented:
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
 
rakokAuthor Commented:
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
 
rakokAuthor Commented:
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
 
rakokAuthor Commented:
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now