Page 1 of 1

Detect if a window has curved corners?

Posted: Tue Apr 09, 2024 8:10 am
by BarryG
Hi guys. I'm testing my app on Win 11 and of course it's thrown me a curve ball because Win 11 has stupid curved window corners now. :(

So, my app draws a nice line across the top of any given third-party window, which now looks stupid because the start and end of the line is not above anything anymore due to the top-left and top-right corners being round.

I can work around that if I start the line 10 pixels right and end it 20 pixels from the right side of the window, but then for borderless apps (Winamp!) the line doesn't flow across the whole window anymore.

As you can tell, I'd rather do the line dynamically depending if the window has curved corners or not. Anyone know how? I tried searching Google but it keeps coming up with ways to disable curved corners on Win 11, which isn't what I want.

Re: Detect if a window has curved corners?

Posted: Tue Apr 09, 2024 10:10 am
by breeze4me
I've looked recently, too, and there's no such general way(APIs or registry values, etc.). Nevertheless, you can get some hints from the link below.

https://learn.microsoft.com/en-us/windo ... ed-corners

Re: Detect if a window has curved corners?

Posted: Tue Apr 09, 2024 11:24 am
by Caronte3D
Maybe... checking the Windows version (build?) and if greater than X then rounded corners?

Re: Detect if a window has curved corners?

Posted: Tue Apr 09, 2024 1:02 pm
by RASHAD
Maybe a workaround :mrgreen:

Code: Select all

flags = #PB_Window_BorderLess
OpenWindow(0,10,10,400,300,"Test",Flags)
wdc = GetDC_(0)
GetWindowRect_(WindowID(0),c.RECT)
co = GetPixel_(wdc,c\left+2,c\top+2)
co2 = GetPixel_(wdc,c\left+8,c\top+2)
ReleaseDC_(0,wdc)
If co = co2
  Debug "Not Rounded"
Else
  Debug "Round Corner"
EndIf

flags = #PB_Window_SystemMenu| #PB_Window_MaximizeGadget| #PB_Window_MinimizeGadget
OpenWindow(1,400,10,400,300,"Test",Flags)
wdc = GetDC_(0)
GetWindowRect_(WindowID(1),c.RECT)
cco = GetPixel_(wdc,c\left+2,c\top+2)
cco2 = GetPixel_(wdc,c\left+8,c\top+2)
ReleaseDC_(0,wdc)
If cco = cco2
  Debug "Not Rounded"
Else
  Debug "Round Corner"
EndIf
Repeat           
  Select WaitWindowEvent()      
    Case #PB_Event_CloseWindow
          Quit = 1
    
    Case #PB_Event_Gadget
        Select EventGadget()
         Case 1            
        EndSelect
  EndSelect
Until Quit = 1
End

Re: Detect if a window has curved corners?

Posted: Tue Apr 09, 2024 7:46 pm
by chi
I had the same problem and cobbled together this demo...

Code: Select all

Procedure _DwmSetWindowAttribute(hWnd, dwAttrib, *pvAttrib, cbAttrib) : EndProcedure
Prototype _DwmSetWindowAttribute(hWnd, dwAttrib, *pvAttrib, cbAttrib)
Procedure _DwmGetWindowAttribute(hWnd, dwAttrib, *pvAttrib, cbAttrib) : EndProcedure
Prototype _DwmGetWindowAttribute(hWnd, dwAttrib, *pvAttrib, cbAttrib)

dwmapi = GetModuleHandle_(@"dwmapi")
If dwmapi = 0 : dwmapi = LoadLibrary_("dwmapi") : EndIf
Function.s{32}

WideCharToMultiByte_(#CP_ACP, 0, @"DwmSetWindowAttribute", -1, @Function, #MAX_PATH, #Null, #Null)
Global DwmSetWindowAttribute__._DwmSetWindowAttribute = GetProcAddress_(dwmapi, @Function)
If DwmSetWindowAttribute__ = 0 : DwmSetWindowAttribute__ = @_DwmSetWindowAttribute() : EndIf

WideCharToMultiByte_(#CP_ACP, 0, @"DwmGetWindowAttribute", -1, @Function, #MAX_PATH, #Null, #Null)
Global DwmGetWindowAttribute__._DwmGetWindowAttribute = GetProcAddress_(dwmapi, @Function)
If DwmGetWindowAttribute__ = 0 : DwmGetWindowAttribute__ = @_DwmGetWindowAttribute() : EndIf

#DWMWA_WINDOW_CORNER_PREFERENCE = 33
#DWMWCP_DEFAULT = 0
#DWMWCP_DONOTROUND = 1
#DWMWCP_ROUND = 2
#DWMWCP_ROUNDSMALL = 3

OpenWindow(0, 0, 0, 320, 200, "win11 corner demo", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_ScreenCentered|#PB_Window_Invisible)
ButtonGadget(0, 10, 10, 100, 30, "click me")
HideWindow(0, #False)

Repeat
  event = WaitWindowEvent()
  Select event
    Case #PB_Event_Gadget
      Select EventGadget()
          
        Case 0
          g=0
          DwmGetWindowAttribute__(WindowID(0), #DWMWA_WINDOW_CORNER_PREFERENCE, @g, SizeOf(g))
          Debug g
          Delay(1000)
          
          s=#DWMWCP_ROUNDSMALL
          DwmSetWindowAttribute__(WindowID(0), #DWMWA_WINDOW_CORNER_PREFERENCE, @s, SizeOf(s))
          DwmGetWindowAttribute__(WindowID(0), #DWMWA_WINDOW_CORNER_PREFERENCE, @g, SizeOf(g))
          Debug g
          Delay(1000)
          
          s=#DWMWCP_ROUND
          DwmSetWindowAttribute__(WindowID(0), #DWMWA_WINDOW_CORNER_PREFERENCE, @s, SizeOf(s))
          DwmGetWindowAttribute__(WindowID(0), #DWMWA_WINDOW_CORNER_PREFERENCE, @g, SizeOf(g))
          Debug g
          Delay(1000)
          
          s=#DWMWCP_DONOTROUND
          DwmSetWindowAttribute__(WindowID(0), #DWMWA_WINDOW_CORNER_PREFERENCE, @s, SizeOf(s))
          DwmGetWindowAttribute__(WindowID(0), #DWMWA_WINDOW_CORNER_PREFERENCE, @g, SizeOf(g))
          Debug g
          Delay(1000)
          
      EndSelect
  EndSelect
Until event = #PB_Event_CloseWindow

Re: Detect if a window has curved corners?

Posted: Tue Apr 09, 2024 7:56 pm
by DarkDragon
Maybe you can find something here:

https://learn.microsoft.com/en-us/windo ... i/uxtheme/

GetThemePartSize or GetThemeMetric or GetThemeBitmap with WP_FRAME or something like that? That's how firefox does control rendering.

https://github.com/mozilla/gecko-dev/bl ... emeWin.cpp

Re: Detect if a window has curved corners?

Posted: Wed Apr 10, 2024 1:35 pm
by BarryG
Thanks guys, I'll do some testing to see which suits best. :)