代码如下,加到CMainFrame::OnCreate里面,为什么成功?#define COMBO_BOX_WIDTH 80 //the width of the combo box
#define IDC_MY_COMBO 13001
int index = 0;
CRect rect;
while(m_wndToolBar.GetItemID(index)!= ID_MY_COMBO_BOX)
index++;
m_wndToolBar.SetButtonInfo(index, ID_MY_COMBO_BOX, TBBS_SEPARATOR, COMBO_BOX_WIDTH);
m_wndToolBar.GetItemRect(index, &rect); CComboBox m_wndMyComboBox;
rect.top+=2;
rect.bottom += 200;
if (!m_wndMyComboBox.Create(
WS_CHILD|WS_VISIBLE | CBS_AUTOHSCROLL |
CBS_DROPDOWNLIST | CBS_HASSTRINGS ,
rect, &m_wndToolBar, IDC_MY_COMBO))
{
TRACE0("Failed to create combo-box\n");
return FALSE;
}
m_wndMyComboBox.ShowWindow(SW_SHOW);
m_wndMyComboBox.AddString("Fisrt Select");
m_wndMyComboBox.AddString("Second Select");
m_wndMyComboBox.AddString("Third Select");
m_wndMyComboBox.SetCurSel(0);
#define IDC_MY_COMBO 13001
int index = 0;
CRect rect;
while(m_wndToolBar.GetItemID(index)!= ID_MY_COMBO_BOX)
index++;
m_wndToolBar.SetButtonInfo(index, ID_MY_COMBO_BOX, TBBS_SEPARATOR, COMBO_BOX_WIDTH);
m_wndToolBar.GetItemRect(index, &rect); CComboBox m_wndMyComboBox;
rect.top+=2;
rect.bottom += 200;
if (!m_wndMyComboBox.Create(
WS_CHILD|WS_VISIBLE | CBS_AUTOHSCROLL |
CBS_DROPDOWNLIST | CBS_HASSTRINGS ,
rect, &m_wndToolBar, IDC_MY_COMBO))
{
TRACE0("Failed to create combo-box\n");
return FALSE;
}
m_wndMyComboBox.ShowWindow(SW_SHOW);
m_wndMyComboBox.AddString("Fisrt Select");
m_wndMyComboBox.AddString("Second Select");
m_wndMyComboBox.AddString("Third Select");
m_wndMyComboBox.SetCurSel(0);
解决方案 »
- vc 图像像素
- 想做成资源管理器那样的界面
- 用pretranslatemessage 屏蔽键盘(只留下 空格键 小键盘的 上下左右键 ,一共5个),我不清楚这几个键的键值。
- 问各位一个简单的问题,自己派生重写的CMyListCtrl类,如何设置选中时高亮的颜色?
- 系统菜单变色问题
- 请问各位已经工作的师兄,有没有做测试的?做测试跟做研发主要区别是什么呢?毕业ing,了解了解,^_^
- 如何用vc调用sql server2000上的数据表和存储过程
- 关于DirectX 8.1的问题
- 如何删除开始按钮下的‘文档’子菜单下的内容???
- 怎么修改ClistCtrl 列表中的数据?
- 为什么这个CLSID_WavDest Filter注册成功了,但是不能用
- 程序随笔
上面的方法为什么不行?
{
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return false; // fail to create
} const int nCmbHeight = 200;
const int nCmbWidth = 120;
m_wndToolBar.SetButtonInfo(nIndex, IDC_CMB_HIERARCHYPROP, TBBS_SEPARATOR, 120); CRect rect;
m_wndToolBar.GetItemRect(nIndex,rect);
rect.top = 1;
rect.bottom = rect.top + 200; if(!m_cmbDevHP.Create(CBS_OWNERDRAWVARIABLE|CBS_DROPDOWNLIST|CBS_HASSTRINGS|WS_VISIBLE|WS_TABSTOP|WS_VSCROLL,
rect,&m_wndToolBar,IDC_CMB_HIERARCHYPROP))
{
return false;
} for(int i = 1; i <= 10; ++i )
{
m_cmbDevHP.AddString("xxx");
}
}
void CComboBox::MeasureItem(LPMEASUREITEMSTRUCT)
{ ASSERT(FALSE); }去掉CBS_OWNERDRAWVARIABLE没有错误了,可还是看不到toolbar上的combobox
我的运行是完全OK的,继承TOOLBAR与否是没关系的,把相关的代码提取出来就可以了的你再检查一下你的代码,
good luck!