Thread: The relation between Font Size & Dialog Units

  1. #1
    Registered User
    Join Date
    Nov 2002

    The relation between Font Size & Dialog Units

    I have an app with about 200 controls created with CreateWindowEx at wm_create. Im now converting this controls to 3 dialogs at a resource file... Each dialog will show as a page called by a TabControl.

    Once I was finished doing that I found out that I had ruined the App UI. The size of the controls got completely different making the appearance horrible, lots of overlapped controls, some controls even got out of the app workspace, etc.

    I could not understand why that happened until I found out somewhere on the web that the dimensions in resource files are not pixels but "Dialog Units" based on the Font you select for that dialog in the resource file.

    Im sure you all probably knew that, I didnt lol. Well now the %$#!@# is done.
    What I am wondering here is that if theres no way to avoid that relation between Font Size and Dialog Units? It would be great to have the possibility of using exact px dimensions on dialogs like we use with CreateWindowEx...

    Maybe theres some way that I am not aware off?

    Sure we could always code something to resize the dimensions of the parent window in order to fit the dialog needs (because it will vary depending if the user has large fonts or small fonts enables on his PC) but that can get too complicated when we are talking about a main window with lots of controls plus the dialogs, it would be necessary to not only resize the main window but also reposition some of the other main window controls, maybe do that at every Tab switch, etc.

    Im just a lame beginner in what concerns the WinAPI, maybe theres some way to use exact px dimension into the resource file that Im not aware of?

    I will appreciate any tip, thanks

  2. #2
    Registered User
    Join Date
    Nov 2002
    Wow, 40 views and no replies, that is enough for me to understand that I am probably asking an extremely dumb question.

    Sorry about that

  3. #3
    Join Date
    Jan 2002
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  4. #4
    Registered User
    Join Date
    Feb 2003
    GetDialogBaseUnits only returns the base units for the system font, which is bigger than the default GUI font. To return base units for any font, use this version of GetDialogBaseUnits that I created:

    // hDC - DC of desired window
    // hFont - handleof desired font
    DWORD GetDialogBaseUnitsEx( HDC hDC, HFONT hFont ){
     HFONT hFontPrev = NULL;
     char *alphabet = "abcdefghijklmnopqrstuvwxyz"
     SIZE sz,psz;
     if(!hDC) return FALSE; 
     if(hFont) hFontPrev = SelectFont(hDC, hFont);
     if(!GetTextMetricsA(hDC, &tm)) return FALSE;
     if(!GetTextExtentPointA(hDC, alphabet, 52, &sz)) return FALSE; = tm.tmHeight; = ( / 26 + 1) / 2;
     if (hFontPrev) SelectFont(hDC, hFontPrev);
     return MAKELONG(,;
    // helper macros to convert dialog units to pixel units
    // DlgSizeX(DlgWidth,BaseUnits)
    // DlgSizeY(DlgHeight,BaseUnits)
    #define DlgSizeX(x,db)    MulDiv((x),LOWORD(db),4)
    #define DlgSizeY(x,db)    MulDiv((x),HIWORD(db),8)
    Last edited by poccil; 02-27-2003 at 02:15 PM.

  5. #5
    Registered User
    Join Date
    Nov 2002
    Thank you both for answering. I am getting the TabControl display area and resizing the Dialog to fit it. I guess its kindda of what you guys are suggesting me.

    So tell me: Theres absolutely no way for me to edit the resource file and use px dimensions inside it? It will always be DLUs (MS Dialog Units )?

    Thanks for the patience

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Change Font Size
    By strokebow in forum Windows Programming
    Replies: 1
    Last Post: 03-30-2009, 12:01 PM
  2. Adventures in labyrinth generation.
    By guesst in forum Game Programming
    Replies: 8
    Last Post: 10-12-2008, 01:30 PM
  3. Font size n ASCII code
    By kewell in forum C Programming
    Replies: 4
    Last Post: 07-15-2002, 09:25 AM
  4. font size and ASCII code
    By kewell in forum Windows Programming
    Replies: 1
    Last Post: 07-15-2002, 02:35 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM