MFC Dialog App & CMDIFrameWnd

mjwilliamson
mjwilliamson used Ask the Experts™
on
Hi

I've created an MFC dialog application. I added an MFC
Class CMyWnd derived from generic CWnd. I then manually
changed derived class to CMDIFrameWnd where appropriate.

On InitInstance I have the following code:

Enable3dControls();              

AfxMessageBox("About to create the window");

CRect rect(200,200, 1000,1000);


CMyWnd* pMainFrame = new CMyWnd;  // assertion failure here
if( !pMainFrame->Create(NULL, _T("Title"), WS_OVERLAPPEDWINDOW|WS_VSCROLL|WS_VISIBLE|WS_SYSMENU|WS_THICKFRAME, rect, NULL, MAKEINTRESOURCE(IDR_MAIN), NULL, NULL))  // assertion failure here
    return FALSE;

AfxMessageBox("Window Created");

pMainFrame->ShowWindow(m_nCmdShow);

HINSTANCE h = theApp.m_hInstance;
HICON ico =::LoadIcon(h, MAKEINTRESOURCE(IDR_MAIN));
BOOL bBigIcon = FALSE;
AfxMessageBox("about to update the window");
pMainFrame->SetIcon(ico, bBigIcon);
pMainFrame->UpdateWindow();
m_pMainWnd = pMainFrame;

return TRUE;


I am getting two assertion failures as shown above.
What am I doing wrong?

I should add that on ignoring the assertion failures the
window is shown as expected, with menu, icon etc.

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

 Do you have the MFC source code installed? When the assertion appears click retry and you will be dumped at the line of MFC code that has the assertion. That will tell you what is wrong.

 I suspect there is a problem using an CMDIFrameWnd outside of a Doc template.

Commented:
I think it is better to make SDI or MDI application using MFC Wizard and after this add dialog to it.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial