SHGetUIMetrics

4/8/2010

The SHGetUIMetrics function retrieves the system font size.

Syntax

HRESULT SHGetUIMetrics (
  SHUIMETRIC shuim,
  PVOID pvBuffer,
  DWORD cbBufferSize,
  DWORD * pcbRequired
);

Parameters

  • shuim
    [in] Indicates how you want the system font size expressed. shuim must be one of the SHUIMETRIC values.
  • pvBuffer
    [out] Reference to the retrieved system font size value. Can be NULL. (See Remarks for details.)
  • cbBufferSize
    [in] The estimated size of pvBuffer.
  • pcbRequired
    [out] Reference to the actual size required for pvBuffer. Can be NULL. (See Remarks for details.)

Return Value

SHGetUIMetrics returns an HRESULT value of either S_OK or an appropriate error code.

Remarks

To ensure that your application displays properly, you should call SHGetUIMetrics to determine current system font size when your application starts. Also, after the window receives the SH_UIMETRIC_CHANGE notification that is broadcast whenever the user changes the system font size, you can call SHGetUIMetrics to determine the new font metrics and then determine whether the new font size requires a new layout of your window.

If you call SHGetUIMetrics to retrieve the system font size, shuim must be one of the three SHUIMETRIC values: SHUIM_FONTSIZE_POINT, or SHUIM_FONTSIZE_PIXEL, or SHUIM_FONTSIZE_PERCENTAGE. In this case, pvBuffer is a pointer to DWORD, and cbBufferSize is the size of a DWORD.

Note

In Smartphone for Windows Mobile 2003 and earlier, users cannot change the system font size.

Code Example

The following code example demonstrates how to use SHGetUIMetrics.

Note

To make the following code example easier to read, security checking and error handling are not included. This code example should not be used in a release configuration unless it has been modified to include them.

#include <Aygshell.h>
LRESULT CALLBACK SHUIMetricWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    // This message will only fire on Windows Mobile Professional and Windows Mobile Classic
    static UINT uMetricChangeMsg = RegisterWindowMessage(SH_UIMETRIC_CHANGE);
    if (message == uMetricChangeMsg)
    {
        HRESULT hr;
        LOGFONT lf;
        HDC hDC = GetDC(hwnd);
        int iFontSizePoint;
        int iFontSizePixel;
        int iFontSizePercentage;
        // Get the height of the current system font size in points. This can be used with the LOGFONT
        // structure to get the correct font height.
        hr = SHGetUIMetrics(SHUIM_FONTSIZE_POINT, &iFontSizePoint, sizeof(iFontSizePoint), NULL);
        lf.lfHeight = -MulDiv(iFontSizePoint, GetDeviceCaps(hDC, LOGPIXELSY), 72);
        // Get the height of the current system font size in pixels. This can be used with the LOGFONT
        // structure to get the correct font height.
        hr = SHGetUIMetrics(SHUIM_FONTSIZE_PIXEL, &iFontSizePixel, sizeof(iFontSizePixel), NULL);
        lf.lfHeight = -iFontSizePixel;
        // Get the height of the current system font size in percentage of the default system font size. This is
        // useful when using richedit controls, since richedit supports the EM_SETZOOM message.
        hr = SHGetUIMetrics(SHUIM_FONTSIZE_PERCENTAGE, &iFontSizePercentage, sizeof(iFontSizePercentage), NULL);
        ReleaseDC(hwnd, hDC);
    }
    return DefWindowProc(hwnd, message, wParam, lParam);
}

Requirements

Header aygshell.h
Library Aygshell.dll
Windows Embedded CE Windows CE .NET 4.2 and later
Windows Mobile Pocket PC for Windows Mobile 2003 Second Edition and later, Smartphone for Windows Mobile 2003 Second Edition and later

See Also

Reference

Shell Functions
SH_UIMETRIC_CHANGE
SHUIMETRIC