ID2D1Factory::GetDesktopDpi method

Retrieves the current desktop dots per inch (DPI). To refresh this value, call ReloadSystemMetrics.

Syntax

void GetDesktopDpi(
  FLOAT *dpiX,
  FLOAT *dpiY
);

Parameters

dpiX

Type: FLOAT*

When this method returns, contains the horizontal DPI of the desktop. You must allocate storage for this parameter.

dpiY

Type: FLOAT*

When this method returns, contains the vertical DPI of the desktop. You must allocate storage for this parameter.

Return Value

This method does not return a value.

Remarks

Use this method to obtain the system DPI when setting physical pixel values, such as when you specify the size of a window.

Examples

The following code uses the GetDesktopDpi method to obtain the system DPI and set the initial size of a window.


        // Because the CreateWindow function takes its size in pixels,
        // obtain the system DPI and use it to scale the window size.
        FLOAT dpiX, dpiY;

        // The factory returns the current system DPI. This is also the value it will use
        // to create its own windows.
        m_pDirect2dFactory->GetDesktopDpi(&dpiX, &dpiY);


        // Create the window.
        m_hwnd = CreateWindow(
            L"D2DDemoApp",
            L"Direct2D Demo App",
            WS_OVERLAPPEDWINDOW,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            static_cast<UINT>(ceil(640.f * dpiX / 96.f)),
            static_cast<UINT>(ceil(480.f * dpiY / 96.f)),
            NULL,
            NULL,
            HINST_THISCOMPONENT,
            this
            );

For more information about enabling high-DPI scenarios, see How to Ensure that Your Application Displays Properly on High-DPI Displays.

Requirements

   
Minimum supported client Windows 7, Windows Vista with SP2 and Platform Update for Windows Vista [desktop apps | UWP apps]
Minimum supported server Windows Server 2008 R2, Windows Server 2008 with SP2 and Platform Update for Windows Server 2008 [desktop apps | UWP apps]
Target Platform Windows
Header d2d1.h
Library D2d1.lib
DLL D2d1.dll

See Also

How to Ensure that Your Application Displays Properly on High-DPI Displays

ID2D1Factory