Attribute VB_Name = "Utils"
Option Explicit

Private Const SPI_GETWORKAREA = 48
Private Declare Function SystemParametersInfo& Lib "User32" Alias "SystemParametersInfoA" ( _
ByVal uAction As Long, _
ByVal uParam As Long, lpvParam As Any, _
ByVal fuWinIni As Long)

Private Type RECT
  left As Long
  top As Long
  Right As Long
  Bottom As Long
End Type

Public ScreenWidth As Long
Public ScreenHeight As Long
Public ScreenLeft As Long
Public ScreenTop As Long

Public Sub ObtenirTamanyUtilPantalla()
  'Dim ScreenWidth&, ScreenHeight&, ScreenLeft&, ScreenTop&
  Dim DesktopArea As RECT
  
  Call SystemParametersInfo(SPI_GETWORKAREA, 0, DesktopArea, 0)

  ScreenHeight = (DesktopArea.Bottom - DesktopArea.top) * Screen.TwipsPerPixelY
  ScreenWidth = (DesktopArea.Right - DesktopArea.left) * Screen.TwipsPerPixelX
  ScreenLeft = DesktopArea.left * Screen.TwipsPerPixelX
  ScreenTop = DesktopArea.top * Screen.TwipsPerPixelY
End Sub

Public Sub CentraForm(frm As Form)
    frm.top = ScreenTop + ((ScreenHeight - frm.Height) / 2)
    frm.left = ScreenLeft + ((ScreenWidth - frm.Width) / 2)
End Sub
