This Winhawk mod solves the issue for Mathematica (kind of) but it also affects other programs:
// ==WindhawkMod==
// @id setcustomdpi
// @name Set custom DPI
// @description Sets custom DPI resolution
// @version 1.0
// @author anixx
// @github https://github.com/Anixx
// @include Mathematica.exe
// ==/WindhawkMod==
// ==WindhawkModReadme==
/*
*/
// ==/WindhawkModReadme==
#include <windows.h>
#include <shellscalingapi.h>
typedef HRESULT (WINAPI *GetDpiForMonitor_t)(
HMONITOR hmonitor,
MONITOR_DPI_TYPE dpiType,
UINT *dpiX,
UINT *dpiY
);
GetDpiForMonitor_t GetDpiForMonitor_Original;
HRESULT WINAPI GetDpiForMonitor_Hook(
HMONITOR hmonitor,
MONITOR_DPI_TYPE dpiType,
UINT *dpiX,
UINT *dpiY
)
{
HRESULT res = GetDpiForMonitor_Original(hmonitor,dpiType,dpiX,dpiY);
*dpiX = 72;
*dpiY = 72;
return res;
}
BOOL Wh_ModInit(void)
{
HMODULE user32module = LoadLibrary(L"Shcore.dll");
FARPROC GetDpiForMonitor = GetProcAddress(user32module, "GetDpiForMonitor");
Wh_SetFunctionHook((void*)GetDpiForMonitor, (void*)GetDpiForMonitor_Hook, (void**)&GetDpiForMonitor_Original);
return TRUE;
}
Another side effect, it also affects the scrollbars, status bar and titlebar.
If anyone knows a better way to fix this, you are welcome. I also tried to hook function GetDpiForSystem
- Mathematica starts only with the returned DPI is 96 or 120 but not 72. I also tried GetSystemMetricsForDpi
- this affects controls size but not the text or cell separators. I also tried other functions, they make no effect.