Window CloseListener timing. How to stop close.

I need to stop, in some situations, the close of a popup window, ask the user and then close (or not) the window.
I inserted a CloseListener but if the user press the X button of the window the event fires but the window is already closed.
Is there any way to intercept the X button before the window is closed and prevent its closing in order to ask the user ?
Tks
Tullio

See
this forum thread
.