You need to add the code in the button handler which is generated with the IDE as I mentioned above.
For quiting the application you can do lots of things
1. Use API DestroyWindow
2. Use API PostQuitMessage
3. Send the WM_CLOSE message to the window
4. Use EndDialog API.