MFC.如何释放m_wndtoolbar.LoadToolBar()已加载的IDR_TOOLBAR1

ToujoursMoi 2015-04-16 10:55:11
BOOL CCutLineAIDC::OnInitDialog()
{
CDialog::OnInitDialog();

// TODO: Add extra initialization here

CRect rect;
GetClientRect(rect);

if (!m_hpglView.Create(rect, this))
return -1;

//CToolBar p_wndtoolbar = new CToolBar; //20150415
//*m_wndtoolbar = p_wndtoolbar; //20150415
//20150323rwt toolbar
if ((!m_wndtoolbar.CreateEx( this,TBSTYLE_FLAT , WS_CHILD | WS_VISIBLE | CBRS_ALIGN_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS,
CRect(4,4,0,0))) || (!m_wndtoolbar.LoadToolBar(IDR_TOOLBAR1)))
{
TRACE0("failed to create toolbar\n");
return false;
}

//* 20150415-rwt
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
CRect rcClientOld; // Old Client Rect
CRect rcClientNew; // New Client Rect with Tollbar Added
GetClientRect(rcClientOld); // Retrive the Old Client WindowSize
// Called to reposition and resize control bars in the client area of a window
// The reposQuery FLAG does not really traw the Toolbar. It only does the calculations.
// And puts the new ClientRect values in rcClientNew so we can do the rest of the Math.
RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0,reposQuery,rcClientNew);
// All of the Child Windows (Controls) now need to be moved so the Tollbar does not cover them up.
// Offest to move all child controls after adding Tollbar
CPoint ptOffset(rcClientNew.left-rcClientOld.left,rcClientNew.top-rcClientOld.top);
CRect rcChild;
CWnd* pwndChild = GetWindow(GW_CHILD); //Handle to the Dialog Controls
while(pwndChild) // Cycle through all child controls
{
pwndChild->GetWindowRect(rcChild); // Get the child control RECT
ScreenToClient(rcChild);
rcChild.OffsetRect(ptOffset); // Changes the Child Rect by the values of the claculated offset
pwndChild->MoveWindow(rcChild,FALSE); // Move the Child Control
pwndChild = pwndChild->GetNextWindow();
}
CRect rcWindow;
GetWindowRect(rcWindow); // Get the RECT of the Dialog
rcWindow.right += rcClientOld.Width() - rcClientNew.Width(); // Increase width to new Client Width
rcWindow.bottom += rcClientOld.Height() - rcClientNew.Height(); // Increase height to new Client Height
MoveWindow(rcWindow,FALSE); // Redraw Window
// Now we REALLY Redraw the Toolbar
RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0);
//*/


//m_wndtoolbar.MoveWindow(0,0, 100, 40,TRUE);//20150415-rwt
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}

m_wndtoolbar.LoadToolBar(IDR_TOOLBAR1) 第一次执行返回值是对的,第二次在执行的时候 返回值就为0了,工具条在打开的窗口中就显示不出来了,如果屏蔽到if()里的return,工具条 框架能显示出来,但是图标都没有了,求大神帮忙,不知道是不是没有释放掉加载的toolbar,如何释放,
...全文
320 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
ToujoursMoi 2015-04-17
  • 打赏
  • 举报
回复
引用 5 楼 zgl7903 的回复:
m_wndtoolbar.CreateEx 之前调用一次 m_wndtoolbar.DestroyWindow( ); 试试看
我把m_wndtoolbar.DestroyWindow( )放到 destroy的消息映射函数里了,还是不行, 调用m_wndtoolbar.DestroyWindow( )之前要像获得函数句柄一样,获得一些东西么?
ToujoursMoi 2015-04-17
  • 打赏
  • 举报
回复
引用 8 楼 VisualEleven 的回复:
你可以使用CToolBar::GetToolBarCtrl()得到CToolBarCtrl对象,然后利用CToolBarCtrl::AddButtons()/DeleteButton/HideButton()等来实现你的功能,没有必要重新Load.
请问CToolBarCtrl::AddButtons(),怎么使用,里面的参数不会写,我只有 工具栏的 ID,和工具栏上各个图标的ID
ToujoursMoi 2015-04-16
  • 打赏
  • 举报
回复
引用 2 楼 VisualEleven 的回复:
为什么会执行两次OnInitDialog函数???
按钮触发 打开新窗口,里面显示图形,工具条上加了一些处理图形的功能
ToujoursMoi 2015-04-16
  • 打赏
  • 举报
回复
按钮触发 打开新窗口,里面显示图形,工具条上加了一些处理图形的功能
Eleven 2015-04-16
  • 打赏
  • 举报
回复
为什么会执行两次OnInitDialog函数???
ToujoursMoi 2015-04-16
  • 打赏
  • 举报
回复
自己顶一下,小弟新手,求大神指导
ToujoursMoi 2015-04-16
  • 打赏
  • 举报
回复
引用 8 楼 VisualEleven 的回复:
你可以使用CToolBar::GetToolBarCtrl()得到CToolBarCtrl对象,然后利用CToolBarCtrl::AddButtons()/DeleteButton/HideButton()等来实现你的功能,没有必要重新Load.
关键还是释放 工具栏的问题吧? 用CToolBarCtrl的方法在dialog关闭之后需不需要手动删除这个button呢?不删除的话,第二次调用initdialog的话 还是会产生类似的问题吧?我先动手试一下。
Eleven 2015-04-16
  • 打赏
  • 举报
回复
你可以使用CToolBar::GetToolBarCtrl()得到CToolBarCtrl对象,然后利用CToolBarCtrl::AddButtons()/DeleteButton/HideButton()等来实现你的功能,没有必要重新Load.
ToujoursMoi 2015-04-16
  • 打赏
  • 举报
回复
没有释放toolbar的 函数么?
ToujoursMoi 2015-04-16
  • 打赏
  • 举报
回复
引用 5 楼 zgl7903 的回复:
m_wndtoolbar.CreateEx 之前调用一次 m_wndtoolbar.DestroyWindow( ); 试试看
我了解你的用意,试了下,但是效果不行啊,第二次调用还是不显示
zgl7903 2015-04-16
  • 打赏
  • 举报
回复
m_wndtoolbar.CreateEx 之前调用一次 m_wndtoolbar.DestroyWindow( ); 试试看
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; //this->Create(NULL,"元器件绘制系统",WS_MAXIMIZE); 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_wndToolBarDraw.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || !m_wndToolBarDraw.LoadToolBar(IDR_DRAW_ICCHIP)) { 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); m_wndToolBarDraw.EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_wndToolBarDraw); this->FloatControlBar(&m_wndToolBarDraw,CPoint(30,120)); //m_wndToolBarDraw.SetSizes(CSize(25+7,25+6),CSize(25,25)); // CG: The following line was added by the Splash Screen component. // CSplashWnd::ShowSplashScreen(this); // CG: The following line was added by the Splash Screen component. CSplashWnd::ShowSplashScreen(this); return 0; }

15,980

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧