Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
4/8/2010

The SHGetUIMetricsfunction 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. shuimmust be one of the SHUIMETRICvalues.

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

SHGetUIMetricsreturns an HRESULTvalue of either S_OKor an appropriate error code.

Remarks

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

If you call SHGetUIMetricsto retrieve the system font size, shuimmust be one of the three SHUIMETRICvalues: SHUIM_FONTSIZE_POINT, or SHUIM_FONTSIZE_PIXEL, or SHUIM_FONTSIZE_PERCENTAGE. In this case, pvBufferis a pointer to DWORD, and cbBufferSizeis 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.
Copy Code
#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