ID2D1Factory::GetDesktopDpi method

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

Syntax


virtual void GetDesktopDpi(
  [out]  FLOAT *dpiX,
  [out]  FLOAT *dpiY
) = 0;

Parameters

dpiX [out]

Type: FLOAT*

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

dpiY [out]

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 the complete example, see the Draw Rectangle Example. 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 | Windows Store apps]

Minimum supported server

Windows Server 2008 R2, Windows Server 2008 with SP2 and Platform Update for Windows Server 2008 [desktop apps | Windows Store apps]

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]

Header

D2d1.h

Library

D2d1.lib

DLL

D2d1.dll

See also

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

 

 

Community Additions

ADD
Show:
© 2014 Microsoft