#pragma once
// CMainToolBar
class CMainToolBar : public CToolBar
{
DECLARE_DYNAMIC(CMainToolBar)
public:
CMainToolBar();
virtual ~CMainToolBar();
protected:
DECLARE_MESSAGE_MAP()
public:
CComboBox m_combox;
};
// MainToolBar.cpp : implementation file
//
#include "stdafx.h"
#include "SingleDoc.h"
#include "MainToolBar.h"
// CMainToolBar
IMPLEMENT_DYNAMIC(CMainToolBar, CToolBar)
CMainToolBar::CMainToolBar()
{
}
CMainToolBar::~CMainToolBar()
{
}
BEGIN_MESSAGE_MAP(CMainToolBar, CToolBar)
END_MESSAGE_MAP()
// CMainToolBar message handlers
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
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 -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: 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);
// maintoolbar
int index = 0;
RECT rect;
//找到指定的工具项
while(m_wndToolBar.GetItemID(index)!=IDD_HKX)
index++;
//设置指定工具项的宽度并获取新的区域 80是宽度
m_wndToolBar.SetButtonInfo(index, IDD_HKX, TBBS_SEPARATOR, 80);
m_wndToolBar.GetItemRect(index, &rect);
//设置位置
rect.top+=2;
rect.bottom += 200;
// 创建并显示控件
if(!m_wndToolBar.m_combox.Create(WS_CHILD|WS_VISIBLE| CBS_AUTOHSCROLL| CBS_DROPDOWNLIST | CBS_HASSTRINGS , rect,
&m_wndToolBar, IDD_HKX))
{
TRACE0("Failed to create combo-box\n");
return FALSE;
}
m_wndToolBar.m_combox.ShowWindow(SW_SHOW);
//填充内容
m_wndToolBar.m_combox.AddString(TEXT("25%"));
m_wndToolBar.m_combox.AddString(TEXT("50%"));
m_wndToolBar.m_combox.AddString(TEXT("75%"));
//m_wndToolBar.m_combox.AddString("100%");
//m_wndToolBar.m_combox.AddString("125%");
//m_wndToolBar.m_combox.AddString("150%");
//m_wndToolBar.m_combox.AddString("175%");
//m_wndToolBar.m_combox.AddString("200%");
//选择默认项
m_wndToolBar.m_combox.SetCurSel(3);