[idd] helper/config: implement window positioning, fonts, and high DPI support

This commit is contained in:
Quantum
2025-09-15 21:34:23 -04:00
committed by Geoffrey McRae
parent e123e02e15
commit 4585362f54
6 changed files with 128 additions and 3 deletions

View File

@@ -11,28 +11,65 @@ bool CConfigWindow::registerClass()
WNDCLASSEX wx = {};
populateWindowClass(wx);
wx.hIconSm = wx.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
wx.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
wx.lpszClassName = L"LookingGlassIddConfig";
s_atom = RegisterClassEx(&wx);
return s_atom;
}
CConfigWindow::CConfigWindow()
CConfigWindow::CConfigWindow() : m_scale(1)
{
if (!CreateWindowEx(0, MAKEINTATOM(s_atom), L"Looking Glass IDD Configuration",
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, 300, 200,
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, 500, 400,
NULL, NULL, hInstance, this))
{
DEBUG_ERROR_HR(GetLastError(), "Failed to create window");
}
m_scale = GetDpiForWindow(m_hwnd) / 96.0;
m_version.reset(new CStaticWidget(L"Looking Glass IDD " LG_VERSION_STR, WS_CHILD | WS_VISIBLE | SS_CENTERIMAGE, m_hwnd));
updateFont();
}
void CConfigWindow::updateFont()
{
NONCLIENTMETRICS ncmMetrics = { sizeof(NONCLIENTMETRICS) };
UINT dpi = GetDpiForWindow(m_hwnd);
if (!SystemParametersInfoForDpi(SPI_GETNONCLIENTMETRICS, sizeof ncmMetrics, &ncmMetrics, 0, dpi))
{
DEBUG_ERROR_HR(GetLastError(), "SystemParametersInfoForDpi(SPI_GETNONCLIENTMETRICS)");
return;
}
m_font.Attach(CreateFontIndirect(&ncmMetrics.lfMessageFont));
if (!m_font.IsValid())
{
DEBUG_ERROR_HR(GetLastError(), "CreateFontIndirect(lfMessageFont)");
return;
}
for (HWND child : std::initializer_list<HWND>({ *m_version }))
SendMessage(child, WM_SETFONT, (WPARAM)m_font.Get(), 1);
}
LRESULT CConfigWindow::handleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_SIZE:
return onResize(LOWORD(lParam), HIWORD(lParam));
case WM_DPICHANGED:
{
LPRECT lpBox = (LPRECT)lParam;
m_scale = LOWORD(wParam) / 96.0;
updateFont();
SetWindowPos(m_hwnd, NULL, lpBox->left, lpBox->top, lpBox->right - lpBox->left,
lpBox->bottom - lpBox->top, SWP_NOZORDER | SWP_NOACTIVATE);
onResize(lpBox->right - lpBox->left, lpBox->bottom - lpBox->top);
RedrawWindow(m_hwnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_ALLCHILDREN);
return 0;
}
default:
return CWindow::handleMessage(uMsg, wParam, lParam);
}
@@ -49,3 +86,10 @@ LRESULT CConfigWindow::onFinal()
m_onDestroy();
return CWindow::onFinal();
}
LRESULT CConfigWindow::onResize(DWORD width, DWORD height)
{
WidgetPositioner pos(m_scale, width, height);
pos.pinTopLeftRight(*m_version, 12, 12, 12, 20);
return 0;
}