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: 668
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 (24.0.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: 70
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).
Back to Top
Pesci7 View Drop Down
Groupie
Groupie
Avatar

Joined: 27 January 2021
Location: Italy
Status: Offline
Points: 17
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 (22.1.0)
Platform: Windows 11 (x64)
Language: Visual Studio 2022 (C++)
Back to Top
cpede View Drop Down
Senior Member
Senior Member


Joined: 13 August 2004
Location: Denmark
Status: Offline
Points: 668
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 (24.0.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: 70
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).
Back to Top
SueDowell View Drop Down
Newbie
Newbie
Avatar

Joined: 26 October 2021
Location: USA
Status: Offline
Points: 1
Post Options Post Options   Thanks (0) Thanks(0)   Quote SueDowell Quote  Post ReplyReply Direct Link To This Post Posted: 26 October 2021 at 8:17am
Can you please tell me what you think of Windows 11? Is it good or the usual?)
Back to Top
dbrookes View Drop Down
Groupie
Groupie


Joined: 30 August 2019
Location: Australia
Status: Offline
Points: 70
Post Options Post Options   Thanks (0) Thanks(0)   Quote dbrookes Quote  Post ReplyReply Direct Link To This Post Posted: 20 December 2021 at 12:46am
Its fine I guess. It had a lot of bugs on release but they've been ironing them out. Its more or less just a reskin of Windows 10 with some extra features like WSLG. They didn't even increment the NT version which is surprising.
Back to Top
rdhd View Drop Down
Senior Member
Senior Member
Avatar

Joined: 13 August 2007
Location: United States
Status: Offline
Points: 891
Post Options Post Options   Thanks (0) Thanks(0)   Quote rdhd Quote  Post ReplyReply Direct Link To This Post Posted: 26 January 2022 at 3:10pm
Unfortunately it is really tough to resize our app if shadows is off. At least on my 4k monitor. I spend a lot of time trying to get the resize cursor icon to show up and not go away when I press the mouse button. Probably my achy shaky hand.
Back to Top
rdhd View Drop Down
Senior Member
Senior Member
Avatar

Joined: 13 August 2007
Location: United States
Status: Offline
Points: 891
Post Options Post Options   Thanks (0) Thanks(0)   Quote rdhd Quote  Post ReplyReply Direct Link To This Post Posted: 26 January 2022 at 3:30pm
Hi cepde,

I totally missed the XTP_ID_RIBBONBACKSTAGE_BACK and implemented my own "Back" button. So I just called to add that command to my backstage and then to set the control to manual update and enabled it. Worked fine. But, I have no tooltip string or image. Did you create your own image and add it to the image manager? When I added the command, the toolkit pro DLL was the main resource handle. No string there so CJ just went the whole MFC route to find a string (none found on my box, which wouldn't have been correct in any case).

Does CJ have its own icon? We provide our own translations so the image is my only impediment to using the CJ "Back" command.
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.422 seconds.