Solved

Managing Multiple Dialog Control Event Functions

Posted on 1998-08-13
8
167 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
 
LVL 2

Accepted Solution

by:
warmcat earned 50 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Show shut-down message as Windows 8 shuts down. 9 85
Strange date stored 22 106
Prevent this page from creating additional dialogs. 3 409
matchUp  challenge 6 53
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

896 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now