diff --git a/GlosSITarget/GlosSITarget.vcxproj b/GlosSITarget/GlosSITarget.vcxproj index ff5cb3a..110915a 100644 --- a/GlosSITarget/GlosSITarget.vcxproj +++ b/GlosSITarget/GlosSITarget.vcxproj @@ -131,6 +131,9 @@ true hid.lib;Cfgmgr32.lib;opengl32.lib;sfml-window-d.lib;sfml-system-d.lib;sfml-graphics-d.lib;dwmapi.lib;xinput9_1_0.lib;setupapi.lib;ViGEmClient.lib;%(AdditionalDependencies) + + PerMonitorHighDPIAware + @@ -149,6 +152,9 @@ true hid.lib;Cfgmgr32.lib;opengl32.lib;xinput9_1_0.lib;setupapi.lib;ViGEmClient.lib;%(AdditionalDependencies) + + PerMonitorHighDPIAware + diff --git a/GlosSITarget/TargetWindow.cpp b/GlosSITarget/TargetWindow.cpp index 075d21d..fceaf20 100644 --- a/GlosSITarget/TargetWindow.cpp +++ b/GlosSITarget/TargetWindow.cpp @@ -24,23 +24,44 @@ limitations under the License. #ifdef _WIN32 #include +#include #include #include + +#if !defined(WM_DPICHANGED) +#define WM_DPICHANGED 0x02E0 #endif +#endif TargetWindow::TargetWindow(std::function on_close, std::vector screenshot_hotkey) : on_close_(std::move(on_close)), - screenshot_keys_(std::move(screenshot_hotkey)), + screenshot_keys_(std::move(screenshot_hotkey)), overlay_(window_, [this]() { close(); }) { - - window_.create(sf::VideoMode::getDesktopMode(), "GlosSITarget", sf::Style::None); + auto desktop_mode = sf::VideoMode::getDesktopMode(); +#ifdef _WIN32 + // For some completely odd reason, the Background becomes black when enabled dpi-awareness and making the window desktop-size. + // Scaling down by 1px each direction is barely noticeable and works. + window_.create(sf::VideoMode(desktop_mode.width - 1, desktop_mode.height - 1, 32), "GlosSITarget", sf::Style::None); + //window_.create(sf::VideoMode(1920, 1080, 24), "GlosSITarget"); +#else + window_.create(desktop_mode, "GlosSITarget", sf::Style::None); +#endif window_.setActive(true); #ifdef _WIN32 HWND hwnd = window_.getSystemHandle(); + auto dpi = GetWindowDPI(hwnd); + spdlog::debug("Screen DPI: {}", dpi); // transparent windows window... + auto style = GetWindowLong(hwnd, GWL_STYLE); + style &= ~WS_OVERLAPPED; + style |= WS_POPUP; + SetWindowLong(hwnd, GWL_STYLE, style); + + DWM_BLURBEHIND bb{.dwFlags = DWM_BB_ENABLE, .fEnable = true, .hRgnBlur = nullptr}; + DwmEnableBlurBehindWindow(hwnd, &bb); MARGINS margins; margins.cxLeftWidth = -1; DwmExtendFrameIntoClientArea(hwnd, &margins); @@ -53,9 +74,15 @@ TargetWindow::TargetWindow(std::function on_close, std::vector(GetProcAddress(hShcore, "GetDpiForMonitor")); + if (pGetDpiForMonitor) { + HMONITOR hMonitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTOPRIMARY); + UINT uiDpiX; + UINT uiDpiY; + HRESULT hr = pGetDpiForMonitor(hMonitor, 0, &uiDpiX, &uiDpiY); + if (SUCCEEDED(hr)) { + return static_cast(uiDpiX); + } + } + } + + // We couldn't get the window's DPI above, so get the DPI of the primary monitor + // using an API that is available in all Windows versions. + HDC hScreenDC = GetDC(0); + int iDpiX = GetDeviceCaps(hScreenDC, LOGPIXELSX); + ReleaseDC(0, hScreenDC); + + return static_cast(iDpiX); +} + +#endif diff --git a/GlosSITarget/TargetWindow.h b/GlosSITarget/TargetWindow.h index 03301c0..ee2397f 100644 --- a/GlosSITarget/TargetWindow.h +++ b/GlosSITarget/TargetWindow.h @@ -55,6 +55,10 @@ class TargetWindow { WindowHandle getSystemHandle() const; +#ifdef _WIN32 + static WORD GetWindowDPI(HWND hWnd); +#endif + private: const std::function on_close_; sf::RenderWindow window_;