DXGL r798 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r797‎ | r798 | r799 >
Date:20:33, 1 April 2018
Author:admin
Status:new
Tags:
Comment:
Support HiDPI settings for Windows 10 v1703 and also legacy System DPI mode.
Remove pre-release tag.
Modified paths:
  • /common/releasever.h (modified) (history)
  • /dxglcfg/dxglcfg.cpp (modified) (history)

Diff [purge]

Index: common/releasever.h
@@ -5,7 +5,7 @@
66 #define DXGLMAJORVER 0
77 #define DXGLMINORVER 5
88 #define DXGLPOINTVER 13
9 -#define DXGLBETA 1
 9+#define DXGLBETA 0
1010
1111 #define STR2(x) #x
1212 #define STR(x) STR2(x)
Index: dxglcfg/dxglcfg.cpp
@@ -2446,6 +2446,48 @@
24472447 return TRUE;
24482448 }
24492449
 2450+DWORD GetDPISupportLevel()
 2451+{
 2452+ HMODULE hSHCore = NULL;
 2453+ HMODULE hUser32 = NULL;
 2454+ HRESULT(WINAPI *_SetProcessDpiAwareness)(DWORD value) = NULL;
 2455+ BOOL(WINAPI *_SetProcessDpiAwarenessContext)(HANDLE value) = NULL;
 2456+ DWORD level = 0;
 2457+ // Vista or higher - supports DWM and DPI scaling
 2458+ if (osver.dwMajorVersion >= 6) level = 1;
 2459+ else return level;
 2460+ // 8.1 or higher - Supports Per-Monitor scaling
 2461+ hSHCore = LoadLibrary(_T("SHCore.dll"));
 2462+ if (hSHCore)
 2463+ {
 2464+ _SetProcessDpiAwareness =
 2465+ (HRESULT(WINAPI*)(DWORD))GetProcAddress(hSHCore, "SetProcessDpiAwareness");
 2466+ if (_SetProcessDpiAwareness) level = 2;
 2467+ else
 2468+ {
 2469+ FreeLibrary(hSHCore);
 2470+ return level;
 2471+ }
 2472+ FreeLibrary(hSHCore);
 2473+ }
 2474+ else return level;
 2475+ // v1703 or higher - Support Per-Monitor scaling v2
 2476+ hUser32 = LoadLibrary(_T("User32.dll"));
 2477+ if (hUser32)
 2478+ {
 2479+ _SetProcessDpiAwarenessContext =
 2480+ (BOOL(WINAPI*)(HANDLE))GetProcAddress(hUser32, "SetProcessDpiAwarenessContext");
 2481+ if (_SetProcessDpiAwarenessContext) level = 3;
 2482+ else
 2483+ {
 2484+ FreeLibrary(hUser32);
 2485+ return level;
 2486+ }
 2487+ FreeLibrary(hUser32);
 2488+ }
 2489+ return level;
 2490+}
 2491+
24502492 LRESULT CALLBACK DXGLCfgCallback(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
24512493 {
24522494 PIXELFORMATDESCRIPTOR pfd =
@@ -2513,6 +2555,7 @@
25142556 NMHDR *nm;
25152557 TCHAR abouttext[1024];
25162558 int newtab;
 2559+ DWORD dpisupport;
25172560 TCITEM tab;
25182561 switch (Msg)
25192562 {
@@ -3018,12 +3061,24 @@
30193062 if (cfg->NoResizeWindow) SendDlgItemMessage(hTabs[3], IDC_NOAUTOSIZE, BM_SETCHECK, BST_CHECKED, 0);
30203063 else SendDlgItemMessage(hTabs[3], IDC_NOAUTOSIZE, BM_SETCHECK, BST_UNCHECKED, 0);
30213064 // DPI
 3065+ dpisupport = GetDPISupportLevel();
30223066 _tcscpy(buffer, _T("Disabled"));
30233067 SendDlgItemMessage(hTabs[0],IDC_DPISCALE,CB_ADDSTRING,0,(LPARAM)buffer);
3024 - _tcscpy(buffer, _T("Enabled"));
 3068+ if (dpisupport >= 2) _tcscpy(buffer, _T("Per-monitor"));
 3069+ else _tcscpy(buffer, _T("Enabled"));
30253070 SendDlgItemMessage(hTabs[0],IDC_DPISCALE,CB_ADDSTRING,1,(LPARAM)buffer);
30263071 _tcscpy(buffer, _T("Windows AppCompat"));
30273072 SendDlgItemMessage(hTabs[0],IDC_DPISCALE,CB_ADDSTRING,2,(LPARAM)buffer);
 3073+ if (dpisupport >= 2)
 3074+ {
 3075+ _tcscpy(buffer, _T("System"));
 3076+ SendDlgItemMessage(hTabs[0], IDC_DPISCALE, CB_ADDSTRING, 2, (LPARAM)buffer);
 3077+ }
 3078+ if (dpisupport >= 3)
 3079+ {
 3080+ _tcscpy(buffer, _T("Per-monitor V2"));
 3081+ SendDlgItemMessage(hTabs[0], IDC_DPISCALE, CB_ADDSTRING, 2, (LPARAM)buffer);
 3082+ }
30283083 SendDlgItemMessage(hTabs[0],IDC_DPISCALE,CB_SETCURSEL,cfg->DPIScale,0);
30293084 // Paths
30303085 EnableWindow(GetDlgItem(hTabs[3], IDC_PATHLABEL), FALSE);