Jump to content

Rounded corners on Windows 11


Recommended Posts

Hi

 

I don't know if this is the right place for this but I thought it might come in useful to someone and I couldn't find it while I was searching for posts that address it.

This:

Global $exampleGUI = GUICreate("Rounded corners", 400, 300, -1, -1)

Will automatically get rounded corners in Windows 11...

But this:

Global $exampleGUI = GUICreate("Rounded corners", 400, 300, -1, -1, $WS_POPUP)

Will not.

I usually like to ditch the windows title bar and replace it with my own, so it was annoying, that on Windows 11, my stuff didn't look the part.

The trick is to use DwmSetWindowAttribute to set DWMWA_WINDOW_CORNER_PREFERENCE (33) to DWMWCP_ROUND (2) as explained here:

Apply rounded corners in desktop apps for Windows 11

I modified the function in WinAPIGdi.au3 to accept 33 as a valid parameter and used the function from there:

Func _WinAPI_DwmSetWindowAttribute($hWnd, $iAttribute, $iData)
    Switch $iAttribute
        Case 2, 3, 4, 6, 7, 8, 10, 11, 12, 33

        Case Else
            Return SetError(1, 0, 0)
    EndSwitch

    Local $aCall = DllCall('dwmapi.dll', 'long', 'DwmSetWindowAttribute', 'hwnd', $hWnd, 'dword', $iAttribute, _
            'dword*', $iData, 'dword', 4)
    If @error Then Return SetError(@error, @extended, 0)
    If $aCall[0] Then Return SetError(10, $aCall[0], 0)

    Return 1
EndFunc   ;==>_WinAPI_DwmSetWindowAttribute

Example:

#include <WinAPIGdi.au3>
#include <GUIConstantsEx.au3>
#include <Windowsconstants.au3>

Global $exampleGUI = GUICreate("Rounded corners", 400, 300, -1, -1, $WS_POPUP)
_WinAPI_DwmSetWindowAttribute($exampleGUI,33,2)

Local $label = GUICtrlCreateLabel(" This is an example.", 50, 150,200, 50)

GUISetState(@SW_SHOW, $exampleGUI)
While 1
$msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
                    Exit
    EndSelect
WEnd

 

Link to post
Share on other sites
  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...