GetDialogBaseUnits

3.0

  DWORD GetDialogBaseUnits(void)    

The GetDialogBaseUnits function returns the dialog box base units used by Windows when creating dialog boxes. An application should use these values to calculate the average width of characters in the system font.

Parameters

This function has no parameters.

Return Value

The low-order word of the return value contains the width, in pixels, of the current dialog box base-width unit, if the function is successful (this base unit is derived from the system font); the high-order word of the return value contains the height, in pixels.

Comments

The values returned represent dialog box base units before being scaled to dialog box units. The dialog box unit in the x-direction is one-fourth of the width returned by the GetDialogBaseUnits function. The dialog box unit in the y-direction is one-eighth of the height returned by the function.

To use GetDialogBaseUnits to determine the height and width, in pixels, of a control, given the width (x) and height (y) in dialog box units and the return value (lDlgBaseUnits), use the following formulas:

(x * LOWORD(lDlgBaseUnits)) / 4
(y * HIWORD(lDlgBaseUnits)) / 8

To avoid rounding problems, perform the multiplication before the division, in case the dialog box base units are not evenly divisible by four.

Example

The following example calculates tab stops based on the dialog box base units:

HMENU hmenu;
WORD DlgWidthUnits;
WORD TabStopList[4];

case WM_CREATE:
    hmenu = LoadMenu(hinst, "TabStopsMenu");
    SetMenu(hwnd, hmenu);
    DlgWidthUnits = LOWORD(GetDialogBaseUnits()) / 4;
    TabStopList[0] = (DlgWidthUnits * 16 * 2);
    TabStopList[1] = (DlgWidthUnits * 32 * 2);
    TabStopList[2] = (DlgWidthUnits * 58 * 2);
    TabStopList[3] = (DlgWidthUnits * 84 * 2);
    break;