LabLord
asked on
Trapping messages for Dynamic Combobox
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.
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
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
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.
ASKER
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)
What messages do you actually want to listen to?
ASKER
cbn_selchange
cbn_editchange
cbn_dropdown
but I'm sure there are probably more as I go along.
cbn_editchange
cbn_dropdown
but I'm sure there are probably more as I go along.
mnewton changed the proposed answer to a comment
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.
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.
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.
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.
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for pointing me in the direction Mike started(and the example). Thanks to everybody else too.
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( );