@@ -70,28 +70,27 @@ void LimitFPS(int fpsLimit) {
7070
7171void Overlay::OverlayLoop () noexcept {
7272 // Create application window
73- WNDCLASSEXW wc = { sizeof (wc), CS_CLASSDC, WndProc, 0L , 0L , GetModuleHandleW (nullptr ), nullptr , nullptr , nullptr , nullptr , L" GDI+ Hook Window Class" , nullptr };
74- ::RegisterClassExW (&wc);
75- window_handle = ::CreateWindowW (wc.lpszClassName , L" GDI+ Window (Lightshot.exe)" , WS_POPUP, 0 , 0 , globals::width, globals::height, nullptr , nullptr , wc.hInstance , nullptr );
73+ WNDCLASSEXW wc = { sizeof (wc), CS_CLASSDC, WndProc, 0L , 0L , GetModuleHandle (nullptr ), nullptr , nullptr , nullptr , nullptr , L" GDI+ Hook Window Class" , nullptr };
74+ ::RegisterClassEx (&wc);
75+ window_handle = ::CreateWindow (wc.lpszClassName , L" GDI+ Window (Lightshot.exe)" , WS_POPUP, 0 , 0 , globals::width, globals::height, nullptr , nullptr , wc.hInstance , nullptr );
76+
77+ SetWindowLongPtr (window_handle, GWL_EXSTYLE, WS_EX_TOPMOST | WS_EX_TRANSPARENT | WS_EX_LAYERED | WS_EX_TOOLWINDOW);
78+ SetLayeredWindowAttributes (window_handle, 0 , 255 , LWA_ALPHA);
79+ MARGINS margins = { -1 , -1 , -1 , -1 };
80+ DwmExtendFrameIntoClientArea (window_handle, &margins);
7681
7782 // Initialize Direct3D
7883 if (!CreateDeviceD3D ()) {
7984 CleanupDeviceD3D ();
80- ::UnregisterClassW (wc.lpszClassName, wc.hInstance);
85+ ::UnregisterClass (wc.lpszClassName, wc.hInstance);
8186 globals::finish = true ;
8287 return ;
8388 }
8489
85- // Show the window
86- ::ShowWindow (window_handle, SW_SHOW );
90+ // ::ShowWindow(window_handle, SW_SHOW);
91+ SetWindowPos (window_handle, HWND_TOPMOST, globals::posX, globals::posY, globals::width, globals::height, SWP_SHOWWINDOW | SWP_NOACTIVATE );
8792 ::UpdateWindow (window_handle);
8893
89- MARGINS margins = { -1 , -1 , -1 , -1 };
90- DwmExtendFrameIntoClientArea (window_handle, &margins);
91- SetWindowLongPtrW (window_handle, GWL_EXSTYLE, WS_EX_TOPMOST | WS_EX_TRANSPARENT | WS_EX_LAYERED | WS_EX_TOOLWINDOW);
92- SetLayeredWindowAttributes (window_handle, 0 , 255 , LWA_ALPHA);
93- // SetWindowPos(window_handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
94-
9594 // Setup Dear ImGui context
9695 IMGUI_CHECKVERSION ();
9796 ImGui::CreateContext ();
@@ -124,9 +123,22 @@ void Overlay::OverlayLoop() noexcept {
124123 };
125124
126125 menu_font = io.Fonts ->AddFontFromFileTTF (" C:/Windows/Fonts/arial.ttf" , 16 .f , nullptr , small_range);
126+ if (menu_font == nullptr ) {
127+ Logger::logWarning (" Failed to load font arial.ttf, falling back to default font" );
128+ menu_font = io.Fonts ->AddFontDefault ();
129+ }
130+
127131 arial_font = io.Fonts ->AddFontFromFileTTF (" C:/Windows/Fonts/arial.ttf" , 32 .f , nullptr , full_range);
132+ if (arial_font == nullptr ) {
133+ Logger::logWarning (" Failed to load font arial.ttf, falling back to default font" );
134+ arial_font = io.Fonts ->AddFontDefault ();
135+ }
136+
128137 bold_font = io.Fonts ->AddFontFromFileTTF (" C:/Windows/Fonts/ariblk.ttf" , 32 .f , nullptr , small_range);
129- // weapon_font = io.Fonts->AddFontFromMemoryTTF(&shell_weapon_font, sizeof(shell_weapon_font), 32.f);
138+ if (bold_font == nullptr ) {
139+ Logger::logWarning (" Failed to load font ariblk.ttf, falling back to default font" );
140+ bold_font = io.Fonts ->AddFontDefault ();
141+ }
130142
131143 // Setup Dear ImGui style
132144 ImGui::StyleColorsDark ();
@@ -138,14 +150,17 @@ void Overlay::OverlayLoop() noexcept {
138150 ErScripts::GetWindowInfo (globals::width, globals::height, globals::posX, globals::posY);
139151
140152 CleanupRenderTarget ();
141- SetWindowPos (window_handle, (HWND)-1 , globals::posX, globals::posY, globals::width, globals::height, 0 );
142153 g_pSwapChain->ResizeBuffers (0 , globals::width, globals::height, DXGI_FORMAT_UNKNOWN, 0 );
143154 CreateRenderTarget ();
144155
145156 std::thread (&Overlay::Handler, this ).detach ();
146157
147158 const float clear_color[4 ]{ 0 };
148- // UINT prevWidth = globals::width, prevHeight = globals::height;
159+
160+ // Disable navigation keys (Ctrtl + Tab)
161+ ImGuiContext& g = *GImGui;
162+ g.ConfigNavWindowingKeyNext = 0 ;
163+ g.ConfigNavWindowingKeyPrev = 0 ;
149164
150165 // Main loop
151166 while (!globals::finish) {
@@ -172,17 +187,6 @@ void Overlay::OverlayLoop() noexcept {
172187 }
173188 g_SwapChainOccluded = false ;
174189
175- /* if (prevWidth != globals::width || prevHeight != globals::height) {
176- CleanupRenderTarget();
177- SetWindowPos(window_handle, HWND_TOPMOST, 0, 0, globals::width, globals::height, SWP_NOMOVE | SWP_NOSIZE);
178- g_pSwapChain->ResizeBuffers(0, globals::width, globals::height, DXGI_FORMAT_UNKNOWN, 0);
179-
180- prevWidth = globals::width;
181- prevHeight = globals::height;
182-
183- CreateRenderTarget();
184- }*/
185-
186190 // Start the Dear ImGui frame
187191 ImGui_ImplDX11_NewFrame ();
188192 ImGui_ImplWin32_NewFrame ();
@@ -197,18 +201,6 @@ void Overlay::OverlayLoop() noexcept {
197201 if (ErScripts::GetWindowState ()) {
198202 Overlay::Render ();
199203
200- /* static bool prevMenuState = false;
201- if (globals::menuState != prevMenuState) {
202- prevMenuState = globals::menuState;
203-
204- if (globals::menuState) {
205- SetWindowLongPtrW(window_handle, GWL_EXSTYLE, WS_EX_TOPMOST | WS_EX_LAYERED | WS_EX_TOOLWINDOW | WS_EX_NOACTIVATE);
206- }
207- else {
208- SetWindowLongPtrW(window_handle, GWL_EXSTYLE, WS_EX_TOPMOST | WS_EX_TRANSPARENT | WS_EX_LAYERED | WS_EX_TOOLWINDOW | WS_EX_NOACTIVATE);
209- }
210- }*/
211-
212204 if (globals::menuState) Overlay::Menu ();
213205 }
214206
@@ -224,7 +216,7 @@ void Overlay::OverlayLoop() noexcept {
224216 ImGui_ImplDX11_RenderDrawData (ImGui::GetDrawData ());
225217
226218 // Present
227- HRESULT hr = g_pSwapChain->Present (/* cfg->vsyncState*/ 0 , 0 );
219+ HRESULT hr = g_pSwapChain->Present (cfg->vsyncState , 0 );
228220 g_SwapChainOccluded = (hr == DXGI_STATUS_OCCLUDED);
229221 }
230222
0 commit comments