Per-Monitor DPI Aware guidelins (C++ SDK)
Posted: 23 May 2017, 08:36
Hi,
I am trying to make my sample application to be Per-Monitor DPI Aware.
Basically I call SetLayoutTransform(new ScaleTransform(scaleX, scaleY)) of the root XAML element during initial setup and when WM_DPICHANGED is sent to the application, and it seems that Noesis correctly scale the UI and render it crisply. So far seems very good.
Is there anything else I need to be aware of ?
Or maybe there is some guidelines to follow when adapting DPI changes ?
Thanks.
I am trying to make my sample application to be Per-Monitor DPI Aware.
Basically I call SetLayoutTransform(new ScaleTransform(scaleX, scaleY)) of the root XAML element during initial setup and when WM_DPICHANGED is sent to the application, and it seems that Noesis correctly scale the UI and render it crisply. So far seems very good.
Code: Select all
// m_xamlRenderer is a wrapper around Noesis GUI
m_xamlRenderer = CXamlRenderer::Create(m_hWnd);
auto monitor = ::MonitorFromWindow(m_hWnd, MONITOR_DEFAULTTONEAREST);
auto dpiX = unsigned{};
auto dpiY = unsigned{};
GetDpiForMonitor(monitor, MDT_EFFECTIVE_DPI, &dpiX, &dpiY);
m_xamlRenderer->SetDpi(dpiX, dpiY); // see below snippet
Code: Select all
afx_msg LRESULT OnDpiChanged(WPARAM wParam, LPARAM lParam) {
auto dpiX = HIWORD(wParam);
auto dpiY = LOWORD(wParam);
m_xamlRenderer->SetDpi(dpiX, dpiY); // see below snippet
auto rect = *reinterpret_cast<RECT *>(lParam);
SetWindowPos(nullptr, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOACTIVATE | SWP_NOZORDER);
return 0;
}
Code: Select all
void CXamlRenderer::SetDpi(int dpiX, int dpiY) {
auto root = m_xaml->GetContent(); // Get root XAML element
auto scaleX = dpiX / 96.0f;
auto scaleY = dpiY / 96.0f;
root->SetLayoutTransform(new ScaleTransform(scaleX, scaleY));
}
Is there anything else I need to be aware of ?
Or maybe there is some guidelines to follow when adapting DPI changes ?
Thanks.