Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Managing Multiple Dialog Control Event Functions

Posted on 1998-08-13
8
Medium Priority
?
176 Views
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.
0
Comment
Question by:tds195
  • 3
  • 3
  • 2
8 Comments
 

Author Comment

by:tds195
ID: 1320713
Adjusted points to 50
0
 
LVL 2

Expert Comment

by:warmcat
ID: 1320714
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.
0
 

Author Comment

by:tds195
ID: 1320715
I am creating a kind of scientific calculator that must have about 30 - 40 buttons on the dialog at any one time.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 2

Accepted Solution

by:
warmcat earned 200 total points
ID: 1320716
Oh well.

Remove all the handlers from your buttons, but ensure each button has a unique command ID, eg IDC_BUTTON_PLUS or something.

Use classwizard to override the OnCommand() member of your dialog (NB: there is no WM_COMMAND override available in classwizard, it explicitly says OnCommand)

In your overridden CMyDialog::OnCommand(), stick the following:

BOOL CSnoopyDlg::OnCommand(WPARAM wParam, LPARAM lParam)
{

  if(lParam) {
     switch((WORD)wParam) {
       case IDC_BUTTON_PLUS: { TRACE("Plus!"); break; }
        // ...  etc, note no default and fallthrough to CDialog::OnCommand()
     }
  }

  return CDialog::OnCommand(wParam, lParam);
}

Regards,

-Andy

0
 
LVL 23

Expert Comment

by:chensu
ID: 1320717
I was a bit late. The following is my answer.

ON_CONTROL_RANGE
ON_CONTROL_RANGE( wNotifyCode, id1, id2, memberFxn )

Parameters

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.

Remarks

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.


0
 
LVL 2

Expert Comment

by:warmcat
ID: 1320718
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?
0
 

Author Comment

by:tds195
ID: 1320719
Thanks very much, I'll go and remove all those functions.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1320720
warmcat,

It is OK.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Suggested Courses
Course of the Month12 days, 3 hours left to enroll

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question