Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - Rounded Corners on Windows 11
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Rounded Corners on Windows 11

 Post Reply Post Reply
Author
Message
cpede View Drop Down
Senior Member
Senior Member


Joined: 13 August 2004
Location: Denmark
Status: Offline
Points: 614
Post Options Post Options   Thanks (0) Thanks(0)   Quote cpede Quote  Post ReplyReply Direct Link To This Post Topic: Rounded Corners on Windows 11
    Posted: 08 October 2021 at 5:43am
How do we get rounded windows corners on Windows 11 using the Office themes?
Product: Xtreme ToolkitPro (20.1.0)
Platform: Windows 10 (x64)
Language: Visual Studio 2017 (C++)
Back to Top
dbrookes View Drop Down
Groupie
Groupie


Joined: 30 August 2019
Location: Australia
Status: Offline
Points: 58
Post Options Post Options   Thanks (0) Thanks(0)   Quote dbrookes Quote  Post ReplyReply Direct Link To This Post Posted: 11 October 2021 at 3:40am
Windows 11 won't enable it by default when the application is drawing its own window frame. They talk a little bit about it here https://docs.microsoft.com/en-us/windows/apps/desktop/modernize/apply-rounded-corners and how to force enable it using dwmapi.

I've tested forcing rounded corners with XTP frame hook theming and it seems to work okay.

Here is a sample I have tested with:

///
/// \enum CornerPreference
///
enum class CornerPreference
  {
  Default    = 0, ///< Let the system decide to round window corners.
  DoNotRound = 1, ///< Never round window corners.
  Round      = 2, ///< Round corners if appropriate.
  RoundSmall = 3, ///< Round corners if appropriate (with small radius).
  };

HRESULT UpdateWindows11RoundCorners(HWND hWnd, CornerPreference cornerPreference)
  {
  typedef HRESULT(WINAPI *PFNSETWINDOWATTRIBUTE)(HWND hWnd, DWORD dwAttribute, LPCVOID pvAttribute, DWORD cbAttribute);

  // We don't build against the Windows 11 SDK so we define these ourselves. These are normally
  // defined in dwmapi.h header.

  ///
  /// \enum DWMWINDOWATTRIBUTE
  ///
  enum DWMWINDOWATTRIBUTE
    {
    DWMWA_WINDOW_CORNER_PREFERENCE = 33
    };

  ///
  /// \enum DWM_WINDOW_CORNER_PREFERENCE
  ///
  enum DWM_WINDOW_CORNER_PREFERENCE
    {
    DWMWCP_DEFAULT    = 0,
    DWMWCP_DONOTROUND = 1,
    DWMWCP_ROUND      = 2,
    DWMWCP_ROUNDSMALL = 3
    };

  HMODULE hDwmApi = ::LoadLibrary(_T("dwmapi.dll"));
  if (hDwmApi)
    {
    auto *pfnSetWindowAttribute = reinterpret_cast<PFNSETWINDOWATTRIBUTE>(
      ::GetProcAddress(hDwmApi, "DwmSetWindowAttribute"));
    if (pfnSetWindowAttribute)
      {
      auto preference = static_cast<DWM_WINDOW_CORNER_PREFERENCE>(cornerPreference);
      return pfnSetWindowAttribute(hWnd, DWMWA_WINDOW_CORNER_PREFERENCE,
                                   &preference, sizeof(DWM_WINDOW_CORNER_PREFERENCE));
      }
    ::FreeLibrary(hDwmApi);
    }

  return E_FAIL;
  }

One thing you'll need to do with XTP frame hook is disable XTP's frame shadows as they won't work correctly with the rounded corners, as you'd probably expect. If that set window attribute function succeeds you should call pCommandBars->GetFrameHook()->DisableShadows(). Your window should then be using the built-in system shadows instead (at least ours seems to).
Product: ToolkitPro v19.1.0
OS: Windows 10
Language: C++ (VS2019)
Back to Top
Pesci7 View Drop Down
Newbie
Newbie
Avatar

Joined: 27 January 2021
Location: Italy
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote Pesci7 Quote  Post ReplyReply Direct Link To This Post Posted: 11 October 2021 at 6:36am
Thanks, another great contribute. It works on the main window and also on the splash screen.
Is it possible to have rounded corner also on context menu?

The drawback is that we have again the problem of catching the border of the window for resizing.
Product: Xtreme ToolkitPro (20.1.0)
Platform: Windows 10 (x64)
Language: Visual Studio 2019 (C++)
Back to Top
cpede View Drop Down
Senior Member
Senior Member


Joined: 13 August 2004
Location: Denmark
Status: Offline
Points: 614
Post Options Post Options   Thanks (0) Thanks(0)   Quote cpede Quote  Post ReplyReply Direct Link To This Post Posted: 11 October 2021 at 9:45am
Thanks for posting, and I can add this for more info:

But, this probably only works when?
pCommandBars->GetFrameHook()->m_bAllowDwm = TRUE;

And in my attempt to use DWM, I got this funny looking drawing error, cutting the top of the full page backstage back arrow, using the Office 2016 themes:
(corrected: maybe it is drawing white on white, why it looks clipped?)


Will CodeJock need to implement the rounded corners in the themes directly?

PS, also notice the new https://docs.microsoft.com/en-us/windows/apps/desktop/modernize/apply-snap-layout-menu Windows 11 feature, that probably also needs to be implemented into the themes?

Product: Xtreme ToolkitPro (20.1.0)
Platform: Windows 10 (x64)
Language: Visual Studio 2017 (C++)
Back to Top
dbrookes View Drop Down
Groupie
Groupie


Joined: 30 August 2019
Location: Australia
Status: Offline
Points: 58
Post Options Post Options   Thanks (0) Thanks(0)   Quote dbrookes Quote  Post ReplyReply Direct Link To This Post Posted: 11 October 2021 at 8:59pm
I have m_bAllowDwm set to FALSE by the looks of it (its been like that for years). It looks like the Office 2013/2016 frame theme automatically turns it off anyway.

Maybe try it on the ribbon sample and see what happens. I've not noticed issues yet.

About the snap menu layout. I looked at this as well. That works okay with XTP's frame hook if you are using menu bar + toolbars since XTP handles WM_NCHITTEST there. However, if you are using a ribbon bar the maximize button (and others) are part of the ribbon bar itself which is not in the non client area, therefore no WM_NCHITTEST. You just have to press the shortcut to get to it (Win + Z).
Product: ToolkitPro v19.1.0
OS: Windows 10
Language: C++ (VS2019)
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.094 seconds.