| 68 | constexpr GUID guidDevinterfaceHid = {0x4d1e55b2, 0xf16f, 0x11cf, {0x88, 0xcb, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30}}; |
| 69 | |
| 70 | void setProcessDpiAware() |
| 71 | { |
| 72 | // Try SetProcessDpiAwareness first |
| 73 | if (const HINSTANCE shCoreDll = LoadLibrary(L"Shcore.dll")) |
| 74 | { |
| 75 | enum ProcessDpiAwareness |
| 76 | { |
| 77 | ProcessDpiUnaware = 0, |
| 78 | ProcessSystemDpiAware = 1, |
| 79 | ProcessPerMonitorDpiAware = 2 |
| 80 | }; |
| 81 | |
| 82 | using SetProcessDpiAwarenessFuncType = HRESULT(WINAPI*)(ProcessDpiAwareness); |
| 83 | auto setProcessDpiAwarenessFunc = reinterpret_cast<SetProcessDpiAwarenessFuncType>( |
| 84 | reinterpret_cast<void*>(GetProcAddress(shCoreDll, "SetProcessDpiAwareness"))); |
| 85 | |
| 86 | if (setProcessDpiAwarenessFunc) |
| 87 | { |
| 88 | // We only check for E_INVALIDARG because we would get |
| 89 | // E_ACCESSDENIED if the DPI was already set previously |
| 90 | // and S_OK means the call was successful. |
| 91 | // We intentionally don't use Per Monitor V2 which can be |
| 92 | // enabled with SetProcessDpiAwarenessContext, because that |
| 93 | // would scale the title bar and thus change window size |
| 94 | // by default when moving the window between monitors. |
| 95 | if (setProcessDpiAwarenessFunc(ProcessPerMonitorDpiAware) == E_INVALIDARG) |
| 96 | { |
| 97 | sf::err() << "Failed to set process DPI awareness" << std::endl; |
| 98 | } |
| 99 | else |
| 100 | { |
| 101 | FreeLibrary(shCoreDll); |
| 102 | return; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | FreeLibrary(shCoreDll); |
| 107 | } |
| 108 | |
| 109 | // Fall back to SetProcessDPIAware if SetProcessDpiAwareness |
| 110 | // is not available on this system |
| 111 | if (const HINSTANCE user32Dll = LoadLibrary(L"user32.dll")) |
| 112 | { |
| 113 | using SetProcessDPIAwareFuncType = BOOL(WINAPI*)(); |
| 114 | auto setProcessDPIAwareFunc = reinterpret_cast<SetProcessDPIAwareFuncType>( |
| 115 | reinterpret_cast<void*>(GetProcAddress(user32Dll, "SetProcessDPIAware"))); |
| 116 | |
| 117 | if (setProcessDPIAwareFunc) |
| 118 | { |
| 119 | if (!setProcessDPIAwareFunc()) |
| 120 | sf::err() << "Failed to set process DPI awareness" << std::endl; |
| 121 | } |
| 122 | |
| 123 | FreeLibrary(user32Dll); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | // Register a RAWINPUTDEVICE representing the mouse to receive raw |