0
votes

I am incorporating a MFC ribbon to an existing SingleDoc application. I get an assertion failure while calling the method LoadFrame() on an object of type CMainFrame : public CFrameWndEx

CMainFrame* pFrame = new CMainFrame;

if (!pFrame) return FALSE;

m_pMainWnd = pFrame;

// create and load the frame with its resources` 

pFrame->LoadFrame(IDR_MAINFRAME, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, NULL);

The assertion is thrown in the function

CMFCRibbonCategory* CMFCRibbonBar::AddPrintPreviewCategory()

in the line

CString strLabel; ENSURE(strLabel.LoadString(IDS_AFXBARRES_PRINT_PREVIEW));

the call stack(I have mentioned only the function calls here) is as follows -

CMFCRibbonBar::AddPrintPrevieCategory()

CMFCRibbonBar::RecalcLayout()

CMFCRibbonBar::LoadState(const char * lpszProfileName=0x06bdf2f8, int nIndex=59398, unsigned int uiID=4294967295)

DockingManager::LoadState(const char * lpszProfileName=0x06bdf2f8, unsigned int uiID=128)

CFrameImpl::LoadDockState(const char * lpszSectionName=0x06bdf2f8)

CFrameImpl::OnLoadFrame()

CFrameWndEx::LoadFrame(unsigned int nIDResource=128, unsigned long dwDefaultStyle=13598720, CWnd * pParentWnd=0x00000000, CCreateContext * pContext=0x00000000)

App::InitInstance() - Here in this function is where I call the Loadframe

Now, I am wondering how to go about this as all that I am doing is call the LoadFrame function.

Any help will be appreciated. Thanks.

1
I believe you need to make sure the ribbon resources are included. Make a new ribbon application from the wizards and look at the .rc and .rc2 files.ta.speot.is
msdn.microsoft.com/en-us/library/bb983935.aspx might help for any other issues.ta.speot.is
@ta.speot.is - Sorry , I changed the details from where the Assertion is being thrown. Yes, I have built an other application on by using the app wizard and also gone through almost all the tutorials available on the net. I am not able to figure out a solution to this which is quite unfortunate. By debbugging the applications side by side, I could not point out to what exactly is missing in my implementation. Thanks.Eternal Learner
So, to be clear, you've looked at the .rc and .rc2 files in the wizard implementation vs. your implementation and your implementation includes the ribbon bar stuff that the wizard implementation does?ta.speot.is
@ta.sepot.is - yeah, I have matched the .rc and .rc2 as much as I can. But , I load a different IDR_MAINFRAME as compared to the one generated by the app wizard sample. Also, I just cannot find the resource IDS_AFXBARRES_PRINT_PREVIEW in the sample application too. I am guessing it is being generated during runtime. Let me know for any more pointers. Thanks.Eternal Learner

1 Answers

2
votes

MFC applications using the ribbon require that you include a few resource files for the ribbon. These files are located in the VC\atlmfc\include sub directory of your VS installation.

My guess is that you didn't compare the .rc files, but instead compared the resource items in VS. Those lines can easily be missed.

As such, your main .rc file needs these two lines in it:

#include "afxprint.rc" // printing/print preview resources

#include "afxribbon.rc" // MFC ribbon and control bar resources

You can easily do that from within Visual Studio. Go to the "Resource View" and right-click the .rc file, then select "Resource Includes ...", you can add it there.

That should do it.