Is there a general rule of what kind of code construction needs to be written to catch the pressing of a certain button, selecting text from a multiple list, changing the style of a drop-down menu, etc.
The general rules that you are referring to would be documentation for the messages and notifications that the various controls in the Windows API use. Its a large topic but the documentation is here - window-controls
As an example, the behavior of button controls is documented here - buttons
Carefully read the documentation for BN_CLICKED, WM_COMMAND and CreateWindow. In particular, carefully review the table in the Remarks section of the CreateWindow documentation. Compare these details with the posted code.
With respect to the posted code -
- CreateWindow does not assign control identifiers to the two buttons created in the WM_CREATE handler. This identifier is passed as the hMenu parameter.
- CreateWindow returns a window handle (an HWND). It should not be cast to an int.
- The switch statement in which the ID_FILE_EXIT menu command is handled appears to be outside of the WM_COMMAND handler.
Finally, handling messages in a window procedure can be simplified by using "message crackers". These are macros that will split out the relevant parts of window messages and make it easier to handle them. They are located in the windowsx.h header.