toolbar code using BCGPControlBar
时间: 2024-05-07 19:21:04 浏览: 16
Here is an example code for creating a toolbar using BCGPControlBar in MFC:
1. Include the necessary header files:
```
#include "BCGCBProInc.h"
#include "BCGPToolbar.h"
#include "BCGCBProVer.h"
```
2. Declare a member variable for the toolbar:
```
CBCGPToolBar m_wndToolBar;
```
3. Create the toolbar in the OnCreate() function of your main frame class:
```
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWndEx::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;
}
return 0;
}
```
4. Add a handler for resizing the toolbar in the OnSize() function:
```
void CMainFrame::OnSize(UINT nType, int cx, int cy)
{
CFrameWndEx::OnSize(nType, cx, cy);
if (m_wndToolBar.GetSafeHwnd() != NULL)
{
m_wndToolBar.SetWindowPos(NULL, 0, 0, cx, cy, SWP_NOACTIVATE | SWP_NOZORDER);
}
}
```
5. Add a handler for customizing the toolbar in the OnCustomize() function:
```
void CMainFrame::OnCustomize()
{
CBCGPToolbarCustomize* pDlgCust = new CBCGPToolbarCustomize (m_wndToolBar, this /* pParentWnd */);
pDlgCust->Create();
}
```
This code will create a toolbar with the default set of buttons from the toolbar resource (IDR_MAINFRAME). You can customize the toolbar by adding or removing buttons using the OnCustomize() function.
相关推荐
![text/x-c](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)