MATLAB: How to stop MATLAB from changing the focus to a random window after closing a dialog

dialoggui

Hi,
when I create a simple dialog like:
dialog('name','My Dialog');
and then close it using the "X" an arbitrary other window (not another MATLAB figure, just a random program like outlook) gets the focus.
strange :-S
Any ideas?
Greetings
Jeffrey

Best Answer

Hmmm. This seems to happen if the 'WindowStyle' is 'Modal':
figure('windowstyle','modal')
Apparently setting the CloseRequestFcn to delete(src) fixes it:
figure('windowstyle','modal','closerequestfcn',@(src,evt)delete(src))