Skip to content

Commit

Permalink
Support HiDPI settings for Windows 10 v1703 and also legacy System DP…
Browse files Browse the repository at this point in the history
…I mode.

Remove pre-release tag.

git-svn-id: https://www.williamfeely.info/svn/dxgl@798 8a90861a-4eca-46d5-b744-240ff16d0c4d
  • Loading branch information
dxgldotorg committed Apr 1, 2018
1 parent c90cdc9 commit 4193ae4
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
2 changes: 1 addition & 1 deletion common/releasever.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#define DXGLMAJORVER 0
#define DXGLMINORVER 5
#define DXGLPOINTVER 13
#define DXGLBETA 1
#define DXGLBETA 0

#define STR2(x) #x
#define STR(x) STR2(x)
Expand Down
57 changes: 56 additions & 1 deletion dxglcfg/dxglcfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2446,6 +2446,48 @@ LRESULT CALLBACK PathsTabCallback(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lPa
return TRUE;
}

DWORD GetDPISupportLevel()
{
HMODULE hSHCore = NULL;
HMODULE hUser32 = NULL;
HRESULT(WINAPI *_SetProcessDpiAwareness)(DWORD value) = NULL;
BOOL(WINAPI *_SetProcessDpiAwarenessContext)(HANDLE value) = NULL;
DWORD level = 0;
// Vista or higher - supports DWM and DPI scaling
if (osver.dwMajorVersion >= 6) level = 1;
else return level;
// 8.1 or higher - Supports Per-Monitor scaling
hSHCore = LoadLibrary(_T("SHCore.dll"));
if (hSHCore)
{
_SetProcessDpiAwareness =
(HRESULT(WINAPI*)(DWORD))GetProcAddress(hSHCore, "SetProcessDpiAwareness");
if (_SetProcessDpiAwareness) level = 2;
else
{
FreeLibrary(hSHCore);
return level;
}
FreeLibrary(hSHCore);
}
else return level;
// v1703 or higher - Support Per-Monitor scaling v2
hUser32 = LoadLibrary(_T("User32.dll"));
if (hUser32)
{
_SetProcessDpiAwarenessContext =
(BOOL(WINAPI*)(HANDLE))GetProcAddress(hUser32, "SetProcessDpiAwarenessContext");
if (_SetProcessDpiAwarenessContext) level = 3;
else
{
FreeLibrary(hUser32);
return level;
}
FreeLibrary(hUser32);
}
return level;
}

LRESULT CALLBACK DXGLCfgCallback(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
PIXELFORMATDESCRIPTOR pfd =
Expand Down Expand Up @@ -2513,6 +2555,7 @@ LRESULT CALLBACK DXGLCfgCallback(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lPar
NMHDR *nm;
TCHAR abouttext[1024];
int newtab;
DWORD dpisupport;
TCITEM tab;
switch (Msg)
{
Expand Down Expand Up @@ -3018,12 +3061,24 @@ LRESULT CALLBACK DXGLCfgCallback(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lPar
if (cfg->NoResizeWindow) SendDlgItemMessage(hTabs[3], IDC_NOAUTOSIZE, BM_SETCHECK, BST_CHECKED, 0);
else SendDlgItemMessage(hTabs[3], IDC_NOAUTOSIZE, BM_SETCHECK, BST_UNCHECKED, 0);
// DPI
dpisupport = GetDPISupportLevel();
_tcscpy(buffer, _T("Disabled"));
SendDlgItemMessage(hTabs[0],IDC_DPISCALE,CB_ADDSTRING,0,(LPARAM)buffer);
_tcscpy(buffer, _T("Enabled"));
if (dpisupport >= 2) _tcscpy(buffer, _T("Per-monitor"));
else _tcscpy(buffer, _T("Enabled"));
SendDlgItemMessage(hTabs[0],IDC_DPISCALE,CB_ADDSTRING,1,(LPARAM)buffer);
_tcscpy(buffer, _T("Windows AppCompat"));
SendDlgItemMessage(hTabs[0],IDC_DPISCALE,CB_ADDSTRING,2,(LPARAM)buffer);
if (dpisupport >= 2)
{
_tcscpy(buffer, _T("System"));
SendDlgItemMessage(hTabs[0], IDC_DPISCALE, CB_ADDSTRING, 2, (LPARAM)buffer);
}
if (dpisupport >= 3)
{
_tcscpy(buffer, _T("Per-monitor V2"));
SendDlgItemMessage(hTabs[0], IDC_DPISCALE, CB_ADDSTRING, 2, (LPARAM)buffer);
}
SendDlgItemMessage(hTabs[0],IDC_DPISCALE,CB_SETCURSEL,cfg->DPIScale,0);
// Paths
EnableWindow(GetDlgItem(hTabs[3], IDC_PATHLABEL), FALSE);
Expand Down

0 comments on commit 4193ae4

Please sign in to comment.