Click here to Skip to main content
12,897,457 members (48,318 online)
Click here to Skip to main content
Add your own
alternative version


39 bookmarked
Posted 16 Nov 2003

Fight the dialog units, DPI and Large Fonts

, 16 Nov 2003 Zlib
Rate this:
Please Sign up or sign in to vote.
Guarantees pixel-to-pixel matching appearance of resource-based dialogs for different font DPIs


Resource-based dialogs, made with a dialog editor do have a potential problem of being scaled improperly for larger Windows font resolutions, no matter whether MFC, ATL, WTL or bare Win32 is used.

The given class allows to pin down and fix a particular DPI mode for a particular dialog resource. Furthermore, DPI resolution/scaling of a resource-based dialog can be dynamically changed in run-time.


For example, static bitmaps on the dialogs normally do not get resized, thus if one would want to make some fancy bitmap background or matched illustration, one will obviously run into problems with "Large Fonts" Windows mode. This is especially useful for wizard-style and login dialogs.

Some of the users tend to have "Large size (120 DPI)" font mode set, which is problematic for the developers, as triple checks are to be made to find out whether dialogs designed look properly in 120 DPI mode.

If the program interface is mostly bitmap based, the best way is to lock the resolution down to 96 DPI and disallow any further dialog scaling. Well, unfortunately, Windows does not seem to have an easy way of turning off DPI-dependent dialog scaling and "dialog units". I've been looking through the network and so far found no easy solutions for the given problem.

Therefore, I have written a class. Once Attach method is invoked in the WM_INITDIALOG handler before the dialog is shown, the dialog will be resized and adjusted in run-time to match the specified resolution.

The supplied code contains a subroutine to re-parse of the dialog resource and to re-calculate DPI-related values such as control positions and sizes. Resolution in DPI is specified as the parameter to the Attach method, and the standard Windows resolution is 96 DPI.

Using the code

The code is tested and functional within MFC, ATL/WTL and Win32 frameworks.

MFC Example:


BOOL CMyDlg::OnInitDialog()

    dpi.Attach(AfxFindResourceHandle(IMAKEINTRESOURCE(IDD), RT_DIALOG),
               m_hWnd,IDD,96.0); // 96 is the DPI

    // The rest of your initialization code goes here

    return TRUE;

ATL/WTL Example:


BOOL CMyDlg::OnInitDialog()

    //                                                         ^^^^ DPI

    // The rest of your initialization code goes here

    return TRUE;


I have looked for an easier way, but so far I have found none. The parser will only work with DIALOGEX structures and will not work with obsolete DIALOG structures.

Also you have to explicitly specify the dialog font. For proper sizing, you need to use Microsoft Sans Serif or Tahoma (and NOT MS Sans Serif or MS Shell Dlg). Tahoma has exactly the same metrics as Microsoft Sans Serif. You can use any other TrueType/OpenType font, avoid using bitmap fonts, as they will not scale well.

Due to obvious reasons, the size of a checkbox square is not affected, though it still will get proper placement and align.


This article, along with any associated source code and files, is licensed under The zlib/libpng License


About the Author

George Yohng
Web Developer
Austria Austria
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionWhy don't effect on multiline edit and checkbox? Pin
nhchmg21-Jul-11 23:10
membernhchmg21-Jul-11 23:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170424.1 | Last Updated 17 Nov 2003
Article Copyright 2003 by George Yohng
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid