How do you scale the title bar on a DPI aware win application?

前端 未结 4 1619
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-28 08:20

I am making my app dpi-aware per monitor by setting True/PM in the manifest file. I can verify with process explorer that this

4条回答
  •  长发绾君心
    2020-12-28 08:37

    The Windows 10 Anniversary Update (v1607) has added a new API you must call to enable DPI scaling of the non-client areas: EnableNonClientDpiScaling. This function should be called, when WM_NCCREATE is received. The message is sent to the window's procedure callback during window creation.

    Example:

    case WM_NCCREATE:
    {
        if (!EnableNonClientDpiScaling(hWnd))
        {
            // Error handling
            return FALSE;
        }
    
        return DefWindowProcW(...);
    }
    

    If the application's DPI-awareness context is DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2, then calling EnableNonClientDpiScaling should be omitted, as it won't have any effect, although the function will still return successfully.

    From the documentation:

    Non-client scaling for top-level windows is not enabled by default. You must call this API to enable it for each individual top-level window for which you wish to have the non-client area scale automatically. Once you do, there is no way to disable it. Enabling non-client scaling means that all the areas drawn by the system for the window will automatically scale in response to DPI changes on the window. That includes areas like the caption bar, the scrollbars, and the menu bar. You want to call EnableNonClientDpiScaling when you want the operating system to be responsible for rendering these areas automatically at the correct size based on the API of the monitor.

    See this blog post for additional information about DPI scaling changes in Windows 10 AU.

提交回复
热议问题