MFC.如何释放m_wndtoolbar.LoadToolBar()已加载的IDR_TOOLBAR1
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,如何释放,
{
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,如何释放,
...全文
相关推荐
MFC问题总结
详细解释并处理在MFC使用过程中出现的各种常见问题,以及各种控件的使用介绍
在Dialog中使用图片Toolbar
在基于对话框Dialog的应用程序中如何添加用图片做成的工具栏Toolbar
制作ToolBar工具条
通过MFC应用程序体现一个ToolBar工具条的开发过程,简洁明了,开发环境VS2010
MFC 界面设计代码收集
界面透明特效设计,内附实现的代码源 改变视图背景色: 在CView的OnDraw函数中添写如下一段程序代码: void CFileNameView::OnDraw(CDC* pDC) { CFileNameDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); CRect rectClient; CBrush brushBkColor; GetClientRect(rectClient); brushBkColor.CreateSolidBrush(RGB(255,0,0)); //颜色设置 pDC->DPtoLP(rectClient); pDC->FillRect(rectClient,&brushBkColor); … }
VC在对话框中加入工具栏
MFC中没有提供供对话框使用的工具条类,而我们时常需要开发以对话框为框架的程序。下面我使用简单的代码说明这种方法。 step1: 在资源编辑器中插入工具条资源,并为每个按钮创建ID。将它命名为IDC_TOOLBAR1


界面
