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 I've seen that use the "x" to minimize to the tray are definitely exceptions, such as WinAmp or an instant messenger. If you're coding something similarly complex, I'd get a good understanding of the language before proceeding. If it's a standard Windows app, the "x" just closes the form, something that happens automatically so you won't need any code.
-Nerseus