Discussion:
How to create a CWnd window in MFC
(too old to reply)
kimi
2004-08-10 01:13:09 UTC
Permalink
I hate the wizard, because it only let me create the mdi/sdi and dialog box.
I want to create my own windows with MFC. So, I create a dialog box project
and delete all info about dialog box, then inherit the CWnd class and create
in the CWinApp's function. like following:
BOOL CCreateWndApp::InitInstance()
{
AfxEnableControlContainer();

#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
// this is what I write
CTestWnd test;
CString classname = AfxRegisterWndClass(CS_DBLCLKS);
//assert will occour when create window
test.Create((LPCTSTR)classname,
TEXT("TEST"),
WS_VISIBLE | WS_OVERLAPPED,
CRect(100,100,300,300),
NULL,
IDW_MAIN_WND,
NULL);
return TRUE;
}
There is a Assertion fail: file wincore.cpp line 735.
Ajay Kalra
2004-08-10 02:18:51 UTC
Permalink
Your CTestWnd object goes out of scope as you are creating it on the stack.
Create it on the heap instead. Follow the steps about how wizard creates a
CFrameWnd (mainframe window) in default doc/view project. There are other
things that you need to do, including calling delete this in OnPostNCDestroy
of CWnd. Pick up Jeff Prosise's book on MFC for reference.

--
Ajay Kalra [MVP - VC++]
Post by kimi
I hate the wizard, because it only let me create the mdi/sdi and dialog box.
I want to create my own windows with MFC. So, I create a dialog box project
and delete all info about dialog box, then inherit the CWnd class and create
BOOL CCreateWndApp::InitInstance()
{
AfxEnableControlContainer();
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
// this is what I write
CTestWnd test;
CString classname = AfxRegisterWndClass(CS_DBLCLKS);
//assert will occour when create window
test.Create((LPCTSTR)classname,
TEXT("TEST"),
WS_VISIBLE | WS_OVERLAPPED,
CRect(100,100,300,300),
NULL,
IDW_MAIN_WND,
NULL);
return TRUE;
}
There is a Assertion fail: file wincore.cpp line 735.
Bill Thompson
2004-08-10 04:17:55 UTC
Permalink
Post by kimi
I hate the wizard, because it only let me create the mdi/sdi and dialog box.
I want to create my own windows with MFC. So, I create a dialog box project
and delete all info about dialog box, then inherit the CWnd class and create
BOOL CCreateWndApp::InitInstance()
{
AfxEnableControlContainer();
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
// this is what I write
CTestWnd test;
CString classname = AfxRegisterWndClass(CS_DBLCLKS);
//assert will occour when create window
test.Create((LPCTSTR)classname,
TEXT("TEST"),
WS_VISIBLE | WS_OVERLAPPED,
CRect(100,100,300,300),
NULL,
IDW_MAIN_WND,
NULL);
return TRUE;
}
There is a Assertion fail: file wincore.cpp line 735.
Another useful reference is "MFC Internals" by Shepard/Wingo

Loading...