New features in WinAPI on Windows 11
With the release of the new operating system, Microsoft’s design priorities have changed – now the interface has animations, and in general it has become less sharp. In this article, I will share some of the tricks that I encountered while working with WinAPI.
All the options in this article appeared with the release of the assembly 22000. And are used by DWM by calling the function
Mica is a new style in Windows 11 that has replaced Fluent. According to Microsoft, it was designed to give the user the best performance. Unlike its predecessor, Mica can be enabled in WinApi applications without special crutches.
This can be done using a variable that is not officially documented –
DWMWA_MICA_EFFECT. She matters
Here’s how to use it in practice:
#define DWMWA_MICA_EFFECT DWORD(1029); // Mica int useMica = 1; DwmSetWindowAttribute(hwnd, DWMWA_MICA_EFFECT, &useMica, sizeof(int));
Unfortunately, Microsoft has informed that this method will not work in future releases of Windows.
Therefore, starting from assembly 22523was replaced by another method, with a small bonus in the form of new styles:
const auto DWMSBT_DISABLE = 1 // Default const auto DWMSBT_MAINWINDOW = 2 // Mica const auto DWMSBT_TRANSIENTWINDOW = 3 // Acrylic const auto DWMSBT_TABBEDWINDOW = 4 // Tabbed DwmSetWindowAttribute(hwnd, DWMWA_SYSTEMBACKDROP_TYPE, &DWMSBT_MAINWINDOW, sizeof(int));
The parameter has no restrictions on use, so it can be pulled on any window. (Microsoft took advantage of this and finally redesigned File Explorer a bit)
For C#, for example, there are several libraries aimed at simulating controls from Mica in WPF.
Change window color
Continuing the list of changes in Dwm… Next comes a small set of options for changing the color of the title bar, the text on it, and the borders of the window itself.
DWMWA_CAPTION_COLOR– Header color
DWMWA_TEXT_COLOR– Header text color
DWMWA_BORDER_COLOR– Window border color
Here is a small usage example:
#define DWMWA_BORDER_COLOR DWORD(34) #define DWMWA_TEXT_COLOR DWORD(36) #define DWMWA_CAPTION_COLOR DWORD(35) auto caption = RGB(45, 80, 45); auto text = RGB(20, 180, 180); auto border = RGB(255, 0, 0); DwmSetWindowAttribute(hwnd, DWMWA_CAPTION_COLOR, &caption, sizeof(COLORREF)); DwmSetWindowAttribute(hwnd, DWMWA_TEXT_COLOR, &text, sizeof(COLORREF)); DwmSetWindowAttribute(hwnd, DWMWA_BORDER_COLOR, &border, sizeof(COLORREF));
As a result, such a designer’s nightmare can turn out …
By the way, this innovation has been used by the Telegram desktop client for a long time.
It is worth saying that before all these parameters appeared, you had to create your own window design, draw buttons, add WM_NCHITTEST message processing to it, and also solve problems with Aero animation … In general, life has become easier.
Don’t like the new rounded windows in Windows 11? Then Microsoft has a solution – parameter
It has three whole meanings:
#define DWMWA_WINDOW_CORNER_PREFERENCE DWORD(33); const auto DWMWCP_DONOTROUND = 1; // Rectangular const auto DWMWCP_ROUND = 2; // Default const auto DWMWCP_ROUNDSMALL = 3; // Semi-rounded DwmSetWindowAttribute(hwnd, DWMWA_WINDOW_CORNER_PREFERENCE, &DWMWCP_DONOTROUND, sizeof(int));
This setting may have been added by Microsoft for personal use. After all, if you expand the window to half or a quarter of the screen, then its corners will also become square.
These are not all innovations in customizing the appearance of windows. “Behind the scenes” there were parameters for changing the thickness of the border, and mirroring the entire window. But these are very specific features that I decided not to talk about.
I hope this article will be useful for someone.