Please bear with me, there's several code components at work here, though they're all really basic.
I'm learning MFC, and its come time to play with toolbars. It was smooth sailing, until I tried to make a custom toolbar class, to accomidate controls that aren't buttons. But lets not get ahead of ourselves here, I haven't gotten to the point of adding extra controls, I can't even seem to derive a class from CToolBar. Here's the relevant code from my CStyleBar class definition. There is literally no other code other than comments, includes, and misc directives that MSVC++ uses.
class CStyleBar : public CToolBar
// Generated message map functions
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
// in StyleBar.cpp
int CStyleBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
if (CToolBar::OnCreate(lpCreateStruct) == -1)
That's the meat of the class definition. The OnCreate() is pretty empty, because I moved the LoadToolBar() into the code below for diagnostic purposes, and...there's no point in adding my custom controls if I can't even get the toolbar to load. Now here's how the CStyleBar is created.
// ...in MainFrame.h
// ...in MainFrame.cpp
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
// Tell the frame window to permit docking.
// Create the toolbars and style bar.
if (!CreateToolBar() // Another toolbar that works ok
|| !CreateStatusBar() // Statusbar, also works ok
|| !CreateStyleBar()) // Doesn't work unless a CToolBar object
if (!m_wndStyleBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC, IDW_STYLEBAR)
m_wndStyleBar.EnableDocking(CBRS_ALIGN_TOP | CBRS_ALIGN_BOTTOM);
I'm getting an assertion error:
// ...in CWnd::AssertValid() from Wincore.cpp
ASSERT(::IsWindow(m_hWnd)); // Causes an Assertion error!
So, it would seem that my m_wndStyleBar is not being properly created as a window, but I don't know why. I've tracked the problem down to the CStyleBar class not working properly, because switching the m_wndStyleBar definition from a CStyleBar to a CToolBar makes the toolbar work properly (albeit unable to hold custom controls).
I must be missing something, maybe an overridable function? I swear I can't find any thing missing or out of place in my code compared to the book I'm learning from (save for I haven't added in any message handlers yet).
I know its a vague question, but anyone have an idea of what's missing?