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

x
?
Solved

Trapping messages for Dynamic Combobox

Posted on 2000-03-13
12
Medium Priority
?
756 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

721 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