Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Converting between different font sizes

Posted on 2003-02-24
3
Medium Priority
?
518 Views
Last Modified: 2013-12-03

Hello!
I have got a problem with dialog sizes in different sizes of font (set in Display properties in Control panels). I have normally set a Large (120dpi) font and my dialog has a width of 512 px. When I set a Small (96dpi) font, it has 387 pixels. I receive font size via GetDeviceCaps(hdc, LOGPIXELSX). I need to convert between these logical sizes of fonts - ie. I need the answer for: "If my dialog has 400px width using a 96dpi font, what width it will have when I set a 110dpi/120dpi/... font?". Logically, I thought, that is a 20/96=125 per cent larger....but 512/387=132 per cent larger! I'm totally confused. So...how can I convert sizes of dialog boxes/controls/etc. between different font settings?
Thank you very much,
Martin Simonovsky
0
Comment
Question by:myson
  • 2
3 Comments
 
LVL 49

Accepted Solution

by:
DanRollins earned 800 total points
ID: 8014212
Dialog box size and control locations are given in "dialog units."   Dialog units are based upon the size of the system default font (of the defualt font for the dialog), which would be controled by that control panel setting.

From MSDN:
"One horizontal dialog unit is equal to one-fourth of the average character width for the current system font. One vertical dialog unit is equal to one-eighth of an average character height for the current system font."

To convert between dialog units and screen units, use the GetDialogBaseUnits API:

     http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/windowing/dialogboxes/dialogboxreference/dialogboxfunctions/getdialogbaseunits.asp

in which is talks about using GetTextMetrics and MapDialogRect APIs for converstions.  See also these informative bits of wisdom:

    145994 - HOWTO: Calculate Dialog Units When Not Using the System Font
    http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B145994
 
    74280 - HOWTO: Translate Dialog-Box Size Units to Screen Units
    http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B74280

=-=-=-=-=-=-=-=-=-=-=-
But the overall recommendation is : make your dialog boxes small and don't try to move things around in them or do any sort of manual resizing.  Look at how Windows itself works:  Whenever a dialog gets at all large, it is made into a multiple-page property sheet.

-- Dan
0
 

Author Comment

by:myson
ID: 8014824
Yes, thank you, I know that - but when I convert screen units of my dialog to dialog units...it a different number again when I use different font size.

Martin
0
 

Author Comment

by:myson
ID: 8014963
No, I give you much of my apologies. I'm an idiot, now it works, with your help.
I receive the mapping coordinates via:
RECT rc = {0,0,4,8};
MapDialogRect(hDlg, &rc);

and store the value of width, which will be uniform to all font sizes, with this:
GetClientRect(hDlg, &rect);
rect.right /= rc.right;
rect.bottom /= rc.bottom;

and when I want the coordinates for any font size, I just use the reverse algorithm.
So I really thank you for your solution and here are your points.

Martin
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

564 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