Click here to Skip to main content
11,790,987 members (60,801 online)
Click here to Skip to main content

Fight the dialog units, DPI and Large Fonts

, 16 Nov 2003 Zlib 161.4K 3.4K 38
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

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
"_$h@nky_"26-May-09 23:53
member"_$h@nky_"26-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
aisonbert4-Apr-06 16:49
memberaisonbert4-Apr-06 16:49 
AnswerRe: an issue when using it in my dialogbar Pin
aisonbert6-Apr-06 16:01
memberaisonbert6-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 
What is stupid, is users like you criticizing and not providing a better solution. What you ask is not simple and can be very messy, having to resize control, dialogs, set different fonts, resize images, etc. and then watch the glitches as the screen refreshes it.

This solution is simple, fast, and in the majority of cases fixes the issue with little pain. The dialog can be designed with both type of users (96 & 120) in mind so the impact on them is reduced.

If you dont like this then provide us with a better mechanism, instead of just saying its stupid. There are some examples on the internet all of which so far have some issues which need to be addresses to be a complete solution. Meanwhile this solution is great imho.

nw Smile | :)
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 
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
sussAnonymous1-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 
GeneralUse it in Windows98 Pin
hansworscht16-Jun-04 4:23
memberhansworscht16-Jun-04 4:23 

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

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

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