https://git.reactos.org/?p=reactos.git;a=commitdiff;h=1c82bf032498d3d107aae7174c5fb179680f0eb5

commit 1c82bf032498d3d107aae7174c5fb179680f0eb5
Author:     Katayama Hirofumi MZ <[email protected]>
AuthorDate: Fri Dec 24 16:08:07 2021 +0900
Commit:     GitHub <[email protected]>
CommitDate: Fri Dec 24 16:08:07 2021 +0900

    [TASKMGR] Avoid freezing in getting icons (#4180)
    
    - Modify the timeout value of SendMessageTimeout.
    - Use SMTO_ABORTIFHUNG flag.
    - Check if the window alive.
    CORE-17894
---
 base/applications/taskmgr/applpage.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/base/applications/taskmgr/applpage.c 
b/base/applications/taskmgr/applpage.c
index f3ad41c891a..b249006e94b 100644
--- a/base/applications/taskmgr/applpage.c
+++ b/base/applications/taskmgr/applpage.c
@@ -353,6 +353,7 @@ BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam)
     WCHAR   szText[260];
     BOOL    bLargeIcon;
     BOOL    bHung = FALSE;
+    LRESULT bAlive;
 
     typedef int (FAR __stdcall *IsHungAppWindowProc)(HWND);
     IsHungAppWindowProc IsHungAppWindow;
@@ -377,20 +378,26 @@ BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam)
 
     noApps = FALSE;
 
+#define GET_ICON(type) \
+    SendMessageTimeoutW(hWnd, WM_GETICON, (type), 0, SMTO_ABORTIFHUNG, 100, 
(PDWORD_PTR)&hIcon)
+
     /* Get the icon for this window */
     hIcon = NULL;
-    SendMessageTimeoutW(hWnd, WM_GETICON, bLargeIcon ? ICON_BIG : ICON_SMALL, 
0, 0, 1000, (PDWORD_PTR)&hIcon);
+    bAlive = GET_ICON(bLargeIcon ? ICON_BIG : ICON_SMALL);
     if (!hIcon)
     {
         /* We failed, try to retrieve other icons... */
-        hIcon = (HICON)(LONG_PTR)GetClassLongPtrW(hWnd, bLargeIcon ? GCL_HICON 
: GCL_HICONSM);
-        if (!hIcon) hIcon = (HICON)(LONG_PTR)GetClassLongPtrW(hWnd, bLargeIcon 
? GCL_HICONSM : GCL_HICON);
-        if (!hIcon) SendMessageTimeoutW(hWnd, WM_QUERYDRAGICON, 0, 0, 0, 1000, 
(PDWORD_PTR)&hIcon);
-        if (!hIcon) SendMessageTimeoutW(hWnd, WM_GETICON, bLargeIcon ? 
ICON_SMALL : ICON_BIG, 0, 0, 1000, (PDWORD_PTR)&hIcon);
+        if (!hIcon && bAlive)
+            GET_ICON(bLargeIcon ? ICON_SMALL : ICON_BIG);
+        if (!hIcon)
+            hIcon = (HICON)(LONG_PTR)GetClassLongPtrW(hWnd, bLargeIcon ? 
GCL_HICON : GCL_HICONSM);
+        if (!hIcon)
+            hIcon = (HICON)(LONG_PTR)GetClassLongPtrW(hWnd, bLargeIcon ? 
GCL_HICONSM : GCL_HICON);
 
         /* If we still do not have any icon, load the default one */
         if (!hIcon) hIcon = LoadIconW(hInst, bLargeIcon ? 
MAKEINTRESOURCEW(IDI_WINDOW) : MAKEINTRESOURCEW(IDI_WINDOWSM));
     }
+#undef GET_ICON
 
     bHung = FALSE;
 

Reply via email to