我为CMainFrame添加了成员CWnd m_wndSub;
在OnCreate使用 if (!m_wndSub.CreateEx(0,
AfxRegisterWndClass(0),
"子窗口",
WS_POPUPWINDOW, rc,
this,
NULL))
{
TRACE0("无法子窗口\n");
return FALSE;
}
我在~CMainFrame()调用了
m_wndSub.Detach();
m_wndSub.DestroyWindow();
为什么关闭程序时总是提示
Debug Assertion Failed
file:dbgheap.c
line:1017
expression:_BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
请高手解释
在OnCreate使用 if (!m_wndSub.CreateEx(0,
AfxRegisterWndClass(0),
"子窗口",
WS_POPUPWINDOW, rc,
this,
NULL))
{
TRACE0("无法子窗口\n");
return FALSE;
}
我在~CMainFrame()调用了
m_wndSub.Detach();
m_wndSub.DestroyWindow();
为什么关闭程序时总是提示
Debug Assertion Failed
file:dbgheap.c
line:1017
expression:_BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
请高手解释
CMyChild : public CWnd
然后才能实例化。不知是否答非所问,你试试吧!
或者
if(IsWindow(m_wndSub.m_hWnd))
{
m_wndSub.Detach();
m_wndSub.DestroyWindow();
}
只要用中模板管理那一块代码,然后加上一句,就可以产生一个和住框架一样的子窗口。
//响应打开新窗口消息
void CMainFrame::OnShowmywindow()
{
// TODO: Add your command handler code here
CSingleDocTemplate* pTemplate;
pTemplate = new CSingleDocTemplate(
IDR_GREATEBEAR,//资源,可以是自建的,也可是IDR_MAINFRAME
RUNTIME_CLASS(CXiongDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CXiongView));
AddDocTemplate(pTemplate);
pTemplate->OpenDocumentFile(NULL,true);
}
2>与主窗口同时创建。BOOL CXiongApp::InitInstance()
{
AfxEnableControlContainer(); // Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif // Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications")); LoadStdProfileSettings(); // Load standard INI file options (including MRU) // Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views. CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CXiongDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CXiongView));
AddDocTemplate(pDocTemplate); // Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo); // Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE; // The one and only window has been initialized, so show and update it.
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow(); //把同样的代码加在下面即可,但注意,这里创建的窗口和主窗口是一样的,要为己所用,必须加上自己的资源等,详见下面的第三点
CSingleDocTemplate* pTemplate;
pTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CXiongDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CXiongView));
AfxGetApp()->AddDocTemplate(pTemplate);
pTemplate->OpenDocumentFile(NULL,true); return TRUE;
}
3〉要创建自己的窗口,只要在模板管理中,加上自己的资源,自己的框架(继承于CFrameWnd),自己的视(继承与自己所需的视类),自己的文档(继承自CDocument)。
4〉要画图只要在自己的View上画图就可以了(OnDraw),但视要派生自CView。其实这样创建出来的窗口,和一般的只有主窗口时,其控制方法是一样的。
5〉最后注意别忘了头文件。
to ruihuahan(飞不起来的笨鸟)
我调整了顺序了,还是有问题
to GreateBear(黑熊)
可是我的子窗口不是基于文档-视图结构的,这总方法行不通啊