| 28 | Win10 gWin10 = { 0 }; |
| 29 | |
| 30 | void win10_init(void) |
| 31 | { |
| 32 | if (IsWindows10OrGreater()) |
| 33 | { |
| 34 | HINSTANCE hUser32 = LoadLibraryA("user32.dll"); |
| 35 | |
| 36 | if (hUser32 == NULL) |
| 37 | panic("Unable to load user32.dll"); |
| 38 | |
| 39 | gWin10.SetThreadDpiAwarenessContext = (SetThreadDpiAwarenessContextProc) GetProcAddress(hUser32, "SetThreadDpiAwarenessContext"); |
| 40 | if (gWin10.SetThreadDpiAwarenessContext == NULL) |
| 41 | panic("Unable to get address of SetThreadDpiAwarenessContext()"); |
| 42 | |
| 43 | gWin10.GetThreadDpiAwarenessContext = (GetThreadDpiAwarenessContextProc) GetProcAddress(hUser32, "GetThreadDpiAwarenessContext"); |
| 44 | if (gWin10.GetThreadDpiAwarenessContext == NULL) |
| 45 | panic("Unable to get address of GetThreadDpiAwarenessContext()"); |
| 46 | |
| 47 | gWin10.AreDpiAwarenessContextsEqual = (AreDpiAwarenessContextsEqualProc) GetProcAddress(hUser32, "AreDpiAwarenessContextsEqual"); |
| 48 | if (gWin10.AreDpiAwarenessContextsEqual == NULL) |
| 49 | panic("Unable to get address of AreDpiAwarenessContextsEqual"); |
| 50 | |
| 51 | gWin10.GetDpiForWindow = (GetDpiForWindowProc) GetProcAddress(hUser32, "GetDpiForWindow"); |
| 52 | if (gWin10.GetDpiForWindow == NULL) |
| 53 | panic("Unable to get address of GetDpiForWindow"); |
| 54 | |
| 55 | FreeLibrary(hUser32); |
| 56 | |
| 57 | HINSTANCE hKernel32 = LoadLibraryA("kernel32.dll"); |
| 58 | |
| 59 | if (hKernel32 == NULL) |
| 60 | panic("Unable to load kernel32.dll"); |
| 61 | |
| 62 | gWin10.GetCurrentPackageFullName = (GetCurrentPackageFullNameProc) GetProcAddress(hKernel32, "GetCurrentPackageFullName"); |
| 63 | if (gWin10.GetCurrentPackageFullName == NULL) |
| 64 | panic("Unable to get address of GetCurrentPackageFullName"); |
| 65 | |
| 66 | FreeLibrary(hKernel32); |
| 67 | |
| 68 | gWin10.Valid = TRUE; |
| 69 | } |
| 70 | |
| 71 | if (gWin10.Valid) { |
| 72 | if (!gWin10.SetThreadDpiAwarenessContext( |
| 73 | DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2)) |
| 74 | panic("Unable to set DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2"); |
| 75 | |
| 76 | if (!gWin10.AreDpiAwarenessContextsEqual( |
| 77 | gWin10.GetThreadDpiAwarenessContext(), |
| 78 | DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2)) |
| 79 | panic("Unexpected DpiAwareness state"); |
| 80 | } |
| 81 | |
| 82 | } |
| 83 | |
| 84 | int win10_monitor_dpi(HWND hWnd) |
| 85 | { |