When you click outside a window, it looses focus. When this event is triggered, you simply hide/destroy/disable/dowhateveryouwanttodowith the gui-stuff.
It works only when client choose other window, not when he click somewhere outside.
Any other ideas?