SetWindowDisplayAffinity on windows 11

sickl8 46 Reputation points
2022-01-18T19:34:59.073+00:00

Hiding windows from screen capture in windows 10 is a breeze
SetWindowDisplayAffinity() with WDA_EXCLUDEFROMCAPTURE and WDA_MONITOR doesn't work on firefox and chrome, but does work on notepad for example (as far as I tested)
What changed in windows 11 that might have caused this "bug?"? Was this intended from the microsoft devs? Would like a solution to port my windows 10 app to win11.
Thanks.

here's a program to test with, it's a command line program. github repo

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,422 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,527 questions
Windows 10 Compatibility
Windows 10 Compatibility
Windows 10: A Microsoft operating system that runs on personal computers and tablets.Compatibility: The extent to which hardware or software adheres to an accepted standard.
455 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
8,166 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Junjie Zhu - MSFT 14,751 Reputation points Microsoft Vendor
    2022-06-16T08:25:41.907+00:00

    HI, All
    Welcome to Microsoft Q&A!

    Here are the steps for the workaround. First the Windows ADK needs to be installed: Download and install the Windows ADK | Microsoft Learn
    1.Start Compatibility Administrator
    2.Select File | New menu item to create a new custom compatibility database file.
    3.Select Database | Create New | Application Fix menu item, which will display the “Create new Application Fix” wizard. Enter information about the program to be fixed, then click Next. The following screen shot demonstrates using HelloWorld.exe(Apps that don't work with SetWindowDisplayAffinity).

    211900-create-new-application-fix.png

    4.Select any desired compatibility modes, then click Next. No compatibility modes are needed in this scenario.

    211898-commodes.png

    5.Check the PreventMouseInPointer compatibility fix, then click Next.
    211987-fixes.png

    6.Select the criteria that the system will use to determine whether to apply the PreventMouseInPointer fix to the application, then click Finish. I selected the COMPANY_NAME, PRODUCT_NAME and UP_TO_BIN_FILE_VERSION options.
    211909-match.png

    7.Compatibility Administrator will then display content similar to the following:
    211899-display.png

    8.Repeat steps 3 through 6 for other executables to add to the custom compatibility database if needed. I repeated the steps to apply PreventMouseInPointer to HelloWorld.exe.

    9.Select File | Save menu item. Provide a name for the custom compatibility database and path/name for the .sdb file.
    212002-image.png

    10.You can then use Compatibility Administrator to install the .sdb file (File | Install menu item), or specify the fill path to the .sdb file as a command line argument to the sdbinst.exe command-line tool.
    Example: sdbinst c:\pathToSdbFile\HelloWorld.sdb
    Compatibility Administrator will then show the custom compatibility database under Installed Databases.

    212011-123333.png

    Thanks!


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1: https://learn.microsoft.com/en-us/windows-hardware/get-started/adk-install 3: /api/attachments/211898-commodes.png?platform=QnA

    5: /api/attachments/212002-image.png?platform=QnA 7: https://learn.microsoft.com/en-us/answers/articles/67444/email-notifications.html


  2. SoftGun 6 Reputation points
    2022-10-19T14:45:22.08+00:00

    252101-chrome.png

    Hello, I have tried all steps for chrome.exe on windows 11. Unfortunately, its not working for that application. I will test with edge, firefox and safari and revert back with results. @Junjie Zhu - MSFT

    0 comments No comments

  3. George Taylor 0 Reputation points
    2023-01-24T15:01:27.5233333+00:00

    I distribute an app that employs SetWindowDisplayAffinity to hide sensitive information from screen capture. This works with the WDA_EXCLUDEFROMCAPTURE flasg on all Windows 10 platforms and earlier, and many WIndows 11 computers. However, there is a subset of Windows 11 computers for which both WDA_EXCLUDEFROMCAPTURE and WDA_MONITOR fails. Of course the proposed solution is no help for an app that is being widely distributed. Unfortunately, currently I am not collecting GetLastError values. I would appreciate a fix. Thanks

    0 comments No comments