Figure it out finally, and this is the code.
In the second window open event:
post event ue_postopen(0,0)
In the ue_postopen event:
RECT windowRect, extendedFrameBounds;
int borderWidth
GetWindowRect(Handle(this), REF windowRect)
DwmGetWindowAttribute(Handle(this), 9, REF extendedFrameBounds, 16)
borderWidth = GetSystemMetrics(5);
x = w_main.x + w_main.width - PixelsToUnits ((windowRect.right - extendedFrameBounds.right) + (extendedFrameBounds.left - windowRect.left) + borderWidth, XPixelsToUnits!)
y = w_main.y
Declaration part:
FUNCTION long GetWindowRect(ulong hwnd, REF RECT lpRect) LIBRARY "user32.dll"
FUNCTION int GetSystemMetrics(int nIndex) LIBRARY "user32.dll";
FUNCTION long DwmGetWindowAttribute(ulong hwnd, long dwAttribute, REF RECT pvAttribute, long cbAttribute) LIBRARY "dwmapi.dll"
$PBExportHeader$rect.srs
global type rect from structure
long left
long top
long right
long bottom
end type