我想在toobar上添加combox请问一下代码错在哪?我编译没有错误,但当运行的时候提示“建立空文档失败”那位大虾知道原因
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_wndcolorbar.CreateEx(this,TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_LEFT
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndcolorbar.LoadToolBar(IDR_COLOR_BAR))
{
TRACE0("Failed to create toolbar\n");
return -1;
} //我自己新添加的Toolbar靠左显示
m_wndcolorbar.SetButtonInfo(2,ID_BUTTON_BLUE,TBBS_SEPARATOR,150);
m_wndcolorbar.GetItemRect(2,r);
r.bottom=r.up+150;
if(m_combobox.Create(WS_CHILD|CBS_DROPDOWN|WS_VSCROLL|CBS_HASSTRINGS|WS_HSCROLL,r,&m_wndcolorbar,ID_BUTTON_BLUE))
{
TRACE0("Fail!");
return -1;
}
m_combobox.ShowWindow(SW_SHOW); //在自己的添加的toolbar上添加combol 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
}
//CRect r; // TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
m_wndcolorbar.EnableDocking(CBRS_ALIGN_ANY); EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
DockControlBar(&m_wndcolorbar);
return 0;
}
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_wndcolorbar.CreateEx(this,TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_LEFT
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndcolorbar.LoadToolBar(IDR_COLOR_BAR))
{
TRACE0("Failed to create toolbar\n");
return -1;
} //我自己新添加的Toolbar靠左显示
m_wndcolorbar.SetButtonInfo(2,ID_BUTTON_BLUE,TBBS_SEPARATOR,150);
m_wndcolorbar.GetItemRect(2,r);
r.bottom=r.up+150;
if(m_combobox.Create(WS_CHILD|CBS_DROPDOWN|WS_VSCROLL|CBS_HASSTRINGS|WS_HSCROLL,r,&m_wndcolorbar,ID_BUTTON_BLUE))
{
TRACE0("Fail!");
return -1;
}
m_combobox.ShowWindow(SW_SHOW); //在自己的添加的toolbar上添加combol 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
}
//CRect r; // TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
m_wndcolorbar.EnableDocking(CBRS_ALIGN_ANY); EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
DockControlBar(&m_wndcolorbar);
return 0;
}
{
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);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_DROPDOWN | CBS_HASSTRINGS , rect,
&m_wndToolBar, ID_TOOL_ZOOM))
{
TRACE0("Failed to create combo-box\n");
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;
}BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs return TRUE;
}
http://www.codeproject.com/docking/ctrls_in_tb.asp
http://www.codeproject.com/docking/toolbarcombo.asp