C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 18th, 2002, 11:30 PM
MJEggertson MJEggertson is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2002
Location: Seattle WA
Posts: 863 MJEggertson User rank is Corporal (100 - 500 Reputation Level)MJEggertson User rank is Corporal (100 - 500 Reputation Level)MJEggertson User rank is Corporal (100 - 500 Reputation Level)MJEggertson User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 sec
Reputation Power: 13
[MFC] How do you derive from CToolBar?

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.

Code:
// StyleBar.h

class CStyleBar : public CToolBar
{
// Implementation
protected:

    // Generated message map functions
    //{{AFX_MSG(CStyleBar)
    afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
    //}}AFX_MSG

    DECLARE_MESSAGE_MAP()
};

// in StyleBar.cpp
BEGIN_MESSAGE_MAP(CStyleBar, CCmdTarget)
    //{{AFX_MSG_MAP(CStyleBar)
    ON_WM_CREATE()
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

int CStyleBar::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
    if (CToolBar::OnCreate(lpCreateStruct) == -1)
        return -1;
    return 0;
}


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.

Code:
// ...in MainFrame.h
    CStyleBar m_wndStyleBar;

// ...in MainFrame.cpp
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
        return -1;

    // Tell the frame window to permit docking.
    EnableDocking(CBRS_ALIGN_ANY);

    // 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
        return -1;

    return 0;
}

BOOL CMainFrame::CreateStyleBar()
{
    if (!m_wndStyleBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_TOP
        | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC, IDW_STYLEBAR)
        || !m_wndStyleBar.LoadToolBar(IDR_STYLEBAR))
        return FALSE;

    m_wndStyleBar.SetWindowText(_T("Styles"));
    m_wndStyleBar.EnableDocking(CBRS_ALIGN_TOP | CBRS_ALIGN_BOTTOM);
    DockControlBar(&m_wndStyleBar);
    return TRUE;
}


I'm getting an assertion error:

Code:
// ...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?

-Mike

Reply With Quote
  #2  
Old March 19th, 2002, 01:35 AM
MJEggertson MJEggertson is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2002
Location: Seattle WA
Posts: 863 MJEggertson User rank is Corporal (100 - 500 Reputation Level)MJEggertson User rank is Corporal (100 - 500 Reputation Level)MJEggertson User rank is Corporal (100 - 500 Reputation Level)MJEggertson User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 sec
Reputation Power: 13
My bad....I found it:

Code:
BEGIN_MESSAGE_MAP(CStyleBar, CCmdTarget)


Heh....I forgot to change the base class there when editing the autogenerated code.

Damit, that took hours to figure out.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > [MFC] How do you derive from CToolBar?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap