Solved

Managing Multiple Dialog Control Event Functions

Posted on 1998-08-13
8
166 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
Comment Utility
Adjusted points to 50
0
 
LVL 2

Expert Comment

by:warmcat
Comment Utility
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
Comment Utility
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
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 23

Expert Comment

by:chensu
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks very much, I'll go and remove all those functions.
0
 
LVL 23

Expert Comment

by:chensu
Comment Utility
warmcat,

It is OK.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

16 Experts available now in Live!

Get 1:1 Help Now