With few exceptions, you do nothing special when the user presses the "x" to close a window. You may trap the Closing event to pop up a message to the user, such as "Are you sure you want to Close?".
The applications Ive seen that use the "x" to minimize to the tray are definitely exceptions, such as WinAmp or an instant messenger. If youre coding something similarly complex, Id get a good understanding of the language before proceeding. If its a standard Windows app, the "x" just closes the form, something that happens automatically so you wont need any code.
-Nerseus