Put a CComboBox control on CToolBar
来源:互联网 发布:淘宝折扣软件 编辑:程序博客网 时间:2024/06/01 08:30
This tutiual is about how to put a CComboBox control on CToolBar.look at the next description.
First of all,you should create a CcomboBoxBar class derived from CToolBar like this:
ComboToolBar.h:
class CComboToolBar : public CToolBar// CToolBar----->you must use CToolBar instead of CToolBarCtrl by yourself.
{
// Construction
public:
CComboToolBar();
// Attributes
public:
CComboBox m_comboBox;//define CComboBox object
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CComboToolBar)
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CComboToolBar();
// Generated message map functions
protected:
//{{AFX_MSG(CComboToolBar)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG
afx_msg void OnSelChange();// Add response function while you select an item in list box.
DECLARE_MESSAGE_MAP()
};
ComboToolBar.cpp:
you must contain header file MainFrm.h in order to use main frame window pointer.
#include "MainFrm.h"
BEGIN_MESSAGE_MAP(CComboToolBar, CToolBar)
//{{AFX_MSG_MAP(CComboToolBar)
// NOTE - the ClassWizard will add and remove mapping macros here.
ON_CBN_SELCHANGE(IDC_COMBOX,OnSelChange)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CComboToolBar message handlers
void CComboToolBar::OnSelChange()
{
CMainFrame *pFrame = (CMainFrame* )AfxGetMainWnd();//Get the main window for the child window
int sel = pFrame->m_wndToolBar.m_comboBox.GetCurSel();
CString text;
pFrame->m_wndToolBar.m_comboBox.GetLBText(sel,text);
AfxMessageBox(_T("you have selected ") + text);
}
In the CFrame head file,you define a CComboToolBar class object like this:
public:
CComboToolBar m_wndToolBar; // define my custom toolbar,use m_wndToolBar instead of default m_wndToolBar.
And then ,renturn CFrame::OnCreate function and add the following code like this:
/***************************************************************************************/
//Set the ComboBox list information on tool bar as following description:
CRect rect;
m_wndToolBar.SetButtonInfo(12,IDC_COMBOX,TBBS_SEPARATOR|TBBS_GROUP,160);
m_wndToolBar.GetItemRect(12,&rect);
//Set the height of list box while the list box will be drag down(拉下)
//this is the key step,you must do it correctly otherwise you will not get what you want.
rect.bottom += 100; // add 100 pixels as list height
BOOL IsCreate = m_wndToolBar.m_comboBox.Create(CBS_DROPDOWN|WS_VISIBLE| //create list box control like this
WS_TABSTOP|CBS_AUTOHSCROLL,rect,&m_wndToolBar,IDC_COMBOX);
if (!IsCreate)
{
return -1;
}
//initialize list box datas
CString item;
for (int i=0; i<10 ; i++)
{
item.Format("list item:%d",i);
m_wndToolBar.m_comboBox.AddString(item);
}
//set the current item
m_wndToolBar.m_comboBox.SetCurSel(0);
/***************************************************************************************/
In the end,you have finished it.
- Put a CComboBox control on CToolBar
- How to use toolbar control on dialog using CToolBar class in VC++ - VC++ 中用CToolBar 类如何使用ToolBar控件
- Using a Context Menu on a Control
- MFC工具条CToolBar添加非按钮控件CComboBox
- MFC工具条CToolBar添加非按钮控件CComboBox
- MFC工具条CToolBar添加非按钮控件CComboBox
- CToolBar
- Put Everything Under Version Control
- Put Everything Under Version Control
- Changing the default skins on a Button control in Flex
- CComboBox
- Ccombobox
- CComboBox
- CComboBox
- CComboBox
- 2.3 Why do calling Focus() on a control not set focus on it?
- [WP7] How to press the mouse on a control, and detect MouseLeftButtonUp on another
- Refresh a GridView control on the parent page, from a pop up window
- oracle日期函数
- boost编译命令
- 15条 linux Find 命令实际使用方法
- Windows Phone Marketplace注册攻略
- 产品经理的职责和角色的定位
- Put a CComboBox control on CToolBar
- 字符编码笔记:ASCII,Unicode和UTF-8
- 设计模式之Abstract Factory的学习笔记
- 使用 Java Native Interface 的最佳实践
- WINDOWS 2003共享文件存取枚举控制
- freeradius的配置-rlm_policy模块的灵活运用1
- 弹窗代码大全window.open
- VC向文件追加数据
- Android Display System Surface Flinger