@@ -57,6 +57,7 @@ class HTCCSettingsApp {
5757 public:
5858 HTCCSettingsApp () = delete ;
5959 explicit HTCCSettingsApp (const HINSTANCE instance) {
60+ gInstance = this ;
6061 Config::LoadBaseConfig ();
6162
6263 const WNDCLASSW wc {
@@ -86,7 +87,8 @@ class HTCCSettingsApp {
8687 nullptr ));
8788 }
8889 if (!mHwnd ) {
89- throw std::runtime_error (std::format (" Failed to create window: {}" , GetLastError ()));
90+ throw std::runtime_error (
91+ std::format (" Failed to create window: {}" , GetLastError ()));
9092 }
9193 RECT clientRect {};
9294 GetClientRect (mHwnd .get (), &clientRect);
@@ -151,6 +153,7 @@ class HTCCSettingsApp {
151153 ImGui_ImplDX11_Shutdown ();
152154 ImGui_ImplWin32_Shutdown ();
153155 ImGui::DestroyContext ();
156+ gInstance = nullptr ;
154157 }
155158
156159 [[nodiscard]] HWND GetHWND () const noexcept {
@@ -159,6 +162,24 @@ class HTCCSettingsApp {
159162
160163 [[nodiscard]] int Run () noexcept {
161164 while (!mExitCode ) {
165+ if (mPendingResize ) {
166+ mRenderTargetView .reset ();
167+ const auto width = std::get<0 >(*mPendingResize );
168+ const auto height = std::get<1 >(*mPendingResize );
169+ mSwapChain ->ResizeBuffers (0 , width, height, DXGI_FORMAT_UNKNOWN, 0 );
170+ wil::com_ptr<ID3D11Texture2D> backBuffer;
171+ THROW_IF_FAILED (
172+ mSwapChain ->GetBuffer (0 , IID_PPV_ARGS (backBuffer.put ())));
173+ THROW_IF_FAILED (mD3DDevice ->CreateRenderTargetView (
174+ backBuffer.get (), nullptr , mRenderTargetView .put ()));
175+
176+ mWindowSize = {
177+ static_cast <FLOAT>(width),
178+ static_cast <FLOAT>(height),
179+ };
180+ mPendingResize = std::nullopt ;
181+ }
182+
162183 MSG msg {};
163184 while (PeekMessage (&msg, nullptr , 0 , 0 , PM_REMOVE)) {
164185 TranslateMessage (&msg);
@@ -188,6 +209,7 @@ class HTCCSettingsApp {
188209 }
189210
190211 private:
212+ static HTCCSettingsApp* gInstance ;
191213 wil::unique_hwnd mHwnd ;
192214 wil::com_ptr<IDXGISwapChain1> mSwapChain ;
193215 wil::com_ptr<ID3D11Device> mD3DDevice ;
@@ -202,6 +224,12 @@ class HTCCSettingsApp {
202224 if (ImGui_ImplWin32_WndProcHandler (hwnd, uMsg, wParam, lParam)) {
203225 return true ;
204226 }
227+ if (uMsg == WM_SIZE) {
228+ const UINT width = LOWORD (lParam);
229+ const UINT height = HIWORD (lParam);
230+ gInstance ->mPendingResize = std::tuple {width, height};
231+ return 0 ;
232+ }
205233 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
206234 }
207235
@@ -413,6 +441,8 @@ class HTCCSettingsApp {
413441 }
414442};
415443
444+ HTCCSettingsApp* HTCCSettingsApp::gInstance {nullptr };
445+
416446int WINAPI wWinMain (
417447 HINSTANCE hInstance,
418448 HINSTANCE hPrevInstance,
0 commit comments