Solved

Trapping messages for Dynamic Combobox

Posted on 2000-03-13
12
711 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
zeroMAx challenge 20 111
building a service to accessed via telnet client, want colors ? 4 92
firstChar challenge 13 119
Making an alias 7 100
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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…
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used.

790 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