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,如何释放,
...全文
376 12 打赏 收藏 转发到动态 举报
写回复
用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( ); 试试看
内容概要:本文围绕基于粒子群算法(PSO)的风电与水电(抽水蓄能)联合优化调度问题展开研究,旨在通过智能优化算法实现可再生能源的高效利用与电力系统的经济稳定运行。文中系统阐述了粒子群算法的核心原理及其在电力调度中的适用性,构建了综合考虑风电出力不确定性、抽水蓄能电站调节能力及系统运行约束的联合优化调度模型。采用Matlab进行算法编程与仿真求解,验证了该方法在降低系统综合运行成本、提升新能源消纳水平、增强电网调峰调频能力等方面的优越性能。研究进一步设计了多种对比场景,分析不同调度策略下的系统表现,充分展示了所提模型在应对复杂运行条件时的鲁棒性与实用价值。; 适合人群:具备一定电力系统分析基础和Matlab编程能力的研究生、科研人员,以及从事新能源并网调度、电力系统规划与运行等相关领域的工程师; 使用场景及目标:①应用于风电场与抽水蓄能电站的协同优化调度决策支持;②为高比例可再生能源接入的电力系统提供经济可靠的低碳调度方案;③服务于高校及科研院所中关于智能优化算法在能源系统中应用的教学与科研实验; 阅读建议:建议读者结合提供的Matlab代码深入理解算法实现细节与模型构建逻辑,重点关注目标函数设计、约束条件处理及参数设置对优化结果的影响,并通过复现仿真结果来掌握粒子群算法解决复杂非线性调度问题的关键技术要点。

15,977

社区成员

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

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