OSDN Git Service

[U] 高DPIモニター対応の強化
authortnishi <sgm00353@nifty.ne.jp>
Fri, 27 Aug 2021 01:28:22 +0000 (10:28 +0900)
committertnishi <sgm00353@nifty.ne.jp>
Fri, 27 Aug 2021 01:28:22 +0000 (10:28 +0900)
DCHook64/dchk64/dchk64.cpp
DCHookTest/DCHookTest.cpp

index 8812dd7..8fe8595 100644 (file)
@@ -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();
+
        // \83O\83\8d\81[\83o\83\8b\95\8e\9a\97ñ\82ð\8f\89\8aú\89»\82µ\82Ä\82¢\82Ü\82·\81B
        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);
+}
+
index eec638c..59a035b 100644 (file)
@@ -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);
+}
+