Failed to disable Peek Preview in Windows 11

trance 11 Reputation points
2022-07-21T02:13:19.12+00:00

Hi, everyone!

To implement some custom fetatures I need to disable peek preview for the window. So I call DwmSetWindowAttribute with DWMWA_DISALLOW_PEEK set to True to disallow peek preview.

It works well in Win7 and Win10 but in my newest Win11 machine, it sill shows peek preview when the mouse hovers over the window's thumbnail in the taskbar.

And I use a demo from VS2019 to reproduce this bug and still it works well in Window 7 and Window 10, but not in Windows 11.

I also read the SDK document and I don't find changes relevant to this behavior. Did I misuse this interface? If you know the right way to disable it, let me know plz~~

Steps to reproduce the bug

  1. Open Visual Studio 2019 and New C++ Desktop Project.
  2. With a built-in demo, disable peek preview with DwmSetWindowAttribute
      #include <dwmapi.h>  
     ....  
     // built-in demo  
     ....  
     BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)  
     {  
        hInst = hInstance;  
    
        HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,  
           CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);  
    
        if (!hWnd)  
        {  
           return FALSE;  
        }  
    
        ShowWindow(hWnd, nCmdShow);  
        UpdateWindow(hWnd);  
    
        // ****************** to reproduce this bug  ******************  
        BOOL disallow_peek = TRUE;  
        DwmSetWindowAttribute(hWnd, DWMWA_DISALLOW_PEEK, &disallow_peek, sizeof(disallow_peek));  
        // ****************** to reproduce this bug  ******************  
    
        return TRUE;  
     }  
    
  3. Add link dependency dwmapi.lib
  4. Compile and Run
  5. It still shows peek preview in Windows 11 but not in Windows 10/7.

Expected behavior

No peek preview in Windows 11(22000.829)

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,734 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
10,807 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Xiaopo Yang - MSFT 12,726 Reputation points Microsoft Vendor
    2022-07-21T05:03:55.793+00:00

    Hello, @trance . I have reproduced the behavior in Windows11 and it does work well in Window 7 and Window 10. I'm consulting my senior for the behavior. Thank You.


  2. Limitless Technology 39,816 Reputation points
    2022-07-21T13:47:13.727+00:00

    Hi,

    According to this document the function should still work in Windows 11:

    https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/nf-dwmapi-dwmsetwindowattribute

    Have you downloaded the latest dwmapi.lib to ensure that this is not the issue?

    ------------------------------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept as answer--


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.