From: William Dauchy on
Hello,

I've 20 combobox in a window.
I've mapped ON_CBN_SELCHANGE message on each one, with a method for
each one too.
But the code is almost the same in each method.
I want to know if it's possible to recover the ID of the combobox when
I'm receiving the ON_CBN_SELCHANGE message, to make a single method.

The aim is something like that :
BEGIN_MESSAGE_MAP(WizardMapRoad, CPropertyPage)
ON_CBN_SELCHANGE(IDC_COMBO1, &MyWindow::OnCbnSelchangeCombo)
ON_CBN_SELCHANGE(IDC_COMBO2, &MyWindow::OnCbnSelchangeCombo)
ON_CBN_SELCHANGE(IDC_COMBO3, &MyWindow::OnCbnSelchangeCombo)
[...]
END_MESSAGE_MAP()

MyWindow::OnCbnSelchangeCombo()
{
id = [a cool method to get the ID of the combobox];
this->foo[id] = "bar";
}

Regards,
--
William
From: Victor on
Yes, it is possible.
You should use the ON_CONTROL_RANGE macro for all of your comboboxes. See
the MSDN artice "Handlers for Message-Map Ranges" in
http://msdn2.microsoft.com/en-us/library/84xtde24.aspx

Victor

"William Dauchy" wrote:

> Hello,
>
> I've 20 combobox in a window.
> I've mapped ON_CBN_SELCHANGE message on each one, with a method for
> each one too.
> But the code is almost the same in each method.
> I want to know if it's possible to recover the ID of the combobox when
> I'm receiving the ON_CBN_SELCHANGE message, to make a single method.
>
> The aim is something like that :
> BEGIN_MESSAGE_MAP(WizardMapRoad, CPropertyPage)
> ON_CBN_SELCHANGE(IDC_COMBO1, &MyWindow::OnCbnSelchangeCombo)
> ON_CBN_SELCHANGE(IDC_COMBO2, &MyWindow::OnCbnSelchangeCombo)
> ON_CBN_SELCHANGE(IDC_COMBO3, &MyWindow::OnCbnSelchangeCombo)
> [...]
> END_MESSAGE_MAP()
>
> MyWindow::OnCbnSelchangeCombo()
> {
> id = [a cool method to get the ID of the combobox];
> this->foo[id] = "bar";
> }
>
> Regards,
> --
> William
>
From: foobar on

You can use ON_CONTROL_RANGE macro to get the control to single
function
if any of the combo box's selection changes.

For an example of handling message map ranges you can refer to
http://msdn2.microsoft.com/de-de/library/84xtde24.aspx

If for some reason, range macros cannot be used in your case,
I think OnCmdMsg method of parent window can be overridden to find
which combo box has
changed its selection.

HTH.

On Apr 23, 1:51 pm, William Dauchy <wdau...(a)gmail.com> wrote:
> Hello,
>
> I've 20 combobox in a window.
> I've mapped ON_CBN_SELCHANGE message on each one, with a method for
> each one too.
> But the code is almost the same in each method.
> I want to know if it's possible to recover the ID of the combobox when
> I'm receiving the ON_CBN_SELCHANGE message, to make a single method.
>
> The aim is something like that :
> BEGIN_MESSAGE_MAP(WizardMapRoad, CPropertyPage)
> ON_CBN_SELCHANGE(IDC_COMBO1, &MyWindow::OnCbnSelchangeCombo)
> ON_CBN_SELCHANGE(IDC_COMBO2, &MyWindow::OnCbnSelchangeCombo)
> ON_CBN_SELCHANGE(IDC_COMBO3, &MyWindow::OnCbnSelchangeCombo)
> [...]
> END_MESSAGE_MAP()
>
> MyWindow::OnCbnSelchangeCombo()
> {
> id = [a cool method to get the ID of the combobox];
> this->foo[id] = "bar";
>
> }
>
> Regards,
> --
> William

From: William Dauchy on
On Apr 23, 11:33 am, foobar <somefoo...(a)gmail.com> wrote:
> You can use ON_CONTROL_RANGE macro to get the control to single
> function
> if any of the combo box's selection changes.

Victor & Foobar > Lot of thank's for your help. It seems to be what I
wanted!

Regards,
--
William

From: Sheng Jiang[MVP] on
You can also create a combobox class and handle CBN_SELCHANGE through
message reflection, then modify the control class in your dialog header
file.

For more information, see MFC tech notes TN062: Message Reflection for
Windows Controls (MFC)
..

--
Sheng Jiang
Microsoft MVP in VC++
"William Dauchy" <wdauchy(a)gmail.com> wrote in message
news:020d5815-519a-4d7f-921d-24b8c2bdf33e(a)j22g2000hsf.googlegroups.com...
> Hello,
>
> I've 20 combobox in a window.
> I've mapped ON_CBN_SELCHANGE message on each one, with a method for
> each one too.
> But the code is almost the same in each method.
> I want to know if it's possible to recover the ID of the combobox when
> I'm receiving the ON_CBN_SELCHANGE message, to make a single method.
>
> The aim is something like that :
> BEGIN_MESSAGE_MAP(WizardMapRoad, CPropertyPage)
> ON_CBN_SELCHANGE(IDC_COMBO1, &MyWindow::OnCbnSelchangeCombo)
> ON_CBN_SELCHANGE(IDC_COMBO2, &MyWindow::OnCbnSelchangeCombo)
> ON_CBN_SELCHANGE(IDC_COMBO3, &MyWindow::OnCbnSelchangeCombo)
> [...]
> END_MESSAGE_MAP()
>
> MyWindow::OnCbnSelchangeCombo()
> {
> id = [a cool method to get the ID of the combobox];
> this->foo[id] = "bar";
> }
>
> Regards,
> --
> William