فهرست منبع

Use SetWindowPos to show windows when SDL_HINT_WINDOW_ACTIVATE_WHEN_SHOWN is set to avoid activating the parent window when showing a child window

Sam Lantinga 1 سال پیش
والد
کامیت
41d436f0fe
1فایلهای تغییر یافته به همراه6 افزوده شده و 4 حذف شده
  1. 6 4
      src/video/windows/SDL_windowswindow.c

+ 6 - 4
src/video/windows/SDL_windowswindow.c

@@ -845,7 +845,6 @@ void WIN_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window)
 {
     DWORD style;
     HWND hwnd;
-    int nCmdShow;
 
     SDL_bool bActivate = SDL_GetHintBoolean(SDL_HINT_WINDOW_ACTIVATE_WHEN_SHOWN, SDL_TRUE);
 
@@ -855,13 +854,16 @@ void WIN_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window)
     }
 
     hwnd = window->driverdata->hwnd;
-    nCmdShow = bActivate ? SW_SHOW : SW_SHOWNA;
     style = GetWindowLong(hwnd, GWL_EXSTYLE);
     if (style & WS_EX_NOACTIVATE) {
-        nCmdShow = SW_SHOWNOACTIVATE;
         bActivate = SDL_FALSE;
     }
-    ShowWindow(hwnd, nCmdShow);
+    if (bActivate) {
+        ShowWindow(hwnd, SW_SHOW);
+    } else {
+        /* Use SetWindowPos instead of ShowWindow to avoid activating the parent window if this is a child window */
+        SetWindowPos(hwnd, NULL, 0, 0, 0, 0, window->driverdata->copybits_flag | SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
+    }
 
     if (window->flags & SDL_WINDOW_POPUP_MENU && bActivate) {
         if (window->parent == SDL_GetKeyboardFocus()) {