You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: hub/apps/desktop/modernize/apply-rounded-corners.md
+14-11Lines changed: 14 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -32,7 +32,7 @@ If your app's main window doesn't receive automatic rounding, it's because you'v
32
32
- Empty non-client area
33
33
- Other customizations, such as extra non-child windows used for custom shadows
34
34
35
-
Changing one of these things will break automatic rounding. Although we did try to round as many apps as possible with our system heuristics, there are some combinations of customizations that we can't predict so we provided a manual opt-in API for those cases. If you address these issues in your app or call the opt-in API, described in the following section, then it's possible for the system to round you. Note, however, that the API is a hint to the system and does not guarantee rounding, depending on the customizations.
35
+
Changing one of these things will break automatic rounding. Although we did try to round as many apps as possible with our system heuristics, there are some combinations of customizations that we can't predict so we provided a manual opt-in API for those cases. If you address these issues in your app or call the opt-in API, described in the following section, then it's possible for the system to round your app's window. Note, however, that the API is a hint to the system and does not guarantee rounding, depending on the customizations.
36
36
1. Apps that cannot ever be rounded, even if they call the opt-in API.
37
37
38
38
These apps have no frame or borders, and typically have heavily customized UI. If your app does one of the following, it cannot be rounded:
@@ -59,7 +59,7 @@ A pointer to the appropriate value from this enum is passed to the third paramet
59
59
60
60
### For C# apps
61
61
62
-
DwmSetWindowAttribute is a native C++ API. If your app is based on .NET and uses C#, you'll need to use [P/Invoke](/dotnet/standard/native-interop/pinvoke) to import dwmapi.dll and the DwmSetWindowAttribute function signature. All standard WinForms and WPF apps are rounded automatically like any other app, but if you customize your window frame or use a third party framework, you might need to opt-in to rounded corners if doing so results in losing the default rounding. See the Examples section for further details.
62
+
DwmSetWindowAttribute is a native Win32 API and is not exposed directly to .NET code. You'll need to use your language's implementation of P/Invoke to declare the function (C# code is given in the example below). All standard WinForms and WPF apps are rounded automatically, but if you customize your window frame or use a third party framework, you might need to opt-in to rounded corners. See the Examples section for further details.
63
63
64
64
## Examples
65
65
@@ -70,7 +70,7 @@ The following examples show how you can call [**DwmSetWindowAttribute**](/window
70
70
71
71
### Example 1 - Rounding an app's main window in C# - WPF
72
72
73
-
To call DwmSetWindowAttribute in a C# WPF desktop app, you'll need to import dwmapi.dll and the DwmSetWindowAttribute function signature with [P/Invoke](/dotnet/standard/native-interop/pinvoke). First you'll need to redefine the required enum values from the native dwmapi.h header, then declare the function using C# types equivalent to the original native function. Because the original takes a pointer for the third parameter, make sure to use the *ref* keyword so you can pass the address of a variable when you call the function. You can do this in your MainWindow class in MainWindow.xaml.cs.
73
+
This example shows how to call DwmSetWindowAttribute from C# by using the **[DllImport]** attribute. Note that this definition is specific to rounded corners; the DwmSetWindowAttribute function is designed to take different parameters depending on the flags provided, so this is not a general-purpose signature. The example also includes copies of the relevant enums from the dwmapi.h header file. Because the Win32 API takes a pointer for the third parameter, make sure to use the *ref* keyword so you can pass the address of a variable when you call the function. You can do this in your MainWindow class in MainWindow.xaml.cs.
74
74
75
75
```CSharp
76
76
usingSystem.Runtime.InteropServices;
@@ -79,13 +79,15 @@ using System.Windows.Interop;
79
79
publicpartialclassMainWindow : Window
80
80
{
81
81
// The enum flag for DwmSetWindowAttribute's second parameter, which tells the function what attribute to set.
82
+
// Copied from dwmapi.h
82
83
publicenumDWMWINDOWATTRIBUTE
83
84
{
84
85
DWMWA_WINDOW_CORNER_PREFERENCE=33
85
86
}
86
87
87
88
// The DWM_WINDOW_CORNER_PREFERENCE enum for DwmSetWindowAttribute's third parameter, which tells the function
88
89
// what value of the enum to set.
90
+
// Copied from dwmapi.h
89
91
publicenumDWM_WINDOW_CORNER_PREFERENCE
90
92
{
91
93
DWMWCP_DEFAULT=0,
@@ -95,12 +97,11 @@ public partial class MainWindow : Window
95
97
}
96
98
97
99
// Import dwmapi.dll and define DwmSetWindowAttribute in C# corresponding to the native function.
### Example 2 - Rounding an app's main window in C# - WinForms
129
130
130
-
Like with WPF, for a WinForms app you'll first need to import dwmapi.dll and the DwmSetWindowAttribute function signature with [P/Invoke](/dotnet/standard/native-interop/pinvoke). You can do this in your primary Form class.
131
+
Like with WPF, for a WinForms app you'll first need to import dwmapi.dll and the DwmSetWindowAttribute function signature with P/Invoke. You can do this in your primary Form class.
131
132
132
133
```Csharp
133
134
usingSystem;
@@ -136,24 +137,26 @@ using System.Runtime.InteropServices;
136
137
publicpartialclassForm1 : Form
137
138
{
138
139
// The enum flag for DwmSetWindowAttribute's second parameter, which tells the function what attribute to set.
140
+
// Copied from dwmapi.h
139
141
publicenumDWMWINDOWATTRIBUTE
140
142
{
141
143
DWMWA_WINDOW_CORNER_PREFERENCE=33
142
-
}
144
+
}
143
145
144
146
// The DWM_WINDOW_CORNER_PREFERENCE enum for DwmSetWindowAttribute's third parameter, which tells the function
145
147
// what value of the enum to set.
148
+
// Copied from dwmapi.h
146
149
publicenumDWM_WINDOW_CORNER_PREFERENCE
147
150
{
148
151
DWMWCP_DEFAULT=0,
149
152
DWMWCP_DONOTROUND=1,
150
153
DWMWCP_ROUND=2,
151
154
DWMWCP_ROUNDSMALL=3
152
-
}
155
+
}
153
156
154
157
// Import dwmapi.dll and define DwmSetWindowAttribute in C# corresponding to the native function.
0 commit comments