Solved

Forcing dialogs to use a certain font

Posted on 1998-08-04
6
243 Views
Last Modified: 2013-12-03
I would like to use a specific font in all of my dialog boxes. The reason this is important to me is that I want to avoid the problem associated with dialog box layout when users choose "large fonts" in the display control panel.

When my application starts up, I create a font with the following code:

       s_DefaultFont = CFont::FromHandle((HFONT) GetStockObject(DEFAULT_GUI_FONT));
      PetzAssert (s_DefaultFont);
      LOGFONT fontStruct;
      s_DefaultFont->GetLogFont (&fontStruct);
      fontStruct.lfHeight = -11;
      fontStruct.lfWeight = 400;
      s_DefaultFont = new CFont;
      s_DefaultFont->CreateFontIndirect (&fontStruct);

I then call SetFont on all of the controls I put in my dialog boxes. However, this font seems to get overridden when I test my application under "Large Fonts". Can you tell me how I can force all my application's dialogs to use the font I created above? Or, do you have a better solution to the large font problem?

Thanks,
Brett Levine
0
Comment
Question by:circuit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 2

Expert Comment

by:lucidity
ID: 1320229
Forcing the font won't do it, the font size is controlled by windows and if want to change you have to reboot (dumb huh). you will still get controls that are out of place. The only way to make sure everything stays in the proper relative postition is to set it explicitly.

use m_OBJECT.MoveWindow(118,143, 53,23); for your buttons, text areas, drop boxes, ect. You have to go thorough and figure out the x,y,width,height for each control, have fun :)

I spent a long time on this and this IS the easiest way to get around this problem.
0
 

Author Comment

by:circuit
ID: 1320230
Actually, all my controls *are* specified in the manner you mentioned (ie in pixels, not dialog units), in code. The code snippet I included does create a font of the size I want (in this case, 11 point), but I can't seem to get that font to be used when the user's fonts are set to Large Fonts (via control panel). Any idea why it won't use my small font?

Thanks,
bre++
0
 
LVL 2

Expert Comment

by:lucidity
ID: 1320231
well.. like I said. thats controlled by windows and cannot be dynamically changed. Alternativly, you can GetSystemMetrics() find out if it is set to small or large fonts then change your font accordingly. Now that you've clarified I had the same problem, in most cases I just left it, but in some cases I had to do what I mentioned above.

good luck
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:kumarana
ID: 1320232
These font problem messed up my life for 3 months. The problem
with window even though you ask for a font with particular metrics you are not guarenteed to get it.There is a font example
program in VC++ samples compile it and run. that program will help you find what are possible fonts you can create on one machine.

But there is a catch there also not all machines have same font.

after you decided on the metrics and font name.

In initdialog
1.Create a font and get a handle to it.
2.Get the window handle of your controls box.
3.Send a message WM_SETFONT to all the controls with
  the font handle.
 
The point is font with the metrics you call CreateFontIndirect()
should exist on the PC.

So use the font program run in all resolutions with large and
small font settings. find out a font which exists in all cases.

I don't exactly remember but I think I finally decided on "Small Font" .

Tell me if this helps..
0
 
LVL 1

Expert Comment

by:kumarana
ID: 1320233
one more thing if windows cannot create a font with the metrics you asked it does not return FALSE. It returns nearest possible fit. BE careful about this feature/bug/pitfall!!!!.
0
 
LVL 8

Accepted Solution

by:
Answers2000 earned 100 total points
ID: 1320234
Don't do it with code,  do it with resources.

In Dev Studio bring up the dialog (by double clicking on it's name in the resource tree).  The dialog box is display.  Right click outside of any controls on some background part of the dialog and pick properties (VC5) or just double click on the background of the dialog (VC4).  On the General Tab is a "Font" button.  You can force the font from here.  Only one font per dialog with this method.

One final point, make sure you use a font which comes with Windows, or you will get different results on machines that have different fonts installed.
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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…

688 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