Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS General Discussion » ComboBox Control Message in Toolbar Collapse All
Subject Author Date
Fransiscus Herry Mar 7, 2007 - 2:34 AM

Hi Prof-UIS,

I’d like to know how to get a message from a control inserted in a Toolbar? I have put a combobox in a toolbar control, however, i do not know how to get the message everytime i change the sel on that combo box. I need some explanation. This also happend when i put a combobox into CExtToolControlBar.... please need your advice.

regards,

Fransiscus Herry Mar 8, 2007 - 9:06 PM

Hi Suhai,

Thank you so much for your help!...Your code is just work fine. I am testing the other control such as slider which is i just follow the implementation as in Prof-uis control project. For a suggestion, probably it would be better if a simple project example profided for novice programmer like me. But anyway thank you. Prof-uis toolkit is getting interesting :)

regards,

Suhai Gyorgy Mar 7, 2007 - 8:04 AM

This is my code for this problem.
In MainFram.h:

class CToolBarCombo : public CExtComboBox
{
public:
	DECLARE_DYNAMIC( CToolBarCombo )
	CToolBarCombo();
	int SetCurSel(int nSelect);
	virtual ~CToolBarCombo();
protected:
	int iSelectedIndex;
	afx_msg void OnReflectCbnSelEndOK();
	DECLARE_MESSAGE_MAP()
}; // class CToolBarCombo
...
class CMainFrame : public CMDIFrameWnd
{
...
protected:
	CToolBarCombo	m_wndComboInToolbar;
...
}
In MainFrm.cpp:
/////////////////////////////////////////////////////////////////////////////
// CToolBarCombo
 
IMPLEMENT_DYNAMIC( CToolBarCombo, CExtComboBox )
 
CToolBarCombo::CToolBarCombo()
	: iSelectedIndex(-1)
{
}
 
CToolBarCombo::~CToolBarCombo()
{
}
 
BEGIN_MESSAGE_MAP( CToolBarCombo, CExtComboBox )
	//{{AFX_MSG_MAP(CToolBarCombo)
	//}}AFX_MSG_MAP
	ON_CONTROL_REFLECT(CBN_SELENDOK,OnReflectCbnSelEndOK)
END_MESSAGE_MAP()
 
int CToolBarCombo::SetCurSel( int nSelect )
{
	if ( nSelect != iSelectedIndex) {
		iSelectedIndex= nSelect;
		return CExtComboBox::SetCurSel( nSelect );
	}
	return CB_ERR;
}
 
void CToolBarCombo::OnReflectCbnSelEndOK()
{
	ASSERT_VALID( this );
	CMainFrame *pFrame = reinterpret_cast<CMainFrame *>(AfxGetMainWnd());
	if (pFrame == NULL) return;
	pFrame->OnToolbarComboSelChanged(GetCurSel());
}
 
...
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
...
	if( (! m_wndToolBar.Create( NULL, this, AFX_IDW_TOOLBAR ) )
		||	(! m_wndToolBar.LoadToolBar( IDR_MAINFRAME ) )
		)
	{
		TRACE0("Failed to create main toolbar\n");
		return -1;      // fail to create
	}
 
	if ( !m_wndComboInToolbar.Create( WS_CHILD|WS_VISIBLE|CBS_HASSTRINGS|CBS_DROPDOWNLIST,
		CRect(0,0,140,200),
		&m_wndToolBar,
		ID_TOOLBAR_COMBO
		)
	)
	{
		TRACE( "Failed to create m_wndComboInToolbar\n" );
		return -1; // fail to create
	}
 
	VERIFY( m_wndToolBar.SetButtonCtrl( m_wndToolBar.CommandToIndex( ID_TOOLBAR_COMBO ), &m_wndComboInToolbar ) );
	m_wndComboInToolbar.SetFont( CFont::FromHandle( (HFONT)::GetStockObject(DEFAULT_GUI_FONT) ) );
	m_wndComboInToolbar.SetItemHeight( -1, m_wndComboInToolbar.GetItemHeight(-1) - 1 );
	for (int i = 0; i < NO_OF_COMBO_ITEMS; i++){
		m_wndComboInToolbar.AddString( strSomeString );
	}
...
}
...
void CMainFrame::OnToolbarComboSelChanged(int nSelected)
{
//any code you need to handle combo selection changed
}