circuit
asked on
Forcing dialogs to use a certain font
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->CreateFontI ndirect (&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
When my application starts up, I create a font with the following code:
s_DefaultFont = CFont::FromHandle((HFONT) GetStockObject(DEFAULT_GUI
PetzAssert (s_DefaultFont);
LOGFONT fontStruct;
s_DefaultFont->GetLogFont (&fontStruct);
fontStruct.lfHeight = -11;
fontStruct.lfWeight = 400;
s_DefaultFont = new CFont;
s_DefaultFont->CreateFontI
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
ASKER
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++
Thanks,
bre++
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
good luck
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..
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..
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!!!!.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
use m_OBJECT.MoveWindow(118,14
I spent a long time on this and this IS the easiest way to get around this problem.