From: tnishi Date: Fri, 27 Aug 2021 01:28:22 +0000 (+0900) Subject: [U] 高DPIモニター対応の強化 X-Git-Url: http://git.osdn.net/view?p=dokopop%2Fdokopop.git;a=commitdiff_plain;h=732ffbdb4ea0caeaf438f23a4612f597982de0b2 [U] 高DPIモニター対応の強化 --- diff --git a/DCHook64/dchk64/dchk64.cpp b/DCHook64/dchk64/dchk64.cpp index 8812dd7..8fe8595 100644 --- a/DCHook64/dchk64/dchk64.cpp +++ b/DCHook64/dchk64/dchk64.cpp @@ -35,6 +35,7 @@ void Cleanup(); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); int atox( const TCHAR *str, TCHAR **next ); +void SetDpiAware(); int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, @@ -47,6 +48,8 @@ int APIENTRY _tWinMain(HINSTANCE hInstance, MSG msg; HACCEL hAccelTable; + SetDpiAware(); + // ƒOƒ[ƒoƒ‹•¶Žš—ñ‚ð‰Šú‰»‚µ‚Ä‚¢‚Ü‚·B LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_DCHK64, szWindowClass, MAX_LOADSTRING); @@ -334,3 +337,21 @@ HANDLE WinExecEx( const char *cmd, int show, const char *dir, const char *title return NULL; return pi.hProcess; } + +typedef WINUSERAPI BOOL (WINAPI *FNSetProcessDpiAwarenessContext)(UINT_PTR vaule); +#define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 ((UINT_PTR)-4) +void SetDpiAware() +{ + HINSTANCE hDll = LoadLibrary( _T("user32") ); + if (!hDll) + return; + FNSetProcessDpiAwarenessContext fnSetProcessDpiAwarenessContext = (FNSetProcessDpiAwarenessContext)GetProcAddress(hDll, "SetProcessDpiAwarenessContext"); + if (fnSetProcessDpiAwarenessContext){ + if (fnSetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2)){ + } else { + DBW("x64-SetDpiAware failed: %d", GetLastError()); + } + } + FreeLibrary(hDll); +} + diff --git a/DCHookTest/DCHookTest.cpp b/DCHookTest/DCHookTest.cpp index eec638c..59a035b 100644 --- a/DCHookTest/DCHookTest.cpp +++ b/DCHookTest/DCHookTest.cpp @@ -23,8 +23,11 @@ USEUNIT("MonitorScale.cpp"); #include "DCHookMain.h" //--------------------------------------------------------------------------- +void SetDpiAware(); + WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { + SetDpiAware(); #if __PROTO SYSTEMTIME st; GetSystemTime(&st); @@ -65,4 +68,21 @@ WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) } //--------------------------------------------------------------------------- +typedef WINUSERAPI BOOL (WINAPI *FNSetProcessDpiAwarenessContext)(UINT_PTR vaule); +#define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 ((UINT_PTR)-4) +void SetDpiAware() +{ + HINSTANCE hDll = LoadLibrary( _T("user32") ); + if (!hDll) + return; + FNSetProcessDpiAwarenessContext fnSetProcessDpiAwarenessContext = (FNSetProcessDpiAwarenessContext)GetProcAddress(hDll, "SetProcessDpiAwarenessContext"); + if (fnSetProcessDpiAwarenessContext){ + if (fnSetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2)){ + } else { + DBW("SetDpiAware failed: %d", GetLastError()); + } + } + FreeLibrary(hDll); +} +