The following steps are for a SDI or MDI project prior to the "MFC Extension Pack" in VS 2008. After that there are more options.
1. Create a Toolbar resource in the Resource View, give it an ID, e.g. ID_TOOLBAR
2. Add the buttons you'd like.
3. If you want the toolbar in your main frame window or in a child frame window, create an instance of a CToolbar class, e.g.
CToolBar m_toolbar;
in CMainFrame or CChildFrame class.
4. Create the toolbar window in the frames OnCreate member like
if (!m_toolbar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_toolbar.LoadToolBar(IDR_TOOLBAR))
{
TRACE0("Failed to create toolbar\n");
return -1; }
m_toolbar.EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_toolbar);
If you want it placed somewhere else, like in a dialog, you have to do it another way. A bit more work but manageable. You might wanna have a look at
this[
^].
Also check the
documentation[
^]
Edit: The excellent article
A Toolbar in the middle of elsewhere[
^] describes very well how to add a toolbar to a dialog.