diff --git a/src/modules/fancyzones/lib/ZoneWindowDrawing.cpp b/src/modules/fancyzones/lib/ZoneWindowDrawing.cpp index b90186bd9b..30a8caa118 100644 --- a/src/modules/fancyzones/lib/ZoneWindowDrawing.cpp +++ b/src/modules/fancyzones/lib/ZoneWindowDrawing.cpp @@ -66,6 +66,7 @@ D2D1_RECT_F ZoneWindowDrawing::ConvertRect(RECT rect) ZoneWindowDrawing::ZoneWindowDrawing(HWND window) { + HRESULT hr; m_window = window; m_renderTarget = nullptr; m_shouldRender = false; @@ -73,23 +74,27 @@ ZoneWindowDrawing::ZoneWindowDrawing(HWND window) // Obtain the size of the drawing area. if (!GetClientRect(window, &m_clientRect)) { + // TODO: Log failures and errors using spdlog return; } // Create a Direct2D render target // We should always use the DPI value of 96 since we're running in DPI aware mode - GetD2DFactory()->CreateHwndRenderTarget( - D2D1::RenderTargetProperties( - D2D1_RENDER_TARGET_TYPE_DEFAULT, - D2D1::PixelFormat(DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_PREMULTIPLIED), - 96.f, - 96.f), - D2D1::HwndRenderTargetProperties( - window, - D2D1::SizeU( - m_clientRect.right - m_clientRect.left, - m_clientRect.bottom - m_clientRect.top)), - &m_renderTarget); + auto renderTargetProperties = D2D1::RenderTargetProperties( + D2D1_RENDER_TARGET_TYPE_DEFAULT, + D2D1::PixelFormat(DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_PREMULTIPLIED), + 96.f, + 96.f); + + auto renderTargetSize = D2D1::SizeU(m_clientRect.right - m_clientRect.left, m_clientRect.bottom - m_clientRect.top); + auto hwndRenderTargetProperties = D2D1::HwndRenderTargetProperties(window, renderTargetSize); + + hr = GetD2DFactory()->CreateHwndRenderTarget(renderTargetProperties, hwndRenderTargetProperties, &m_renderTarget); + + if (!SUCCEEDED(hr)) + { + return; + } m_renderThread = std::thread([this]() { while (!m_abortThread)