how can i disable the "x" button of the dialog or mainwindow??

the root of my problem is when my app is still processing(loop) and the user click the "x" button it closes but it doesnt terminate the whole program the loop is still running..

thanks