Click here to Skip to main content
15,041,764 members
Articles / Desktop Programming / WTL
Posted 16 Nov 2003


44 bookmarked

Fight the dialog units, DPI and Large Fonts

Rate me:
Please Sign up or sign in to vote.
4.95/5 (25 votes)
16 Nov 2003Zlib2 min read
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

Comments and Discussions

GeneralTitle Bar Size is to big and border also big in MFC dialog Pin
Beniwal0130-Oct-17 21:36
MemberBeniwal0130-Oct-17 21:36 
GeneralMy vote of 5 Pin
omindream6-Feb-13 22:05
Memberomindream6-Feb-13 22:05 
QuestionWhy don't effect on multiline edit and checkbox? Pin
nhchmg21-Jul-11 23:10
Membernhchmg21-Jul-11 23:10 
GeneralHelp for use in Visual C Pin
symons6527-Jun-10 6:10
Membersymons6527-Jun-10 6:10 
QuestionHow can use it in SDI or MDI type application? Pin
Le@rner26-May-09 23:53
MemberLe@rner26-May-09 23:53 
Generalscaling factor for dialog resource [modified] Pin
athish12-Apr-07 2:23
Memberathish12-Apr-07 2:23 
QuestionPropertySheet Tab title size is still too big Pin
Luckymmkay1-Dec-06 6:02
MemberLuckymmkay1-Dec-06 6:02 
AnswerRe: PropertySheet Tab title size is still too big Pin
George Yohng1-Dec-06 6:37
MemberGeorge Yohng1-Dec-06 6:37 
GeneralRe: PropertySheet Tab title size is still too big Pin
Luckymmkay1-Dec-06 8:40
MemberLuckymmkay1-Dec-06 8:40 
Questionan issue when using it in my dialogbar Pin
Albert19864-Apr-06 16:49
MemberAlbert19864-Apr-06 16:49 
AnswerRe: an issue when using it in my dialogbar Pin
Albert19866-Apr-06 16:01
MemberAlbert19866-Apr-06 16:01 
Generalthe issue using MSLU in windows 98/me Pin
ssliao21-Feb-06 20:50
Memberssliao21-Feb-06 20:50 
GeneralRe: the issue using MSLU in windows 98/me Pin
ssliao23-Feb-06 22:06
Memberssliao23-Feb-06 22:06 
GeneralOh no! Pin
Alexander Gräf26-Sep-05 0:46
MemberAlexander Gräf26-Sep-05 0:46 
GeneralRe: Oh no! Pin
George Yohng26-Sep-05 0:55
MemberGeorge Yohng26-Sep-05 0:55 
GeneralRe: Oh no! Pin
Nic Wilson3-Apr-06 18:17
MemberNic Wilson3-Apr-06 18:17 
GeneralRe: Oh no! Pin
CodeSafe Hawk12-Mar-09 4:22
MemberCodeSafe Hawk12-Mar-09 4:22 
GeneralExcellent job Pin
iberg4-Jul-05 0:09
Memberiberg4-Jul-05 0:09 
George Yohng10-May-05 2:47
MemberGeorge Yohng10-May-05 2:47 

If IMAKEINTRESOURCE symbol gets you an error (MFC example), then use simple MAKEINTRESOURCE (without leading I).


bensabat10-May-05 4:27
Memberbensabat10-May-05 4:27 
George Yohng15-May-05 3:41
MemberGeorge Yohng15-May-05 3:41 
GeneralMFC example Pin
Anonymous1-Feb-05 0:53
MemberAnonymous1-Feb-05 0:53 
GeneralRe: MFC example Pin
George Yohng12-Feb-05 5:21
MemberGeorge Yohng12-Feb-05 5:21 
GeneralRe: MFC example Pin
bensabat10-May-05 2:28
Memberbensabat10-May-05 2:28 
GeneralRe: MFC example Pin
George Yohng15-May-05 3:49
MemberGeorge Yohng15-May-05 3:49 

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.