Question

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.

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top