From bc1f143a0292bc2cde94770afdd1396e72a01ac9 Mon Sep 17 00:00:00 2001 From: wj32 Date: Sat, 11 Sep 2010 03:47:37 +0000 Subject: [PATCH] improved window finding algorithm git-svn-id: svn://svn.code.sf.net/p/processhacker/code@3594 21ef857c-d57f-4fe0-8362-d861dc6d29cd --- 2.x/trunk/ProcessHacker/mainwnd.c | 7 ++++++- 2.x/trunk/ProcessHacker/proctree.c | 22 ++++++++++------------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/2.x/trunk/ProcessHacker/mainwnd.c b/2.x/trunk/ProcessHacker/mainwnd.c index 3bc6cd47f..3dc406c3a 100644 --- a/2.x/trunk/ProcessHacker/mainwnd.c +++ b/2.x/trunk/ProcessHacker/mainwnd.c @@ -3201,13 +3201,18 @@ BOOL CALLBACK PhpEnumProcessWindowsProc( ) { ULONG processId; + HWND parentWindow; if (!IsWindowVisible(hwnd)) return TRUE; GetWindowThreadProcessId(hwnd, &processId); - if (processId == (ULONG)lParam) + if ( + processId == (ULONG)lParam && + !((parentWindow = GetParent(hwnd)) && IsWindowVisible(parentWindow)) && // skip windows with a visible parent + GetWindowTextLength(hwnd) != 0 + ) { SelectedProcessWindowHandle = hwnd; return FALSE; diff --git a/2.x/trunk/ProcessHacker/proctree.c b/2.x/trunk/ProcessHacker/proctree.c index 60c8d2def..25861888c 100644 --- a/2.x/trunk/ProcessHacker/proctree.c +++ b/2.x/trunk/ProcessHacker/proctree.c @@ -572,6 +572,15 @@ BOOL CALLBACK PhpEnumProcessNodeWindowsProc( if (UlongToHandle(processId) == processNode->ProcessId) { + HWND parentWindow; + + if ( + !IsWindowVisible(hwnd) || // skip invisible windows + ((parentWindow = GetParent(hwnd)) && IsWindowVisible(parentWindow)) || // skip windows with visible parents + GetWindowTextLength(hwnd) == 0 // skip windows with no title + ) + return TRUE; + processNode->WindowHandle = hwnd; return FALSE; } @@ -592,18 +601,7 @@ VOID PhpUpdateProcessNodeWindow( if (ProcessNode->WindowHandle) { - ProcessNode->WindowText = PhCreateStringEx(NULL, 128); - - if (InternalGetWindowText(ProcessNode->WindowHandle, - ProcessNode->WindowText->Buffer, ProcessNode->WindowText->Length / sizeof(WCHAR)) != 0) - { - PhTrimToNullTerminatorString(ProcessNode->WindowText); - } - else - { - PhSwapReference(&ProcessNode->WindowText, NULL); - } - + ProcessNode->WindowText = PhGetWindowText(ProcessNode->WindowHandle); ProcessNode->WindowHung = !!IsHungAppWindow(ProcessNode->WindowHandle); }