如何获取子类组合框消息以将其消息转发到父工具栏?

时间:2015-08-17 00:54:54

标签: c++ mfc

我在工具栏上有五个组合框,我想处理他们的消息和通知,特别是在子类工具栏类中的CBN_SELCHANGE通知。我尝试了几种方法无济于事。工具栏和组合框类的定义如下所示:

#pragma once
// CMyComboBox

class CMyComboBox : public CComboBox
{
    DECLARE_DYNAMIC(CMyComboBox)

public:
    CMyComboBox();
    virtual ~CMyComboBox();

protected:
    DECLARE_MESSAGE_MAP()
public:
    afx_msg BOOL OnCbnSelchange();
    //afx_msg void OnCbnSelchange();
};





// MyComboBox.cpp : implementation file
//

#include "stdafx.h"
#include "MyComboBox.h"


IMPLEMENT_DYNAMIC(CMyComboBox, CComboBoxEx)

CMyComboBox::CMyComboBox()
{

}

CMyComboBox::~CMyComboBox()
{
}


BEGIN_MESSAGE_MAP(CMyComboBox, CComboBoxEx)
    //ON_CONTROL_REFLECT(CBN_SELCHANGE, &CMyComboBox::OnCbnSelchange)
    ON_CONTROL_REFLECT_EX(CBN_SELCHANGE, &CMyComboBox::OnCbnSelchange)
END_MESSAGE_MAP()



// CMyComboBox message handlers


BOOL CMyComboBox::OnCbnSelchange()
{
    return FALSE;
}


#pragma once
#include "MyStatic.h"
#include "MyComboBox.h"

// MyToolBar

class CMyToolBar : public CMFCToolBar
{
    DECLARE_DYNAMIC(CMyToolBar)

public:
    CMyToolBar();
    virtual ~CMyToolBar();

public:
    void EmbedControls();
    //CMyStatic m_pStatic3;
    CMyComboBox m_Combo1,m_Combo2,m_Combo3,m_Combo4,m_Combo5;
    CWnd m_pEdit1;
    CFont m_font;
private:
public:
    afx_msg void OnCbnSelchange1();
    afx_msg void OnCbnSelchange2();
    afx_msg void OnCbnSelchange3();
    afx_msg void OnCbnSelchange4();
    afx_msg void OnCbnSelchange5();
protected:
    DECLARE_MESSAGE_MAP()
//public:
    //afx_msg void OnSize(UINT nType, int cx, int cy);
};




IMPLEMENT_DYNAMIC(CMyToolBar, CMFCToolBar)

CMyToolBar::CMyToolBar()
{
}

CMyToolBar::~CMyToolBar()
{
}


BEGIN_MESSAGE_MAP(CMyToolBar, CMFCToolBar)
    ON_CBN_SELCHANGE(ID_COMBO1, &CMyToolBar::OnCbnSelchange1)
    ON_CBN_SELCHANGE(ID_COMBO2, &CMyToolBar::OnCbnSelchange2)
    ON_CBN_SELCHANGE(ID_COMBO3, &CMyToolBar::OnCbnSelchange3)
    ON_CBN_SELCHANGE(ID_COMBO4, &CMyToolBar::OnCbnSelchange4)
    ON_CBN_SELCHANGE(ID_COMBO5, &CMyToolBar::OnCbnSelchange5)
    //ON_WM_SIZE()
END_MESSAGE_MAP()



// MyToolBar message handlers
#include "stdAfx.h"
#include "MyToolBar.h"
void CMyToolBar::OnCbnSelchange1()
{
  //Operation1
}

void CMyToolBar::OnCbnSelchange2()
{
 //Operation1
}

void CMyToolBar::OnCbnSelchange2()
{
 //Operation2
}

void CMyToolBar::OnCbnSelchange3()
{
 //Operation3
}

void CMyToolBar::OnCbnSelchange4()
{
 //Operation4
}

void CMyToolBar::OnCbnSelchange5()
{
 //Operation5
}

void CMyToolBar:EmbedControls()
{
//Creates five comboboxes of type MyComboBox and embeds then on the tool bar
}

问题是操作1到4都没有执行,表示选择更改消息没有到达工具栏。在运行时进入代码也可以确认这一点。

那么,如何让组合框将消息转发到工具栏以进行处理?

0 个答案:

没有答案