Solved

Trapping messages for Dynamic Combobox

Posted on 2000-03-13
12
670 Views
Last Modified: 2013-11-20
I have created N number of combo box's dynamically, but didn't derive my own ccombobox class.  I am not sure how to trap the messages for the individual combo box's that I might have created.  Do I have to derive my own class off of CComboBox to do this? or can I trap them somehow in pre-translate message.
0
Comment
Question by:LabLord
  • 5
  • 3
  • 2
  • +2
12 Comments
 
LVL 3

Expert Comment

by:mnewton022700
Comment Utility
You can listen to many of the messages for the individual combo boxes through the message map of the dialog (the one containing the combo boxes).

Have a look at all the ON_CBN_ macros in MSDN.

ON_CBN_CLOSEUP( <id>, <memberFxn> ) afx_msg void memberFxn( )
ON_CBN_DBLCLK( <id>, <memberFxn> ) afx_msg void memberFxn( );
ON_CBN_DROPDOWN( <id>, <memberFxn> ) afx_msg void memberFxn( );
ON_CBN_EDITCHANGE( <id>, <memberFxn> ) afx_msg void memberFxn( );
ON_CBN_EDITUPDATE( <id>, <memberFxn> ) afx_msg void memberFxn( );
ON_CBN_ERRSPACE( <id>, <memberFxn> ) afx_msg void memberFxn( );
ON_CBN_KILLFOCUS( <id>, <memberFxn> ) afx_msg void memberFxn( );
ON_CBN_SELCHANGE( <id>, <memberFxn> ) afx_msg void memberFxn( );
ON_CBN_SELENDCANCEL( <id>, <memberFxn> ) afx_msg void memberFxn( );
ON_CBN_SELENDOK( <id>, <memberFxn> ) afx_msg void memberFxn( );
ON_CBN_SETFOCUS( <id>, <memberFxn> ) afx_msg void memberFxn( );

0
 
LVL 11

Expert Comment

by:mikeblas
Comment Utility
What I think you really want is ON_COMMAND_RANGE(). Otherwise, you'll have to code an ON_CBN_SOMETHING() for each and every one of your boxes, in addition to each and every message.

Is the list of comboboxes dynamic? That is, do you know how many you'll have at compile time, or not until runtime? If the list is dynamic, you'll need a different solution altogether.

..B ekiM
0
 
LVL 3

Expert Comment

by:mnewton022700
Comment Utility
I just noticed the 'dynamic' part of your question. Do you know the ID's of the combo boxes at compile time? If you do then my answer above should be fine. If not, then you will need to derive your own combo box class.
0
 

Author Comment

by:LabLord
Comment Utility
I do not know the ids at compile time...  I can go derive the class, but I have no idea how/where to trap those messages within my combobox class(i.e. what functions to overload)
0
 
LVL 3

Expert Comment

by:mnewton022700
Comment Utility
What messages do you actually want to listen to?
0
 

Author Comment

by:LabLord
Comment Utility
cbn_selchange
cbn_editchange
cbn_dropdown

but I'm sure there are probably more as I go along.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 3

Expert Comment

by:mnewton022700
Comment Utility
mnewton changed the proposed answer to a comment
0
 
LVL 3

Expert Comment

by:mnewton022700
Comment Utility
Here's one way to do it:

In your CCombobox derived class (CMyComboBox) add a method onSelChanged.

In your dialog class, override preTranslateMessage. If the message is CBN_SELCHANGE, get the window with the current focus, cast it to a CMyComboBox,
and call onSelChanged on it.

Do the same thing for the other messages you want to listen to.
0
 

Expert Comment

by:thinh
Comment Utility
Hi LabLord,

I guess you could have a range of ids for your dynamic comboBox.  When you need to create a combobox, you could assign one of those value to your combobox.

Example:

Ids for 10 comboBox: range from 1000 to 1009.

First comboBox id: 1000
2nd.. 1001
...
Last.. 1009

And you can map the messages and take a look at those ids in oder to  perform the actions.


Thinh.
0
 

Expert Comment

by:thinh
Comment Utility
Hi LabLord,

I guess you could have a range of ids for your dynamic comboBox.  When you need to create a combobox, you could assign one of those value to your combobox.

Example:

Ids for 10 comboBox: range from 1000 to 1009.

First comboBox id: 1000
2nd.. 1001
...
Last.. 1009

And you can map the messages and take a look at those ids in oder to  perform the actions.


Thinh.
0
 
LVL 1

Accepted Solution

by:
mahno earned 100 total points
Comment Utility
Hi LabLord,

U can create Ur class, for example CMyComboBox : public CComboBox,
And override methods OnSelchange, OnDropdown ..., by following way:

void CMyComboBox::OnSelchange()
{
  //wParam contain action code (for example OnSelchange = 0, OnDropdown = 1, etc)
  //lParam contain pointer to CMyComboBox
  GetParent()->SendMessage(WM_USER + 0x100/*for example*/, 0, (LPARAM)(DWORD)this);
}

void CMyComboBox::OnDropdown()
{
  //wParam contain action code (for example OnSelchange = 0, OnDropdown = 1, etc)
  //lParam contain pointer to CMyComboBox
  GetParent()->SendMessage(WM_USER + 0x100/*for example*/, 1, (LPARAM)(DWORD)this);
}

//...


....And in Ur dialog class add:

BEGIN_MESSAGE_MAP(CMyComboBox, CComboBox)
  //...
  ON_MESSAGE(WM_USER+0x100, OnCBChange)
END_MESSAGE_MAP()

//...

void CMyDlg::OnCBChange(WPARAM wParam, LPARAM lParam) {
  //Get pointer to ComboBox witch send this messge
  CMyComboBox *cb = (CMyComboBox *)(DWORD)lParam;
  //Get Action code
  int nActionCode = wParam;

  //cb - pointer to combobox
  swich (nActionCode) {
    case 0: //Handle OnSelchange for "cb"
      break;
    case 1: //Handle OnDropdown for "cb"
      break;
  }
}


....and in *Dlg*.h file add:

  //{{AFX_MSG(CCallRoutingManagerDlg)
  //...
  afx_msg void OnCBChange(WPARAM wParam, LPARAM lParam);
  //}}AFX_MSG

Hope that helps,
  mahno
0
 

Author Comment

by:LabLord
Comment Utility
Thanks for pointing me in the direction Mike started(and the example). Thanks to everybody else too.  

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: 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 …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

763 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

6 Experts available now in Live!

Get 1:1 Help Now