And here it is :-). Code to position the dialog box relative to the current position of the text cursor in the Writer editor. The key is the data returned by thisComponent.currentController.viewData transferred to an array:
Array : T( 0 To 8 ) As string
(0) | string : “7435” = X cursor
(1) | string : “4369” = Y cursor
(2) | string : “140” = % magnification
(3) | string : “0” = horizontal scroll position
(4) | string : “0” = vertical scroll position
(5) | string : “16586” = LO window width.
(6) | string : “10264” = LO window height
(7) | string : “0” = maybe you know?
(8) | string : “0” = maybe you know?
and the knowledge that the given values (except magnification) are given in units com.sun.star.util.MeasureUnit.TWIP
For this, you need to take into account the height of the menu bar and toolbars from the top and the rulers (if enabled) from the top and left.
The following code will work if you first initialize the DialogLibraries.Standard.Dialog1 dialog box
Use if helpful 
sub LocationOnScreen
dim TextDoc as object
dim TextView as object
dim TextViewData as string
dim TextViewDataScope as variant
dim TextViewComponent as object
dim TextViewAccesible as object
dim TextViewAccesibleChildContext as object
dim TextViewZoom as double
dim HorizScrollOffset as long
dim VertScrollOffset as long
dim TopMenuAndToolbarsOffset as integer
dim LeftRulerOffset as integer
dim TopRulerOffset as integer
dim CursorLocation as new com.sun.star.awt.Point
dim CursorOnScreenLocation as new com.sun.star.awt.Point
dim TextViewSize as new com.sun.star.awt.Size
dim HDlgBox as integer
dim ScreenGear as object
dim i as integer
'----------------------------------'
TextDoc = thisComponent
TextView = TextDoc.currentController
TextViewData = TextView.viewData
TextViewDataScope = split(TextViewData, ";")
TextViewComponent = TextView.frame.componentWindow
TextViewAccesible = TextViewComponent.AccessibleContext
TextViewAccesibleChildContext = TextViewAccesible.getAccessibleChild(0).AccessibleContext
LeftRulerOffset = 0
TopRulerOffset = 0
on error resume next
for i = 0 to TextViewAccesibleChildContext.AccessibleChildcount - 1
with TextViewAccesibleChildContext.getAccessibleChild(i)
if .getAccessibleContext.accessibleRole = 77 then '[RULER = 77]'
if .getAccessibleContext.size.width < 50 then LeftRulerOffset = .getAccessibleContext.size.width
if .getAccessibleContext.size.height < 50 then TopRulerOffset = .getAccessibleContext.size.height
endif
end with
next
on error goto 0
TopMenuAndToolbarsOffset = TextViewAccesible.AccessibleParent.AccessibleContext.Location.Y + TextViewAccesible.Location.Y
TextViewZoom = cDbl(TextViewDataScope(2)) / 100
HorizScrollOffset = cLng(TextViewDataScope(3)) 'TWIP'
VertScrollOffset = cLng(TextViewDataScope(4)) 'TWIP'
CursorLocation.X = (cLng(TextViewDataScope(0)) - HorizScrollOffset) * TextViewZoom 'TWIP'
CursorLocation.Y = (cLng(TextViewDataScope(1)) - VertScrollOffset) * TextViewZoom 'TWIP'
TextViewSize.Width = cLng(TextViewDataScope(5)) * TextViewZoom 'TWIP'
TextViewSize.Height = cLng(TextViewDataScope(6)) * TextViewZoom 'TWIP'
ScreenGear = CreateUnoDialog(DialogLibraries.Standard.Dialog1)
CursorOnScreenLocation = TextViewComponent.convertPointToPixel(CursorLocation, com.sun.star.util.MeasureUnit.TWIP)
HDlgBox = 80
ScreenGear.setPosSize(CursorOnScreenLocation.X + LeftRulerOffset,_
CursorOnScreenLocation.Y + TopMenuAndToolbarsOffset + TopRulerOffset - HDlgBox, 50, 50,_
com.sun.star.awt.PosSize.POSSIZE)
ScreenGear.setVisible(True)
ScreenGear.execute
end sub
Finally, a note - the position of the dialog is given relative to the upper left corner of the main Writer window, if you need coordinates strictly relative to the screen you need to add the offset of this window from the top/left edge of the screen.