Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
560 views
in Technique[技术] by (71.8m points)

winapi - How to identify Windows 10 background store processes that have non-displayed windows that are programmatically visible and minimizable?

I have a Win32?application that determines whether there are any visible, non-iconic, minimizable?windows being shown. To the best of my knowledge it's worked fine for Win9x through to Win8.1, but under Windows 10 it often finds several windows that aren't actually visible on the screen.

To try to identify what's going on I've written a simple test application that enumerates and records all such windows. Here's the essence of the EnumWindows callback code:

BOOL CALLBACK EnumFunc( HWND hWnd, LPARAM lParam )
{
  if ( IsWindowVisible( hWnd ) )
  {
    if ( !IsIconic( hWnd ) )
    {
      const LONG style = GetWindowLong( hWnd, GWL_STYLE );

      if ( WS_MINIMIZEBOX & style )
      {
     //      record window info
      }
    }
   }
 return TRUE;
}

Most of the phantom windows under Windows 10 belong to background store app processes such as Mail, Calculator, and Photos. These are listed under the Background processes section of Task Manager, and if I use Task Manager to end those background tasks, their phantom window is no longer found by my test application.

enter image description here

In the above screen shot from my test application you can see that all but 1 of the offending windows belong to threads of the same process id 7768, which is ApplicationFrameHost.exe. The final window with process id 11808 is explorer.exe.

I've looked at the phantom windows with Spy++ and can't see any particular style combination that would help in uniquely identifying them.

I've had a suggestion that the undocumented Windows "bands" may be involved, but I've tried using the (undocumented, so this may be wrong) API:

BOOL WINAPI GetWindowBand (HWND hWnd, PDWORD pdwBand);

but it returns a band of 1 for any window, so doesn't differentiate these phantoms.

How to reliably identify these phantom windows?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The approved way of detecting these phantom windows is to use DwmGetWindowAttribute and DWMWA_CLOAKED.

Here's the code I've used:

static bool IsInvisibleWin10BackgroundAppWindow( HWND hWnd )
{
    int CloakedVal;
    HRESULT hRes = DwmGetWindowAttribute( hWnd, DWMWA_CLOAKED, &CloakedVal, sizeof( CloakedVal ) );
    if ( hRes != S_OK )
    {
        CloakedVal = 0;
    }
    return CloakedVal ? true : false;
}

Thanks to Scot Br from MS for posting the answer here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...