?
Solved

Converting between different font sizes

Posted on 2003-02-24
3
Medium Priority
?
515 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
[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
  • 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…

770 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