Reputation: 342
So, here's my code (for simplicity I put it all into one file):
#include <afxwin.h>
#include "resource.h"
class CMainWnd : public CFrameWnd
{
};
class CApp : public CWinApp
{
public:
virtual BOOL InitInstance()
{
CMainWnd* wnd = new CMainWnd();
if (!wnd->Create(0, _T("test"))) return FALSE;
m_pMainWnd = wnd;
wnd->ShowWindow(SW_SHOW);
wnd->UpdateWindow();
return TRUE;
}
};
CApp app;
It creates simple window with default parameters and title "test". Works perfectly. But then, I want to load my window from resources, so I can put something to it. I replace:
if (!wnd->Create(0, _T("test"))) return FALSE;
with
if (!wnd->LoadFrame(IDD_CLIENTWINDOW)) return FALSE;
(IDD_CLIENTWINDOW
is ID of my dialog in resources). LoadFrame returns FALSE, and program exits. There's debug message in output:
Warning: failed to load menu for CFrameWnd.
But there's no menu in dialog IDD_CLIENTWINDOW
that I created. How do I load frame correctly? What am I missing?
Upvotes: 1
Views: 4169
Reputation: 6040
What you are trying won't work. LoadFrame() with the ID of a dialog won't load a dialog. If you want to use a dialog, make CWnd derive from CDialog or use a view derived from CFormView. Your call to LoadFrame is failing because you don't have a menu resource with the correct ID. But, you're not really trying to do that.
I recommend you use the AppWizard to generate a new application that is either dialog based or CFormView based and see what kind of code is generated. You can look at the code to see what you really want to do.
Upvotes: 1