KB956003: BUG: MFC Feature Pack wizard generated code with CFormView-derived view shows Debug Assertion
- KNOWLEDGE BASE SOLUTIONS
KNOWLEDGE BASE SOLUTIONS PROVIDE INFORMATION DIRECTLY FROM WITHIN THE MICROSOFT SUPPORT ORGANIZATION. THE INFORMATION CONTAINED HEREIN IS CREATED IN RESPONSE TO EMERGING OR UNIQUE TOPICS, OR IS INTENDED SUPPLEMENT OTHER KNOWLEDGE BASE INFORMATION.
Link to Original Article from Microsoft Support
BUG: MFC Feature Pack wizard generated code with CFormView-derived view shows Debug Assertion
Action
Note: This article applies to the Visual C++ 2008 Feature Pack
1.
Create a MFC Document/View application.
2.
Under Application Type, select the Project style as “Office”.
3.
Select Use of MFC as “static library”, Click Next.
4.
Under Generated Classes, select the CFormView as base class for application view.
5.
Click Finish.
6.
A message will appear saying “No printing support will be available for CFormView”. Click Yes.
7.
Build and Run your application.
Result
The application shows a debug assertion on f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\afxribbonbar.cpp, Line: 3891
The following function shows the assertion:
CMFCRibbonCategory* CMFCRibbonBar::AddPrintPreviewCategory()
{
...
// This line shows the assertion
ENSURE(str1.LoadString(AFX_IDS_ONEPAGE));
...
}- Edited byAndrew BrennerMSFT, AdministratorTuesday, September 02, 2008 8:45 PMedit
- Edited byXiaoyun Li – MSFT Thursday, September 04, 2008 2:13 AMedit
- Edited byXiaoyun Li – MSFT Tuesday, September 16, 2008 9:58 AMedit
Answers
- Cause
During the initialization of ribbon bar control, the application calls SetQuickAccessDefaultState() to set the Quick Access Toolbar. Inside this function, the ribbon bar tries to recalculate its layout by calling RecalcLayout() function. This function internally checks if printing is supported by the class, then it adds it to the Print Preview Category. While adding it to this category, the application tries to load a printing string resource with ID AFX_IDS_ONEPAGE. Since this resource ID is not part of the application instance, loading it shows an debug assertion.
Resolution
Disable the Print Preview for Ribbon Bar. This can be done using CMFCRibbonBar::EnablePrintPreview function.
More Information
This is a know bug with the wizard-generated code. CFormView classes do not have printing support. After creating the project, the wizard does prompt the message “No printing support will be available for CFormView”, but it fails to generate correct code for ribbon bar for disabling the printing.
Making the following change allows it to work.
void CMainFrame::InitializeRibbon()
{
...
// Disable the Print Preview for Ribbon Bar
m_wndRibbonBar.EnablePrintPreview(FALSE);
m_wndRibbonBar.SetQuickAccessCommands(lstQATCmds);
...
}
As the application links statically to MFC, the ID will not be available in the application instance. All standard MFC resources are selectively built or not built into your module, based on wizard selections. For dynamic link they are always part of the MFC80[u][d].dll.
See Also
Concepts
MFC Hierarchy Chart (http://msdn.microsoft.com/en-us/library/bb982033.aspx)
Reference
CMFCRibbonBar Class (http://msdn.microsoft.com/en-us/library/bb983906.aspx)DISCLAIMER
MICROSOFT AND/OR ITS SUPPLIERS MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY, RELIABILITY OR ACCURACY OF THE INFORMATION CONTAINED IN THE DOCUMENTS AND RELATED GRAPHICS PUBLISHED ON THIS WEBSITE (THE “MATERIALS”) FOR ANY PURPOSE. THE MATERIALS MAY INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS AND MAY BE REVISED AT ANY TIME WITHOUT NOTICE.
TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, MICROSOFT AND/OR ITS SUPPLIERS DISCLAIM AND EXCLUDE ALL REPRESENTATIONS, WARRANTIES, AND CONDITIONS WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO REPRESENTATIONS, WARRANTIES, OR CONDITIONS OF TITLE, NON INFRINGEMENT, SATISFACTORY CONDITION OR QUALITY, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, WITH RESPECT TO THE MATERIALS.- Marked As Answer byXiaoyun Li – MSFT Thursday, August 28, 2008 4:51 AM
- Edited byXiaoyun Li – MSFT Thursday, August 28, 2008 4:53 AMedit
- Edited byXiaoyun Li – MSFT Thursday, August 28, 2008 4:54 AMedit
All Replies
- Cause
During the initialization of ribbon bar control, the application calls SetQuickAccessDefaultState() to set the Quick Access Toolbar. Inside this function, the ribbon bar tries to recalculate its layout by calling RecalcLayout() function. This function internally checks if printing is supported by the class, then it adds it to the Print Preview Category. While adding it to this category, the application tries to load a printing string resource with ID AFX_IDS_ONEPAGE. Since this resource ID is not part of the application instance, loading it shows an debug assertion.
Resolution
Disable the Print Preview for Ribbon Bar. This can be done using CMFCRibbonBar::EnablePrintPreview function.
More Information
This is a know bug with the wizard-generated code. CFormView classes do not have printing support. After creating the project, the wizard does prompt the message “No printing support will be available for CFormView”, but it fails to generate correct code for ribbon bar for disabling the printing.
Making the following change allows it to work.
void CMainFrame::InitializeRibbon()
{
...
// Disable the Print Preview for Ribbon Bar
m_wndRibbonBar.EnablePrintPreview(FALSE);
m_wndRibbonBar.SetQuickAccessCommands(lstQATCmds);
...
}
As the application links statically to MFC, the ID will not be available in the application instance. All standard MFC resources are selectively built or not built into your module, based on wizard selections. For dynamic link they are always part of the MFC80[u][d].dll.
See Also
Concepts
MFC Hierarchy Chart (http://msdn.microsoft.com/en-us/library/bb982033.aspx)
Reference
CMFCRibbonBar Class (http://msdn.microsoft.com/en-us/library/bb983906.aspx)DISCLAIMER
MICROSOFT AND/OR ITS SUPPLIERS MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY, RELIABILITY OR ACCURACY OF THE INFORMATION CONTAINED IN THE DOCUMENTS AND RELATED GRAPHICS PUBLISHED ON THIS WEBSITE (THE “MATERIALS”) FOR ANY PURPOSE. THE MATERIALS MAY INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS AND MAY BE REVISED AT ANY TIME WITHOUT NOTICE.
TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, MICROSOFT AND/OR ITS SUPPLIERS DISCLAIM AND EXCLUDE ALL REPRESENTATIONS, WARRANTIES, AND CONDITIONS WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO REPRESENTATIONS, WARRANTIES, OR CONDITIONS OF TITLE, NON INFRINGEMENT, SATISFACTORY CONDITION OR QUALITY, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, WITH RESPECT TO THE MATERIALS.- Marked As Answer byXiaoyun Li – MSFT Thursday, August 28, 2008 4:51 AM
- Edited byXiaoyun Li – MSFT Thursday, August 28, 2008 4:53 AMedit
- Edited byXiaoyun Li – MSFT Thursday, August 28, 2008 4:54 AMedit


