在工具条上添加控件

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);

 

posted @ 2013-09-27 11:15  鬞鬤  阅读(199)  评论(0编辑  收藏  举报