Page 1 of 1

UWP Caption Buttons Dimensions [Windows]

Posted: Sat Jul 16, 2022 4:15 am
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

Re: UWP Caption Buttons Dimensions [Windows]

Posted: Sat Jul 16, 2022 6:48 am
by BarryG
Thanks, Rashad. Although I had to "/4" instead of "/3" to get the actual Close button width.

Re: UWP Caption Buttons Dimensions [Windows]

Posted: Sat Jul 16, 2022 3:33 pm
by RASHAD
First post updated as per BarryG noticed
MS left space for Help Button so it is 4 buttons (MS standard) not three

Re: UWP Caption Buttons Dimensions [Windows]

Posted: Sun Jul 31, 2022 8:23 pm
by Kwai chang caine
Cool, works nice here with "Calculatrice" word :wink:
Thanks for sharing 8)