张洋 3 weeks ago
parent
commit
e14467546e
1 changed files with 21 additions and 1 deletions
  1. 21 1
      DuiLib/Core/UIBase.cpp

+ 21 - 1
DuiLib/Core/UIBase.cpp

@@ -310,6 +310,18 @@ void CWindowWnd::ShowWindow(bool bShow /*= true*/, bool bTakeFocus /*= false*/)
     ::ShowWindow(m_hWnd, bShow ? (bTakeFocus ? SW_SHOWNORMAL : SW_SHOWNOACTIVATE) : SW_HIDE);
     ::ShowWindow(m_hWnd, bShow ? (bTakeFocus ? SW_SHOWNORMAL : SW_SHOWNOACTIVATE) : SW_HIDE);
 }
 }
 
 
+// 临时诊断:识别弹框触摸时「抢走前台」的窗口(如 00210472),解释 WM_TOUCH 为何不投递给弹框。
+// 只取 class/owner/parent/style(不取 text,避免跨进程 GetWindowText 卡死)。
+static void TouchTraceLogWindowIdentity(LPCTSTR tag, HWND h)
+{
+    if( !::IsWindow(h) ) { DuiLib::TouchTrace::Log(_T("%s hwnd=%p INVALID"), tag, (void*)h); return; }
+    TCHAR cls[128] = { 0 };
+    ::GetClassName(h, cls, 128);
+    DuiLib::TouchTrace::Log(_T("%s hwnd=%p cls=\"%s\" owner=%p parent=%p style=0x%08X ex=0x%08X"),
+        tag, (void*)h, cls, (void*)::GetWindow(h, GW_OWNER), (void*)::GetParent(h),
+        (unsigned)::GetWindowLong(h, GWL_STYLE), (unsigned)::GetWindowLong(h, GWL_EXSTYLE));
+}
+
 UINT CWindowWnd::ShowModal()
 UINT CWindowWnd::ShowModal()
 {
 {
     ASSERT(::IsWindow(m_hWnd));
     ASSERT(::IsWindow(m_hWnd));
@@ -329,12 +341,20 @@ UINT CWindowWnd::ShowModal()
         (int)::IsWindowEnabled(m_hWnd), (int)::IsWindowVisible(m_hWnd),
         (int)::IsWindowEnabled(m_hWnd), (int)::IsWindowVisible(m_hWnd),
         (unsigned)::GetWindowLong(m_hWnd, GWL_STYLE), (unsigned)::GetWindowLong(m_hWnd, GWL_EXSTYLE));
         (unsigned)::GetWindowLong(m_hWnd, GWL_STYLE), (unsigned)::GetWindowLong(m_hWnd, GWL_EXSTYLE));
     ::EnableWindow(hWndParent, FALSE);
     ::EnableWindow(hWndParent, FALSE);
+    // 临时诊断:禁用父窗口后立刻抓一次前台窗口,验证「禁用父窗口把前台从弹框抢走」假设
+    DuiLib::TouchTrace::Log(_T("MODAL-AFTER-DISABLE-PARENT hwnd=%p parent=%p foreground=%p active=%p focus=%p"),
+        (void*)m_hWnd, (void*)hWndParent, (void*)::GetForegroundWindow(), (void*)::GetActiveWindow(), (void*)::GetFocus());
     MSG msg = { 0 };
     MSG msg = { 0 };
     while( ::IsWindow(m_hWnd) && ::GetMessage(&msg, NULL, 0, 0) ) {
     while( ::IsWindow(m_hWnd) && ::GetMessage(&msg, NULL, 0, 0) ) {
         if( msg.message == WM_TOUCH || msg.message == WM_LBUTTONDOWN || msg.message == WM_LBUTTONUP || msg.message == WM_MOUSEMOVE ) {
         if( msg.message == WM_TOUCH || msg.message == WM_LBUTTONDOWN || msg.message == WM_LBUTTONUP || msg.message == WM_MOUSEMOVE ) {
+            HWND hFG = ::GetForegroundWindow();
             DuiLib::TouchTrace::Log(_T("MODAL-RAW hwnd=%p msg=0x%04X target=%p w=0x%p l=0x%p capture=%p focus=%p active=%p foreground=%p"),
             DuiLib::TouchTrace::Log(_T("MODAL-RAW hwnd=%p msg=0x%04X target=%p w=0x%p l=0x%p capture=%p focus=%p active=%p foreground=%p"),
                 m_hWnd, msg.message, msg.hwnd, (void*)msg.wParam, (void*)msg.lParam,
                 m_hWnd, msg.message, msg.hwnd, (void*)msg.wParam, (void*)msg.lParam,
-                (void*)::GetCapture(), (void*)::GetFocus(), (void*)::GetActiveWindow(), (void*)::GetForegroundWindow());
+                (void*)::GetCapture(), (void*)::GetFocus(), (void*)::GetActiveWindow(), (void*)hFG);
+            if( hFG != m_hWnd ) {
+                static HWND s_hForeign = NULL;
+                if( hFG != s_hForeign ) { s_hForeign = hFG; TouchTraceLogWindowIdentity(_T("FOREIGN-FG"), hFG); }
+            }
         }
         }
         if( msg.message == WM_CLOSE && msg.hwnd == m_hWnd ) {
         if( msg.message == WM_CLOSE && msg.hwnd == m_hWnd ) {
             nRet = (int)msg.wParam;
             nRet = (int)msg.wParam;