c++winapidwm

Use DwmSetWindowAttribute to create rounded-corner window but didn't work


Windows 10, Win32 classic application: I want to use DwmSetWindowAttribute to create a rounded-corner window, but the function did not work, why?

enter image description here

MainWindow = CreateWindow(wxex.lpszClassName, WindowTitle, WS_OVERLAPPEDWINDOW,
      0, 0, nWidth, nHeight, NULL, NULL hin, NULL);
DWM_WINDOW_CORNER_PREFERENCE pef = DWMWCP_ROUND;
DwmSetWindowAttribite(MainWindow, DWMWA_WINDOW_CORNER_PREFERENCE, &pef, sizeof(pef));
ShowWindow(MainWindow, SW_SHOW);

enter image description here


Solution

  • You say you're using Windows 10, but DWMWA_WINDOW_CORNER_PREFERENCE is supported only starting with Windows 11 Build 22000 as official doc says:

    DWMWA_WINDOW_CORNER_PREFERENCE Use with DwmSetWindowAttribute. Specifies the rounded corner preference for a window. The pvAttribute parameter points to a value of type DWM_WINDOW_CORNER_PREFERENCE.

    This value is supported starting with Windows 11 Build 22000.