Well that rather depends on the environment you are writing your program in (I have already assumed Windows so ignore this if you are using *nix) straight WIN32 or MFC.
Like a said you need to subclass the button and then add your ownhandlers. This is reasonably easy in MFC your just create a subclass from the CButton class and then add your message handlers to that new class. Then in the class Wizard you have to assign a variable to the Button with a type of CButton and then manually edit the header file for the window to change the class CButton to CMyButton.
In normal windows you need to subclass the button by using GetWindowLong to get the event handler for the button, store that event handler and use SetWindowLong to insert your onw event handler for the button. In your own event handler call the original event handler except for the messages you wish to intercept in order to change the button colour.