use a modern font (win32)

Wed, 08 Oct 2025 15:54:33 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 08 Oct 2025 15:54:33 +0200
changeset 817
d09817e6e6a4
parent 816
f5690594b240
child 818
8185cd761897

use a modern font (win32)

ui/win32/button.c file | annotate | diff | comparison | revisions
ui/win32/toolkit.c file | annotate | diff | comparison | revisions
ui/win32/toolkit.h file | annotate | diff | comparison | revisions
--- a/ui/win32/button.c	Wed Oct 08 15:42:23 2025 +0200
+++ b/ui/win32/button.c	Wed Oct 08 15:54:33 2025 +0200
@@ -51,6 +51,7 @@
             (HMENU)0,
             hInstance,
             NULL);
+    ui_win32_set_ui_font(hwnd);
 
     W32Widget *widget = w32_widget_create(&button_widget_class, hwnd, sizeof(UiButton));
     ui_container_add(container, widget, &layout);
--- a/ui/win32/toolkit.c	Wed Oct 08 15:42:23 2025 +0200
+++ b/ui/win32/toolkit.c	Wed Oct 08 15:54:33 2025 +0200
@@ -52,6 +52,8 @@
 static ui_callback   exit_func;
 void                 *exit_data;
 
+static HFONT ui_font = NULL;
+
 void ui_init(const char *appname, int argc, char **argv) {
     application_name = appname;
 
@@ -66,6 +68,20 @@
     InitCommonControlsEx(&icex);
 
     SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
+
+    NONCLIENTMETRICS ncm = { sizeof(ncm) };
+    SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, FALSE);
+    ui_font = CreateFontIndirect(&ncm.lfMessageFont);
+}
+
+HFONT ui_win32_get_font(void) {
+    return ui_font;
+}
+
+void ui_win32_set_ui_font(HWND control) {
+    if (ui_font) {
+        SendMessage(control, WM_SETFONT, (WPARAM)ui_font, TRUE);
+    }
 }
 
 const char* ui_appname() {
--- a/ui/win32/toolkit.h	Wed Oct 08 15:42:23 2025 +0200
+++ b/ui/win32/toolkit.h	Wed Oct 08 15:54:33 2025 +0200
@@ -40,6 +40,8 @@
 extern "C" {
 #endif
 
+HFONT ui_win32_get_font(void);
+void ui_win32_set_ui_font(HWND control);
 
 
 #ifdef	__cplusplus

mercurial