Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
MSDN Library

SHGetUIMetrics

Send Feedback

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 Values

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 Windows Mobile 2003 software and earlier, users cannot change the system font size on Windows Mobile-based Smartphones.

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 Pocket PC
    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

Pocket PC: Windows Mobile 2003 Second Edition and later.
Smartphone: Windows Mobile 2003 Second Edition and later.
OS Versions: Windows CE .NET 4.2 and later.
Header: Aygshell.h.
Library: Aygshell.dll


Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.


Show:
© 2015 Microsoft