[PATCH] regedit: Scale UI according to screen DPI.

Mark Harmstone mark at harmstone.com
Fri Apr 2 11:31:01 CDT 2021


Regedit chooses UI sizes that aren't appropriate for high-DPI monitors;
scale them to compensate.

Signed-off-by: Mark Harmstone <mark at harmstone.com>
---
 programs/regedit/childwnd.c | 12 +++++++++++-
 programs/regedit/listview.c |  9 ++++++---
 programs/regedit/main.h     |  1 +
 3 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/programs/regedit/childwnd.c b/programs/regedit/childwnd.c
index 582f3c0c177..d1d2dd6e47e 100644
--- a/programs/regedit/childwnd.c
+++ b/programs/regedit/childwnd.c
@@ -430,6 +430,16 @@ static int listview_notify(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam
     return 0;
 }
 
+int get_dpi(void)
+{
+    HDC dc = GetDC(NULL);
+    int dpi = GetDeviceCaps(dc, LOGPIXELSX);
+
+    ReleaseDC(NULL, dc);
+
+    return dpi == 0 ? 96 : dpi;
+}
+
 #define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
 #define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
 
@@ -451,7 +461,7 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa
         g_pChildWnd = heap_xalloc(sizeof(ChildWnd));
         if (!g_pChildWnd) return 0;
         LoadStringW(hInst, IDS_REGISTRY_ROOT_NAME, g_pChildWnd->szPath, MAX_PATH);
-        g_pChildWnd->nSplitPos = 250;
+        g_pChildWnd->nSplitPos = 250 * (float)get_dpi() / 96.0f;
         g_pChildWnd->hWnd = hWnd;
         g_pChildWnd->hTreeWnd = CreateTreeView(hWnd, g_pChildWnd->szPath, TREE_WINDOW);
         g_pChildWnd->hListWnd = CreateListView(hWnd, LIST_WINDOW/*, g_pChildWnd->szPath*/);
diff --git a/programs/regedit/listview.c b/programs/regedit/listview.c
index 0132cfb8db8..7e27e3d0931 100644
--- a/programs/regedit/listview.c
+++ b/programs/regedit/listview.c
@@ -222,15 +222,18 @@ static BOOL CreateListColumns(HWND hWndListView)
     WCHAR szText[50];
     int index;
     LVCOLUMNW lvC;
+    float dpi_multiplier;
 
     /* Create columns. */
     lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
     lvC.pszText = szText;
 
+    dpi_multiplier = (float)get_dpi() / 96.0f;
+
     /* Load the column labels from the resource file. */
     for (index = 0; index < MAX_LIST_COLUMNS; index++) {
         lvC.iSubItem = index;
-        lvC.cx = default_column_widths[index];
+        lvC.cx = default_column_widths[index] * dpi_multiplier;
         lvC.fmt = column_alignment[index];
         LoadStringW(hInst, IDS_LIST_COLUMN_FIRST + index, szText, ARRAY_SIZE(szText));
         if (ListView_InsertColumnW(hWndListView, index, &lvC) == -1) return FALSE;
diff --git a/programs/regedit/main.h b/programs/regedit/main.h
index ae034405646..e3119ac7d54 100644
--- a/programs/regedit/main.h
+++ b/programs/regedit/main.h
@@ -121,6 +121,7 @@ void ShowAboutBox(HWND hWnd);
 /* childwnd.c */
 LPWSTR GetItemFullPath(HWND hwndTV, HTREEITEM hItem, BOOL bFull);
 LRESULT CALLBACK ChildWndProc(HWND, UINT, WPARAM, LPARAM);
+int get_dpi(void);
 
 /* edit.c */
 BOOL CreateKey(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPWSTR newKeyName);
-- 
2.26.3




More information about the wine-devel mailing list