Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Managing Multiple Dialog Control Event Functions

Posted on 1998-08-13
8
Medium Priority
?
173 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: 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!

 
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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…

705 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