diff options
-rw-r--r-- | c/common.c | 18 | ||||
-rw-r--r-- | c/datalistview.c | 4 | ||||
-rw-r--r-- | c/defs.h | 1 | ||||
-rw-r--r-- | c/episodelistview.c | 9 | ||||
-rw-r--r-- | c/listview.c | 2 | ||||
-rw-r--r-- | c/main.c | 18 |
6 files changed, 46 insertions, 6 deletions
@@ -4,6 +4,24 @@ #include "resource.h" #include "defs.h" +/* Scale integer according to DPI. */ +int Dpi(int i) +{ + extern int IDPI; + + if (IDPI == -1) { + HMODULE hModule; + FARPROC GetDpiForWindow; + extern HWND HWnd; + IDPI = 96; + hModule = LoadLibrary(TEXT("User32.dll")); + if (hModule && (GetDpiForWindow = GetProcAddress(hModule, "GetDpiForWindow"))) + IDPI = GetDpiForWindow(HWnd); + } + + return MulDiv(i, IDPI, 96); +} + /* Convert normal string to TSTR using given codepage. */ TCHAR * TszFromSz(const char *sz, int iCp) diff --git a/c/datalistview.c b/c/datalistview.c index 901f16f..637350d 100644 --- a/c/datalistview.c +++ b/c/datalistview.c @@ -1,3 +1,4 @@ +#include <stdio.h> #include <windows.h> #include <commctrl.h> #include <SWI-Prolog.h> @@ -17,7 +18,8 @@ DlvCreate() lvc.mask = LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM; lvc.iSubItem = 0; lvc.pszText = TEXT("Key"); - lvc.cx = 42; + + lvc.cx = Dpi(42); ListView_InsertColumn(HDlv, 0, &lvc); lvc.iSubItem = 1; @@ -5,6 +5,7 @@ #include <commctrl.h> /* common.c */ +int Dpi(int); TCHAR *TszFromSz(const char *, int); int Watched(int); diff --git a/c/episodelistview.c b/c/episodelistview.c index 95f234a..76c99d9 100644 --- a/c/episodelistview.c +++ b/c/episodelistview.c @@ -23,7 +23,7 @@ ElvCreate() lvc.mask = LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM; lvc.iSubItem = 0; lvc.pszText = TEXT("#"); - lvc.cx = 42; + lvc.cx = Dpi(42); ListView_InsertColumn(HElv, 0, &lvc); lvc.iSubItem = 1; @@ -117,10 +117,13 @@ ElvSelectRecent() term_t t; t = T(1); - P("track_episodes","most_recently_watched",1,t) return; + P("track_episodes","most_recently_watched",1,t) { + iEpisode = 1; + goto sel; + } GI(t,&iEpisode) return; - lvfi.flags = LVFI_PARAM; +sel: lvfi.flags = LVFI_PARAM; lvfi.lParam = iEpisode; iItem = ListView_FindItem(HElv, -1, &lvfi); diff --git a/c/listview.c b/c/listview.c index ce81adf..628ed13 100644 --- a/c/listview.c +++ b/c/listview.c @@ -74,7 +74,7 @@ LvHeight(HWND hLv) { int iCount; iCount = ListView_GetItemCount(hLv); - return iCount? 27+iCount*19: 0; + return iCount? Dpi(27)+iCount*Dpi(19): 0; } /* Enable/disable non-classic list view theme. */ @@ -11,6 +11,7 @@ HFONT HfBold; HMENU HPopupMenu; HWND HFocus; HWND HWnd; +int IDPI = -1; static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); static INT_PTR CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM); static int Attach(void); @@ -60,6 +61,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, tszErr = TEXT("Could not register window class."); if (!RegisterClassEx(&wc)) goto f; + /* Create window. */ hWnd = CreateWindowEx( @@ -67,11 +69,12 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, TEXT("Episode Browser"), TEXT("Episode Browser"), WS_OVERLAPPEDWINDOW, - CW_USEDEFAULT, CW_USEDEFAULT, 510, 400, + CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL, hInstance, NULL ); tszErr = TEXT("Could not create main window."); if (!hWnd) goto f; + SetWindowPos(hWnd, NULL, -1, -1, Dpi(510), Dpi(400), SWP_NOMOVE); SetupFonts(); ShowWindow(hWnd, nCmdShow); @@ -121,6 +124,19 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_THEMECHANGED: UpdateTheme(); break; + case 0x02E0: /* WM_DPICHANGED */ + { + LPRECT lpr; + lpr = (LPRECT)lParam; + IDPI = HIWORD(wParam); + SetWindowPos(hWnd, NULL, + lpr->left, lpr->top, + lpr->right-lpr->left, + lpr->bottom-lpr->top, + SWP_NOZORDER | SWP_NOACTIVATE); + UpdateLayout(); + break; + } case WM_ACTIVATE: switch (wParam) { case WA_INACTIVE: |