VC++实现工具栏上添加平面组合框控件(6)
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar ");
return -1; // fail to create
}
// 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);
int index = 0;
RECT rect;
//找到指定的工具项
while(m_wndToolBar.GetItemID(index)!=ID_TOOL_ZOOM)index++;
//设置指定工具项的宽度并获取新的区域 80是宽度
m_wndToolBar.SetButtonInfo(index, ID_TOOL_ZOOM, TBBS_SEPARATOR, 80);
m_wndToolBar.GetItemRect(index, &rect);
//设置位置
rect.top+=2;
rect.bottom += 200;
// 创建并显示
if (!m_wndToolBar.m_wndZoom.Create(WS_CHILD|WS_VISIBLE |CBS_AUTOHSCROLL|CBS_DROPDOWNLIST |
CBS_HASSTRINGS ,rect, &m_wndToolBar, ID_TOOL_ZOOM))
{
TRACE0("Failed to create combo-box ");
return FALSE;
}
m_wndToolBar.m_wndZoom.ShowWindow(SW_SHOW);
//填充内容
m_wndToolBar.m_wndZoom.AddString("25%");
m_wndToolBar.m_wndZoom.AddString("50%");
m_wndToolBar.m_wndZoom.AddString("75%");
m_wndToolBar.m_wndZoom.AddString("100%");
m_wndToolBar.m_wndZoom.AddString("125%");
m_wndToolBar.m_wndZoom.AddString("150%");
m_wndToolBar.m_wndZoom.AddString("175%");
m_wndToolBar.m_wndZoom.AddString("200%");
m_wndToolBar.m_wndZoom.SetCurSel(3);
return 0;
}
void CMainFrame::OnSelectZoomed()
{
CString strContent;
m_wndToolBar.m_wndZoom.GetWindowText(strContent);
AfxMessageBox(strContent);
}
四、小结
为了实现OFFICE2000风格的工具条,本实例介了一种比较巧妙的方法,利用Visual C++6.0已有的开发环境支持,在工具条中加入了平面组合框控件,并实现了组合框的消息响应,用户选择组合框中的某一项后,会弹出一个对话框,提示用户所选择的信息。