gpt4 book ai didi

c++ - 如何在大型机中添加第二个工具栏?

转载 作者:行者123 更新时间:2023-11-30 05:21:06 25 4
gpt4 key购买 nike

我想在我的主框架窗口中添加第二个工具栏,使其位于现有工具栏的下方。

阅读以下教程:
http://forums.codeguru.com/showthread.php?495887-Add-a-toolbar-to-an-MFC-application

http://www.codersource.net/2010/01/30/mfc-tutorial-toolbars/

MFC Toolbar on Dialog?

我对这个未回答的话题得出了类似的结论:
https://stackoverflow.com/questions/35736580/how-to-add-a-second-toolbar-to-an-mfc-application-so-that-the-toolbar-is-added-o

这是我的代码:

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// create a view to occupy the client area of the frame
if (!m_wndView.Create(NULL, NULL, AFX_WS_DEFAULT_VIEW,
CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST, NULL))
{
TRACE0("Failed to create view window\n");
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
}

m_wndStatusBar.SetPaneInfo(EWF_PANE_INDEX, ID_SEPARATOR, SBPS_NORMAL, EWF_PANE_WIDTH);

for (int i=0;i<5; i++) {
// Change Status Bar style to make it Owner-drawn
m_wndStatusBar.GetStatusBarCtrl().SetText("", i, SBT_OWNERDRAW);
}

CToolBar myToolBar;

if (!myToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!myToolBar.LoadToolBar(IDR_MAINFRAME_B))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}


return 0;
}

我已经添加了:

CToolBar myToolBar;

if (!myToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!myToolBar.LoadToolBar(IDR_MAINFRAME_B))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}

在我的第二个工具栏的底部,但当应用程序打开时它没有出现并且编译没有错误。
与由 pFrame->LoadFrame(IDR_MAINFRAME, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE , NULL, NULL);
InitInstance() 调用的已经提供的工具栏相比如果我在下一行用我的第二个工具栏调用此 pFrame->LoadFrame,应用程序将不会一起加载。
我需要如何调用我的第二个工具栏?
我完全错过了什么吗?

最佳答案

您需要将 CToolBar myToolBar 添加为您的 CMainFrame 类的成员变量,方法与 m_wndToolBar 相同。否则,如果您在 OnCreate 退出后将其定义为局部变量,它将被销毁。

关于c++ - 如何在大型机中添加第二个工具栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40385203/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com