From 732ffbdb4ea0caeaf438f23a4612f597982de0b2 Mon Sep 17 00:00:00 2001 From: tnishi Date: Fri, 27 Aug 2021 10:28:22 +0900 Subject: [PATCH] =?utf8?q?[U]=20=E9=AB=98DPI=E3=83=A2=E3=83=8B=E3=82=BF?= =?utf8?q?=E3=83=BC=E5=AF=BE=E5=BF=9C=E3=81=AE=E5=BC=B7=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- DCHook64/dchk64/dchk64.cpp | 21 +++++++++++++++++++++ DCHookTest/DCHookTest.cpp | 20 ++++++++++++++++++++ 2 files changed, 41 insertions(+) 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); +} + -- 2.11.0