急!!急!!怎样在ToolBar中加入下拉组合框啊?jiangsheng和用过BCGControlBar的进来救救小弟!

lxas 2001-10-08 12:03:07
我按照帮助上面的作了,可是编译后工具条上新添加的那个按钮并没有被替换为组合框而且显示为不可选状态!!!救救我吧!!
...全文
147 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
lxas 2001-10-10
  • 打赏
  • 举报
回复
给分了!!!
lxas 2001-10-10
  • 打赏
  • 举报
回复
自己UP以下!
lxas 2001-10-09
  • 打赏
  • 举报
回复
to: prog_st(st)
已经收到了,但是有个地方没搞懂!
IDC_SNAP_COMBO 这个是干什么用的啊?
还有我编译以后当combo中的选项改变的时候没有出现Messagebox,你在帮我看看好吗?
我已经发到你的邮箱了。谢谢,解决后一定给分!!
guanjinke 2001-10-09
  • 打赏
  • 举报
回复
1.声明一个带有下拉菜单的新类:
class CToolBarWithCombo : public CToolBar
{
.....
......
public:
CComboBox m_comboBox;
........

}
2.然后到MainFrame.h里声明一个CToolBarWithCombo的对象,当然,不要忘记#include <ToolBarWithCombo.h>了。
3.然后将以前用CtoolBar类的地方,全都用新的类替换。(可以用find实现)
4.在资源里,点击工具栏资源,添加一个按钮,设定按钮的ID。
5.然后在MainFrame类里的OnCreate里面,查找ID是这个的按钮,把它的属性改成间隔线(应该是用SetButton(..)函数),rect设成你要的空间大小,然后Create一个Combo在这里,ID要相同。这样看上去很自然。但是有一点很重要,就是Create的控件不能是这个ToolBar上的最后一个按钮,否则会不显示。
突击召唤师 2001-10-09
  • 打赏
  • 举报
回复
还有,这个rect需要InflateRect(0,0,0,150)(根据你需要的大小),属性
for(int i = 0; i < iItemNumber; i++)
{
switch(GetItemID(i))
{
case IDC_MY_COMBO:
SetButtonInfo(i, IDC_MY_COMBO, TBBS_SEPARATOR, 100);
GetItemRect(i, &rect);
rect.InflateRect(0, 1, 0, 150);
m_Combo.Create(WS_VSCROLL | WS_TABSTOP | WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST, rect, this, IDC_MY_COMBO);
break;
case ....
....
....
}
}
突击召唤师 2001-10-09
  • 打赏
  • 举报
回复
什么都可以create上去的,只要留出空间就好了。
我不是用的BCG(因为它太强大以至于无法从容使用),直接继承的toolbar.
资源里面,放一个空的位置,ID设成你要的,然后在OnCreate里面,查找ID是这个的Item,把它的属性改成间隔线,rect设成你要的空间大小,然后Create一个Combo在这里,ID要相同。这样看上去很自然。但是有一点很重要,就是Create的控件不能是这个ToolBar上的最后一个Item,否则会不显示。
蒋晟 2001-10-09
  • 打赏
  • 举报
回复
参见MSDN中的CTRLBARS 示例
Custom toolbars, dynamic rearrangement of buttons in the toolbar, and adding controls (such as a combo box) to a toolbar. CTRLBARS demonstrates two ways of customizing a toolbar. The first toolbar, the Tool Bar, changes the arrangement of buttons between short (5 buttons) and long (10 buttons). CTRLBARS calls CToolBar::SetButtonInfo for each button to map it to a tile position in the toolbar's bitmap and to a command identification. The second toolbar, the Style Bar, illustrates replacing a toolbar button (or separator) with a control — a combo box in this example. CMainFrame::CreateStyleBar creates a 100-pixel-wide toolbar separator. It then creates the combo box (IDW_COMBO) as a child of the toolbar, and sets the position of the combo box to take the space it just allocated for the separator.
lxas 2001-10-08
  • 打赏
  • 举报
回复
to:
karma(无为):谢了,不过我用的是BCGControlBar这个类库,情况有点不一样啊。

to:
prog_st(st)我的E-Mail:falcos@163.com
karma 2001-10-08
  • 打赏
  • 举报
回复
1.
class CToolBarWithCombo : public CToolBar
{
protected:
CFont m_font;

public:
CComboBox m_comboBox;
int m_nMaxStrings;

CToolBarWithCombo() {
m_nMaxStrings = 10; }

void GetText(CString& str) {
m_comboBox.GetWindowText(str); }
void SetText(const CString& str) {
m_comboBox.SetWindowText(str); }
void AddString(const CString& str);

BOOL CreateComboBox(CComboBox& comboBox,
UINT nIndex, UINT nID,

int nWidth, int nDropHeight);

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CToolBarWithCombo)
//}}AFX_VIRTUAL

// Generated message map functions
protected:
//{{AFX_MSG(CToolBarWithCombo)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

BEGIN_MESSAGE_MAP(CToolBarWithCombo, CToolBar)
//{{AFX_MSG_MAP(CToolBarWithCombo)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

void CToolBarWithCombo::AddString(const CString& str)
{
if( str.IsEmpty() )
return;

int nIndex = m_comboBox.FindStringExact(-1, str);
if( nIndex >= 0 )
m_comboBox.DeleteString(nIndex);

if( m_comboBox.GetCount() == m_nMaxStrings )
m_comboBox.DeleteString(m_nMaxStrings-1);

m_comboBox.InsertString(0, str);
}

BOOL CToolBarWithCombo::CreateComboBox(CComboBox& comboBox, UINT
nIndex, UINT nID,
int
nWidth, int nDropHeight)
{
// Create the combo box
SetButtonInfo(nIndex, nID, TBBS_SEPARATOR, nWidth);

CRect rect;
GetItemRect(nIndex, &rect);
rect.top = 3;
rect.bottom = rect.top + nDropHeight;
if (!comboBox.Create(
CBS_DROPDOWN|WS_VISIBLE|WS_TABSTOP|WS_VSCROLL,
rect, this, nID))
{
TRACE0("Failed to create combo-box\n");
return FALSE;
}

// Create a font for the combobox
LOGFONT logFont;
memset(&logFont, 0, sizeof(logFont));

if (!::GetSystemMetrics(SM_DBCSENABLED))
{
// Since design guide says toolbars are fixed height
so is the font.
logFont.lfHeight = -11;
logFont.lfWeight = FW_BOLD;
CString strDefaultFont = "MS Sans Serif";
lstrcpy(logFont.lfFaceName, strDefaultFont);
if (!m_font.CreateFontIndirect(&logFont))
TRACE0("Could Not create font for combo\n");
else
comboBox.SetFont(&m_font);
}
else
{
m_font.Attach(::GetStockObject(SYSTEM_FONT));
comboBox.SetFont(&m_font);
}

return TRUE;
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;

if (!m_wndToolBar.Create(this) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
//很重要
if (!m_wndToolBar.CreateComboBox(m_wndToolBar.m_comboBox, 3,
ID_COMBO, 150, 100))
{
TRACE0("Failed to create toolbar's combo box\n");
return -1; // fail to create
}

if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}

// TODO: Remove this if you don't want tool tips or a
resizeable toolbar
m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);

// TODO: Delete these three lines if you don't want the
toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
}


also see http://codeguru.earthweb.com/toolbar/combo_in_flatbar.shtml
prog_st 2001-10-08
  • 打赏
  • 举报
回复
可以给例程,Email
prog_st 2001-10-08
  • 打赏
  • 举报
回复
>falcos@163.com 发出!

16,470

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧