We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now


Managing Multiple Dialog Control Event Functions

tds195 asked
Medium Priority
Last Modified: 2013-11-20
My dialog application has many button controls, each of which I have assigned a BN_CLICKED event handler function.
As a result, I have a very cluttered amount of functions in my Dlg class. Is there a method for reducing the amount of functions? Is it possible to group button controls that call a single event function with an index to which button was clicked? I could then use a switch-case to process individual button controls. I am interested in any sensible alternative to having one function for each button control.
Watch Question


Adjusted points to 50

The problem here is probably not one of mapping a function to a button, but the layout of your dialog.  How many buttons are we talking about?  I am sure if you meditate on the buttons' functions and any natural grouping or heirarchy within that you will find a better way than to have all those buttons in the first place.


I am creating a kind of scientific calculator that must have about 30 - 40 buttons on the dialog at any one time.
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

I was a bit late. The following is my answer.

ON_CONTROL_RANGE( wNotifyCode, id1, id2, memberFxn )


wNotifyCode   The notification code to which your handler is responding.

id1   Command ID at the beginning of a contiguous range of control IDs.

id2   Command ID at the end of a contiguous range of control IDs.

memberFxn   The name of the message-handler function to which the controls are mapped.


Use this macro to map a contiguous range of control IDs to a single message handler function for a specified Windows notification message, such as BN_CLICKED. The range of IDs starts with id1 and ends with id2. The handler is called for the specified notification coming from any of the mapped controls.

ClassWizard does not support message map ranges, so you must place the macro yourself. Be sure to put it outside the message map //{{AFX_MSG_MAP delimiters.

Sorry chensu, I hate it when that happens.  I wonder if EE have considered allowing multiple answers to questions which then take part in a 'beauty contest' by the proposer, perhaps with the option to share points?


Thanks very much, I'll go and remove all those functions.


It is OK.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.