[EXPLORER] Improve the minimize-condition on Win+D (#5423)

- Add CanBeMinimized helper function to determine whether the window should be minimized.
- Use them in FindEffectiveProc and MinimizeWindowsProc functions.
- Improve the Minimize code.
CORE-18427
This commit is contained in:
Katayama Hirofumi MZ 2023-07-14 18:03:15 +09:00 committed by GitHub
parent cdfd8f4e1b
commit 22ab8c812a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -99,6 +99,20 @@ VOID RestoreWindowPos()
g_WindowPosBackup.RemoveAll();
}
BOOL CanBeMinimized(HWND hwnd)
{
if (::IsWindowVisible(hwnd) && !::IsIconic(hwnd) && ::IsWindowEnabled(hwnd))
{
if (::GetClassLongPtrW(hwnd, GCW_ATOM) == (ULONG_PTR)WC_DIALOG)
return TRUE;
DWORD exstyle = (DWORD)::GetWindowLongPtrW(hwnd, GWL_EXSTYLE);
if (!(exstyle & WS_EX_TOPMOST))
return TRUE;
}
return FALSE;
}
struct EFFECTIVE_INFO
{
HWND hwndFound;
@ -113,7 +127,7 @@ FindEffectiveProc(HWND hwnd, LPARAM lParam)
{
EFFECTIVE_INFO *pei = (EFFECTIVE_INFO *)lParam;
if (!IsWindowVisible(hwnd) || IsIconic(hwnd))
if (!CanBeMinimized(hwnd))
return TRUE; // continue
if (pei->hTrayWnd == hwnd || pei->hwndDesktop == hwnd ||
@ -159,13 +173,6 @@ IsThereAnyEffectiveWindow(BOOL bMustBeInMonitor)
ei.bMustBeInMonitor = bMustBeInMonitor;
EnumWindows(FindEffectiveProc, (LPARAM)&ei);
if (ei.hwndFound && FALSE)
{
WCHAR szClass[64], szText[64];
GetClassNameW(ei.hwndFound, szClass, _countof(szClass));
GetWindowTextW(ei.hwndFound, szText, _countof(szText));
MessageBoxW(NULL, szText, szClass, 0);
}
return ei.hwndFound != NULL;
}
@ -2689,7 +2696,7 @@ ChangePos:
LRESULT OnCopyData(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
COPYDATASTRUCT *pCopyData = reinterpret_cast<COPYDATASTRUCT *>(lParam);
COPYDATASTRUCT *pCopyData = (COPYDATASTRUCT *)lParam;
switch (pCopyData->dwData)
{
case TABDMC_APPBAR:
@ -3262,16 +3269,14 @@ HandleTrayContextMenu:
return TRUE;
}
if (::IsWindowVisible(hwnd) && !::IsIconic(hwnd))
if (CanBeMinimized(hwnd))
{
MINWNDPOS mwp;
mwp.hwnd = hwnd;
mwp.wndpl.length = sizeof(mwp.wndpl);
::GetWindowPlacement(hwnd, &mwp.wndpl); // Save the position and status
info->pMinimizedAll->Add(mwp);
::ShowWindowAsync(hwnd, SW_MINIMIZE);
MINWNDPOS mwp = { hwnd, { sizeof(mwp.wndpl) } };
if (::GetWindowPlacement(hwnd, &mwp.wndpl) && // Save the position and status
::ShowWindowAsync(hwnd, SW_SHOWMINNOACTIVE)) // Minimize
{
info->pMinimizedAll->Add(mwp);
}
}
return TRUE;
@ -3309,9 +3314,7 @@ HandleTrayContextMenu:
{
HWND hwnd = g_MinimizedAll[i].hwnd;
if (::IsWindowVisible(hwnd) && ::IsIconic(hwnd))
{
::SetWindowPlacement(hwnd, &g_MinimizedAll[i].wndpl);
}
}
g_MinimizedAll.RemoveAll();