Print Page | Close Window

Rounded Corners on Windows 11

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=24223
Printed Date: 18 April 2024 at 9:29pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Rounded Corners on Windows 11
Posted By: cpede
Subject: Rounded Corners on Windows 11
Date 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.3.0)
Platform: Windows 10 (x64)
Language: Visual Studio 2017 (C++)



Replies:
Posted By: dbrookes
Date 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" rel="nofollow - 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).


Posted By: Pesci7
Date 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++)


Posted By: cpede
Date Posted: 11 October 2021 at 9:45am
Thanks for posting, and I can add this for more info:
http://docs.microsoft.com/en-us/windows/apps/desktop/modernize/apply-rounded-corners" rel="nofollow - https://docs.microsoft.com/en-us/windows/apps/desktop/modernize/apply-rounded-corners

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  http://docs.microsoft.com/en-us/windows/apps/desktop/modernize/apply-snap-layout-menu" rel="nofollow - 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.3.0)
Platform: Windows 10 (x64)
Language: Visual Studio 2017 (C++)


Posted By: dbrookes
Date 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).


Posted By: SueDowell
Date Posted: 26 October 2021 at 8:17am
Can you please tell me what you think of Windows 11? Is it good or the usual?)


Posted By: dbrookes
Date 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.


Posted By: rdhd
Date 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.


Posted By: rdhd
Date 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.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net