Solved

Managing Multiple Dialog Control Event Functions

Posted on 1998-08-13
8
169 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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
 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
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…
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 video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

808 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