Solved

Trapping messages for Dynamic Combobox

Posted on 2000-03-13
12
703 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
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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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 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.

777 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