Click to See Complete Forum and Search --> : Insert a ToolBar in a Dialog based app
Cedric Le Jalle
May 20th, 1999, 06:41 AM
Hi..
I was wondering how I could add a ToolBar to one of my Dialog Based MFC App...I could easily add a Menu bar, but I can't find the way to add a ToolBar...Could someone help me ?
Jason Teagle
May 20th, 1999, 08:12 AM
If you embed a CToolBar object as a member of the dialogue class, then add a handler for the WM_CREATE message, then in the OnCreate() method it generates add these lines (stolen from CMainFrame as generated by AppWizard):
--- if (!m_wndToolBar.Create(this) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
---
(where IDR_MAINFRAME is a toolbar resource).
This should work. Does it help?
Talal Tayyab
May 20th, 1999, 09:56 AM
You should also add the following code after you have loaded the toolbar
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
There is one problem , if you are calling your dialog from some other dialog/view then the second time you call it the toolbar does not load ... any solutions
Cedric Le Jalle
May 21st, 1999, 06:38 AM
Hi..thank you for your help..but well, I can't make it work...the toolbar doesn't appear in the dialog box..Maybe by adding the line talal tayyab just said, then it works...I'll try as soon I'm at home..I hope it'll work then..
Thanks again 4 ur help both u jason and talal tayyab.. :)
Jason Teagle
May 21st, 1999, 07:39 AM
You'll be pleased to know that with Talal's added comment, it WILL work - but you will have to shift all controls on the dialogue box DOWN by the height of the toolbar.
Normally, a frame window has the toolbar attached to one side and then places a client window (the view) inside the area left after the toolbar and status bar have been positioned; because the dialogue box puts controls directly onto its surface rather than on a client window placed inside the frame, the controls overlap the toolbar. It is, however, a simple thing to move them all down {:v).
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.