I'm renovating an old MFC program that utilizes the CToolBar class of back then. But, naturally, it won't compile in VS-22.
https://learn.microsoft.com/en-us/cpp/mfc/using-your-old-toolbars?view=msvc-170 says, If you have used previous versions of Visual C++ to create customized toolbars, the new implementation of class CToolBar could cause you problems. So that you don't have to give up your old toolbars to use the new functionality, the old implementation is still supported.
https://learn.microsoft.com/en-us/cpp/mfc/mfc-toolbar-implementation?view=msvc-170 says: For backward compatibility, MFC retains the older toolbar implementation in class COldToolBar. The documentation for earlier versions of MFC describe COldToolBar under CToolBar.
When I change my derived class definition from
class CPaletteBar : public CToolBar
to
class CPaletteBar : public COldToolBar
upon build, I get an error
Error C2504: 'COldToolBar': base class undefined
So far I have found no reference to a different header file for COldToolBar
than for CToolBar
, being in afxext.h
. I haven't been able to extract detailed information from said resources.
Can anyone give me a heads-up? Thank you.
I had to resort to a more current method as depicted in the Docktool sample available from Git. But whereas I was able to construct the palette bar in my view class, I found that it had to happen in the mainframe. Whereas all of the support routines are still in the view. So I had to construct the palette bar in mainframe and provide a pointer for access by the view class. For some reason, I could not make a public pointer for it in mainframe and the compiler wouldn't allow a proper access routine from outside the mainframe. So I ended up with an ad-hock method of placing a pointer in the app process by mainframe and then accessing that pointer from the view. Not kosher, but it seems to work. So long as the location of the palette object is not changed by the system. Any suggestion for correction would be welcome. Following is code copied from Docktool that I found necessary to make functional in my application. I'm sure that it could be further refined.
m_bColor = (AfxGetApp()->GetProfileInt(_T("General"), _T("Color"), 1) != 0);
m_bToolTips = (AfxGetApp()->GetProfileInt(_T("General"), _T("ToolTips"), 1) != 0);
EnableDocking(CBRS_ALIGN_ANY);
if (!m_wndPaletteBar.Create(this, WS_CHILD | CBRS_GRIPPER | WS_EX_TOOLWINDOW | WS_VISIBLE | CBRS_SIZE_DYNAMIC |
CBRS_TOP | ((m_bToolTips) ? (CBRS_TOOLTIPS | CBRS_FLYBY) : 0), IDW_PALETTE_BAR) ||
!m_wndPaletteBar.LoadBitmap(IDC_PALETTE) ||
!m_wndPaletteBar.SetButtons(PaletteButtons, sizeof(PaletteButtons) / sizeof(UINT)))
{
TRACE0("Failed to create palettebar\n");
return -1; // fail to create
}
theApp.setPaletteBar((CPaletteBar*)&m_wndPaletteBar);
//m_wndPaletteBar.SetWindowText(_T("Palette"));
m_wndPaletteBar.EnableDocking(CBRS_ALIGN_ANY);
CRect temp;
m_wndPaletteBar.GetItemRect(0, &temp);
m_wndPaletteBar.SetSizes(CSize(temp.Width()+15,
temp.Height()+15), CSize(16, 15));
CPoint point(1,1);
FloatControlBar(
&m_wndPaletteBar,
point,
CBRS_ALIGN_TOP);
DockControlBar((CControlBar*) &m_wndPaletteBar, AFX_IDW_DOCKBAR_FLOAT);
m_wndPaletteBar.SetColumns(AfxGetApp()->GetProfileInt(_T("General"), _T("Columns"), 2));
LoadBarState(_T("General"));
ShowControlBar(&m_wndPaletteBar, FALSE, FALSE);