I want to mimic the dialog that is uses for autocompletion when you type code in the front end. One of the main difficulties is to open a dialog directly under the cursor position as it is done by the front end

Simple example is
CreateDialog[Style["Empty Box", 30, Red],
WindowFrame -> "Frameless",
WindowMargins -> Automatic]
Now you can use WindowMargins
to put the dialog everywhere you like on the screen but I see no direct way to extract the current cursor position.
Does someone know how the front end achieves this for autocompletion or how one can mimic this?
Cheers
Patrick
Btw, there is a strongly related question of mine on Stack Exchange.