Solved

Trapping messages for Dynamic Combobox

Posted on 2000-03-13
12
719 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
[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
  • 5
  • 3
  • 2
  • +2
12 Comments
 
LVL 3

Expert Comment

by:mnewton022700
ID: 2614033
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
ID: 2614054
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
ID: 2614059
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
Independent Software Vendors: 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!

 

Author Comment

by:LabLord
ID: 2614067
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
ID: 2614095
What messages do you actually want to listen to?
0
 

Author Comment

by:LabLord
ID: 2614099
cbn_selchange
cbn_editchange
cbn_dropdown

but I'm sure there are probably more as I go along.
0
 
LVL 3

Expert Comment

by:mnewton022700
ID: 2614109
mnewton changed the proposed answer to a comment
0
 
LVL 3

Expert Comment

by:mnewton022700
ID: 2614281
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
ID: 2614440
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
ID: 2614441
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
ID: 2615317
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
ID: 2616383
Thanks for pointing me in the direction Mike started(and the example). Thanks to everybody else too.  

0

Featured Post

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!

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

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