UWP Caption Buttons Dimensions [Windows]

Share your advanced PureBasic knowledge/code with the community.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 5012
Joined: Sun Apr 12, 2009 6:27 am

UWP Caption Buttons Dimensions [Windows]

Post by RASHAD »

Hi

Code: Select all

Prototype DwmGetWindowAttribute(hWnd,dwAttribute.l,*pvAttribute,cbAttribute.l)
Global DwmGWA.DwmGetWindowAttribute,hWnd,title${#MAX_PATH},class${#MAX_PATH}
#DWMWA_CLOAKED = 14

Global handle

Procedure GetWinHandle(pro$)
  hWnd = FindWindow_(0, 0)
  Repeat
    hWnd = GetWindow_(hWnd, #GW_HWNDNEXT)
    If hWnd And IsWindowVisible_(hWnd) And GetWindowLongPtr_(hWnd, #GWL_HWNDPARENT) = 0
      GetWindowText_(hWnd, @title$, #MAX_PATH)
      GetClassName_(hWnd,@class$,#MAX_PATH)
      If class$ = "ApplicationFrameWindow" Or class$ = "Windows.UI.Core.CoreWindow"
        dll = OpenLibrary(#PB_Any,"DWMAPI.DLL")
        If dll
          DwmGWA = GetFunction(dll,"DwmGetWindowAttribute")
          If DwmGWA
            DwmGWA(hWnd,#DWMWA_CLOAKED,@Cloaked,SizeOf(Cloaked))
            If Cloaked = 0 And title$ = pro$
              handle = hwnd
              ProcedureReturn handle
            EndIf
          EndIf
          CloseLibrary(dll)
        EndIf
      EndIf
    EndIf
  Until hWnd = 0
  ProcedureReturn #False
EndProcedure

RunProgram("Calc.exe")
Delay(1000)
GetWinHandle("Calculator")

If Handle
  GetWindowRect_(handle,r.RECT)
  hWndOver = WindowFromPoint_((r\top+5) << 32 + r\right-20)
  GetWindowRect_(hWndOver,r.RECT)
  Debug "Button Width : "+Str((r\right - r\left) /4)
  Debug "Button Height : "+Str(r\bottom-r\top)
  
  SendMessage_(Handle, #WM_SYSCOMMAND, #SC_CLOSE, 0)
Else
  MessageRequester("Info","Not a UWP application",#MB_OK|#MB_ICONINFORMATION)
EndIf


Edit : Modified
Last edited by RASHAD on Sat Jul 16, 2022 3:29 pm, edited 1 time in total.
Egypt my love
BarryG
Addict
Addict
Posts: 4269
Joined: Thu Apr 18, 2019 8:17 am

Re: UWP Caption Buttons Dimensions [Windows]

Post by BarryG »

Thanks, Rashad. Although I had to "/4" instead of "/3" to get the actual Close button width.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 5012
Joined: Sun Apr 12, 2009 6:27 am

Re: UWP Caption Buttons Dimensions [Windows]

Post by RASHAD »

First post updated as per BarryG noticed
MS left space for Help Button so it is 4 buttons (MS standard) not three
Egypt my love
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5526
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: UWP Caption Buttons Dimensions [Windows]

Post by Kwai chang caine »

Cool, works nice here with "Calculatrice" word :wink:
Thanks for sharing 8)
ImageThe happiness is a road...
Not a destination
Post Reply