在工具条上添加控件

1、新建一个类继承自CToolBar,在该类中添加相应的控件成员变量。

2、新建工具条资源。

3、在对话框中创建工具条,及控件。

具体代码如下:

//创建并载入工具条
    m_ToolBar.Create(this);
    m_ToolBar.LoadToolBar(IDR_TOOLBAR1);

    //找到指定控件位置的索引
    int index = 0;
    while(m_ToolBar.GetItemID(index) != IDR_BUTTON_FIRST)
    {
        index ++;
    }

    CRect rect;
    //设置控件的大小
    m_ToolBar.GetItemRect(index, &rect);
    rect.right += 100;
    rect.bottom += 50;

    //创建控件
    if (!m_ToolBar.m_wndMyCombo.Create(WS_CHILD|WS_VISIBLE| CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | CBS_HASSTRINGS , rect, &m_ToolBar, IDR_BUTTON_FIRST))
    {
        MessageBox(_T("aaa"));
    }
    m_ToolBar.m_wndMyCombo.ShowWindow(SW_SHOW);

    m_ToolBar.m_wndMyCombo.AddString(_T("%25"));
    m_ToolBar.m_wndMyCombo.AddString(_T("%50"));
    m_ToolBar.m_wndMyCombo.AddString(_T("%75"));
    m_ToolBar.m_wndMyCombo.AddString(_T("%100"));


    //调整工具条位置
    m_ToolBar.RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0);
    RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0);

 

转载于:https://www.cnblogs.com/nangning/p/3342415.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值