From: Peter Boulton on
Hi,

I've upgraded my app to use the MFC Feature Pack and am using
CMFCToolBars in an MDI app with most of the Feature Pack UI features
running. Everything is beautiful except the toolbar customisations.

Using Alt and drag, I can remove existing buttons from the toolbars,
but I cannot change the buttons' positions, drag a button from one bar
to another (I have several!) and the 'Customize' dialog lets me drag
Commands off the dialog, but when the command is in a drop position
over a toolbar the cursor still shows the 'dragging' cursor with a
cross in it and it cannot be dropped.

Curiously, I can create new toolbars using the Customize dialog! And
drag and drop Commands from the dialog to the new toolbar.

My question is, what do I have to do to enable the same functionality
on my existing toolbars?

Here's what I think is the relevant stuff from my code:

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWndEx::OnCreate(lpCreateStruct) == -1)
return -1;
......
// enable quick (Alt+drag) toolbar customization
CMFCToolBar::EnableQuickCustomization();

if (CMFCToolBar::GetUserImages() == NULL)
{
// load user-defined toolbar images
if (m_UserImages.Load(_T("UserImages.bmp")))
{
m_UserImages.SetImageSize(CSize(16, 16), FALSE);
CMFCToolBar::SetUserImages(&m_UserImages);
}
}
....
m_wndMenuBar.SetPaneStyle(m_wndMenuBar.GetPaneStyle() |
CBRS_SIZE_DYNAMIC | CBRS_TOOLTIPS | CBRS_FLYBY);

// prevent the menu bar from taking the focus on activation
CMFCPopupMenu::SetForceMenuFocus(FALSE);



// CREATE STANDARD TOOLBAR - note, it uses CreateEx, whereas the other
toolbars use Create()
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
}
m_wndToolBar.SetWindowText("Standard");

CString strCustomize;
bNameValid = strCustomize.LoadString(IDS_TOOLBAR_CUSTOMIZE);
ASSERT(bNameValid);
m_wndToolBar.EnableCustomizeButton(TRUE, ID_VIEW_CUSTOMIZE,
strCustomize);

....
// Allow user-defined toolbars operations:
InitUserToolbars(NULL, uiFirstUserToolBarId, uiLastUserToolBarId);

m_wndMenuBar.EnableDocking(CBRS_ALIGN_ANY);
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
....
// enable Visual Studio 2005 style docking window behavior
CDockingManager::SetDockingMode(DT_SMART);
// enable Visual Studio 2005 style docking window auto-hide behavior
EnableAutoHidePanes(CBRS_ALIGN_ANY);

// Enable enhanced windows management dialog
EnableWindowsDialog(ID_WINDOW_MANAGER, IDS_WINDOWS_MANAGER, TRUE);

// Enable toolbar and docking window menu replacement
EnablePaneMenu(TRUE, ID_VIEW_CUSTOMIZE, strCustomize,
ID_VIEW_TOOLBAR);
....
// TODO: define your own basic commands, ensuring that each pulldown
menu has at least one basic command.
CList<UINT, UINT> lstBasicCommands;

lstBasicCommands.AddTail(ID_FILE_NEW);
//etc.
CMFCToolBar::SetBasicCommands(lstBasicCommands);

// Load menu items images(not placed on the standard toolbars):
CMFCToolBar::AddToolBarForImageCollection(IDR_MENU_IMAGES);
....
}

I'm wondering why I can't drag and drop ONTO my toolbars when I can
remove buttons fine! Any suggestions would be most appreciated!

Thanks.

Pete


From: Peter Boulton on
It happens that Peter Boulton formulated :
> Hi,
>
> I've upgraded my app to use the MFC Feature Pack and am using CMFCToolBars in
> an MDI app with most of the Feature Pack UI features running. Everything is
> beautiful except the toolbar customisations.
>
> Using Alt and drag, I can remove existing buttons from the toolbars, but I
> cannot change the buttons' positions, drag a button from one bar to another
> (I have several!) and the 'Customize' dialog lets me drag Commands off the
> dialog, but when the command is in a drop position over a toolbar the cursor
> still shows the 'dragging' cursor with a cross in it and it cannot be
> dropped.
>
> .. snipped ..

> I'm wondering why I can't drag and drop ONTO my toolbars when I can remove
> buttons fine! Any suggestions would be most appreciated!
>
> Thanks.
>
> Pete

OP here - problem solved! The solution is to call AfxOleInit() before
the toolbars are created - probably in the InitInstance().

Pete