I have a GUI project at work that uses MFC.
The widgets (controls) have message processing in a compile-time message map table.
I want to conditionally add controls to the form during runtime, but I'm stuck on how to append message handlers to the message map during runtime.
How do I add message handlers to the MFC message map during runtime?
Is there an alternate process that I should use?
See MFC Message Maps documentation for information about message maps.
Environment:
Windows 7 or Windows 10 (The application works on both OS)
Visual Studio 2017
If you know the range of the "ID" values you give to your added controls (as you should), then you can use the
ON_CONTROL_RANGE
entry in your message map, rather than theON_CONTROL
(which is typically used for a specific, single control). For example, for a button click on one of your controls (which has an ID in the rangeIDC_FIRST
thruIDC_LAST
, you can add the following message map entry:The message handler,
OnButtonClick
, has a very similar format to that for a single control, but with aUINT
parameter that is the ID of the control that sent the message:Feel free to ask for further clarification and/or explanation.