Hey, I am doing a little program that is connected to the database and keeps track of users using the program also, for example when someone opens the program it adds one to the users number in the database, what I need to do is to see when user presses the red close button on my program(the normal X on the right corner) to minus one from the users, how would I do that, is there like onExit event or something?

If you are using the MFC or Win32 APIs, any of the OnClose , DestroyWindow functions, or the WM_CLOSE event can be used.
Read the documentation to find the best one for your needs.

Even if you are using some other development environment with custom APIs, they usually have functions with similar names.