How do I get the x (close) button in the title bar to minimize the app instead of closing.

I want the user to only be able to close the program using exit on the popup menu in taskbar.

Thanks.