fixed Windows HiDPI support (#184)

This commit is contained in:
Andrew 2016-09-03 13:52:20 -07:00
parent 86c4485578
commit b9f52ef416
2 changed files with 10 additions and 1 deletions

View File

@ -61,7 +61,9 @@ static BOOL onWM_NOTIFY(uiControl *c, HWND hwnd, NMHDR *nmhdr, LRESULT *lResult)
ID2D1SolidColorBrush *brush;
uiWindowsSizing sizing;
int x, y;
float dpi_x, dpi_y;
HRESULT hr;
D2D1_MATRIX_3X2_F dm;
if (nmhdr->code != NM_CUSTOMDRAW)
return FALSE;
@ -73,6 +75,13 @@ static BOOL onWM_NOTIFY(uiControl *c, HWND hwnd, NMHDR *nmhdr, LRESULT *lResult)
rt = makeHDCRenderTarget(nm->hdc, &client);
rt->BeginDraw();
// scale Direct2D's rendering to be in pixels instead of DIPs
rt->GetDpi(&dpi_x, &dpi_y);
ZeroMemory(&dm, sizeof (D2D1_MATRIX_3X2_F));
dm._11 = 96.f/dpi_x;
dm._22 = 96.f/dpi_y;
rt->SetTransform(&dm);
uiWindowsGetSizing(b->hwnd, &sizing);
x = 3; // should be enough
y = 3;

View File

@ -70,7 +70,7 @@ const char *uiInit(uiInitOptions *o)
if ((si.dwFlags & STARTF_USESHOWWINDOW) != 0)
nCmdShow = si.wShowWindow;
// LONGTERM set DPI awareness
SetProcessDPIAware();
hDefaultIcon = LoadIconW(NULL, IDI_APPLICATION);
if (hDefaultIcon == NULL)