How to remove the borders created by DwmExtendFrameIntoClientArea?

Leonardo 91 Reputation points

I'm creating a frameless rounded border window and calling the DwmExtendFrameIntoClientArea
API to add the shadow effect around it.

However, the API also creates a white border around the window:


These borders appear only when i call the DwmExtendFrameIntoClientArea API:

const MARGINS shadow = { 1, 1, 1, 1 };  
DwmExtendFrameIntoClientArea(mainwindow_hWnd, &shadow);  

Some things i noted:

  • The borders are visible on Win10, but not on Win11.
  • They are visible only when the window is focused.

Is it possible to remove or hide these borders?

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,511 questions
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,626 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Tong Xu - MSFT 2,201 Reputation points Microsoft Vendor

    Welcome to Microsoft Q&A!
    I have reproduced this scenario,
    this problem occurs because of the dwStyle parameter. You must have added WS_THICKFRAME. After adding WS_POPUP, the window does not appear white border.

    Could you please show a minimal, reproducible sample without private information?

    Thank you.

    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][2] to enable e-mail notifications if you want to receive the related email notification for this thread. [2]:

    1 person found this answer helpful.
    0 comments No comments

  2. Leonardo 91 Reputation points

    @Tong Xu - MSFT thank you for trying it!

    Indeed adding WS_POPUP the white border doesn't appear, however the shadow is also gone and the window cant be minimized anymore.

    I have been able to change that border color using the undoc SetWindowCompositionAttribute, however i couldn't get it fully transparent:

    const MARGINS shadow = { 1, 1, 1, 1 };  
    DwmExtendFrameIntoClientArea(mainwindow_hWnd, &shadow);  
    struct ACCENTPOLICY  
        int nAccentState;  
        int nFlags;  
        int nColor;  
        int nAnimationId;  
      int na;  
      PVOID pd;  
      ULONG ul;  
    typedef enum _ACCENT_STATE {  
        ACCENT_DISABLED = 0,  
    typedef struct _ACCENT_POLICY {  
        ACCENT_STATE AccentState;  
        DWORD        AccentFlags;  
        DWORD        GradientColor;  
        DWORD        AnimationId;  
        DrawLeftBorder = 0x20,  
        DrawTopBorder = 0x40,  
        DrawRightBorder = 0x80,  
        DrawBottomBorder = 0x100,  
        DrawAllBorders = (DrawLeftBorder | DrawTopBorder | DrawRightBorder | DrawBottomBorder)  
    const HINSTANCE hm = LoadLibrary(L"user32.dll");  
    if (hm)  
        typedef BOOL(WINAPI* pSetWindowCompositionAttribute)(HWND, WINCOMPATTRDATA*);  
        const pSetWindowCompositionAttribute SetWindowCompositionAttribute = (pSetWindowCompositionAttribute)GetProcAddress(hm, "SetWindowCompositionAttribute");  
        if (SetWindowCompositionAttribute)  
            ACCENTPOLICY policy = { 2, 0, 0x01000000, 0 };  
            WINCOMPATTRDATA data = { 19, &policy, sizeof(ACCENTPOLICY) }; // WCA_ACCENT_POLICY=19  
            SetWindowCompositionAttribute(mainwindow_hWnd, &data);  
            DWORD err = GetLastError();  
            qDebug() << "err: " << err;  

    Could you please show a minimal, reproducible sample without private information?

    I didn't share the full code because the window im working is being built using the Qt framework, I'm editing these things by handling into her DefWindowProc.

    I wonder if you could share the code you've used, so i could try get it working on it and after replicate on the Qt window.

    (I'm replying as an answer because i wasn't allowed to do on comment as it 'exceeded maximum characters')