Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 828
David Lowndes Avatar asked Nov 30 '25 07:11

David Lowndes


1 Answers

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

like image 169
David Lowndes Avatar answered Dec 02 '25 05:12

David Lowndes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!