C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
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 19th, 2002, 12:30 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: 9
[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, 02: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: 9
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?


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




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

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




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek