I found a solution. Using Windows API functions, I find the coordinates of the monitor that the parent window is located on and center the current window using those instead of the screen size returned by the environment object.
forward
global type n_monitorinfo from nonvisualobject
end type
type rect from structure within n_monitorinfo
end type
type monitorinfoex from structure within n_monitorinfo
end type
end forward
type rect from structure
long left
long top
long right
long bottom
end type
type monitorinfoex from structure
unsignedlong cbsize
rect rcmonitor
rect rcwork
unsignedlong dwflags
character szdevice[32]
end type
global type n_monitorinfo from nonvisualobject autoinstantiate
end type
type prototypes
Function long MonitorFromWindow ( &
long hwnd, &
ulong dwFlags &
) Library "user32.dll"
Function boolean GetMonitorInfo ( &
long hMonitor, &
Ref MONITORINFOEX lpmi &
) Library "user32.dll" Alias For "GetMonitorInfoW"
end prototypes
forward prototypes
public subroutine of_centeronmonitor (window aw_window)
public subroutine of_centeronwindow (window aw_parent, window aw_window)
end prototypes
public subroutine of_centeronmonitor (window aw_window);// Center the window on the current monitor
Constant ULong MONITOR_DEFAULTTONULL = 0
MONITORINFOEX mi
Boolean lb_Result
Long ll_hWnd, ll_hMonitor
Long ll_MonWidth, ll_MonHeight
Long ll_WinWidth, ll_WinHeight
Long ll_XPos, ll_YPos
ll_hWnd = Handle(aw_window)
ll_hMonitor = MonitorFromWindow(ll_hWnd, MONITOR_DEFAULTTONULL)
If ll_hMonitor > 0 Then
mi.cbSize = 104
lb_Result = GetMonitorInfo(ll_hMonitor, mi)
ll_MonWidth = PixelsToUnits(mi.rcWork.Right - mi.rcWork.Left, XPixelsToUnits!)
ll_MonHeight = PixelsToUnits(mi.rcWork.Bottom - mi.rcWork.Top, YPixelsToUnits!)
ll_WinWidth = aw_window.Width
ll_WinHeight = aw_window.Height
ll_XPos = PixelsToUnits(mi.rcWork.Left, XPixelsToUnits!) + ((ll_MonWidth - ll_WinWidth) / 2)
ll_YPos = PixelsToUnits(mi.rcWork.Top, YPixelsToUnits!) + ((ll_MonHeight - ll_WinHeight) / 2)
aw_window.X = ll_XPos
aw_window.Y = ll_YPos
End If
end subroutine
public subroutine of_centeronwindow (window aw_parent, window aw_window);// Center the window on the current monitor of the parent window
Constant ULong MONITOR_DEFAULTTONULL = 0
MONITORINFOEX mi
Boolean lb_Result
Long ll_hWnd, ll_hMonitor
Long ll_MonWidth, ll_MonHeight
Long ll_WinWidth, ll_WinHeight
Long ll_XPos, ll_YPos
ll_hWnd = Handle(aw_parent)
ll_hMonitor = MonitorFromWindow(ll_hWnd, MONITOR_DEFAULTTONULL)
If ll_hMonitor > 0 Then
mi.cbSize = 104
lb_Result = GetMonitorInfo(ll_hMonitor, mi)
ll_MonWidth = PixelsToUnits(mi.rcWork.Right - mi.rcWork.Left, XPixelsToUnits!)
ll_MonHeight = PixelsToUnits(mi.rcWork.Bottom - mi.rcWork.Top, YPixelsToUnits!)
ll_WinWidth = aw_window.Width
ll_WinHeight = aw_window.Height
ll_XPos = PixelsToUnits(mi.rcWork.Left, XPixelsToUnits!) + ((ll_MonWidth - ll_WinWidth) / 2)
ll_YPos = PixelsToUnits(mi.rcWork.Top, YPixelsToUnits!) + ((ll_MonHeight - ll_WinHeight) / 2)
aw_window.X = ll_XPos
aw_window.Y = ll_YPos
End If
end subroutine
on n_monitorinfo.create
call super::create
TriggerEvent( this, "constructor" )
end on
on n_monitorinfo.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on