切换视时基于FormView的对话框属性设置与ASSERT报错的问题 (Debug Assertion Failed!)
2013-03-19 01:57
423 查看
切换视时基于FormView的对话框属性设置与ASSERT报错的问题 (Debug Assertion Failed!)
分类: vc++2012-10-03 13:40 101人阅读 评论(0) 收藏 举报dialogborderdocumentationnullapplicationgoogle
最近做的项目中用到了FormView切换视图,其主要原理是:先新建一些Dialog对话框,然后给这些对话框绑定对应的View,注意:这些View要基于FormView。
一开始还好好的,利用切换视的代码进行的很顺利(网上的相关代码很多,我就不赘述了),但是,后来新加了两个Dialog,不知我怎么弄的,奇怪的事发生了:先前添加了Dialog都能正常的切换,但是,一切换新添加的Dialog,每次运行到:
BOOL CFormView::Create(LPCTSTR /*lpszClassName*/, LPCTSTR /*lpszWindowName*/,
DWORD dwRequestedStyle, const RECT& rect, CWnd* pParentWnd, UINT nID,
CCreateContext* pContext)
{
ASSERT(pParentWnd != NULL);
ASSERT(m_lpszTemplateName != NULL);
m_pCreateContext = pContext; // save state for later OnCreate
#ifdef _DEBUG
// dialog template must exist and be invisible with WS_CHILD set <——请注意此处
if (!_AfxCheckDialogTemplate(m_lpszTemplateName, TRUE))
{
ASSERT(FALSE); // invalid dialog template name
PostNcDestroy(); // cleanup if Create fails too soon
return FALSE;
}
#endif //_DEBUG
中的ASSERT时就报错,而在Release版本下却不会报错。我检查了一下这两个新加的Dialog与先前的Dialog属性有哪些不同,原来是自己把后来加的Dialog的Visible属性设置成了TRUE了, 根据代码的要求是:对话框模板必须存在,属性要设置成不可见和子窗口风格。SystemMenu和TitleBar属性最好都设为False,改完以后,一切正常~~
注:还有一种方法就是在添加Dialog资源时,在Dialog列表上点右键->添加资源,选择Dialog->IDD_FORMVIEW,再点“新建”按钮,这样新建出来的Dialog属性就会自动配好了
分割窗口时CFormView与Pane关联时出现的问题
分割窗口时,其中一个窗格Pane,所关联的视,这个视若是从 CEditView, CTreeView, CView等类导出的,则没有问题,若是从 CFormView导出的, 那么编译正常,但执行那个时会出现---------------------------
Microsoft Visual C++ Debug Library
---------------------------
Debug Assertion Failed!
Program: D:\VC_PROJECT\testMultiPane\Debug\testMultiPane.exe
File: viewform.cpp
Line: 69
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.
(Press Retry to debug the application)
---------------------------
Abort(A) Retry(R) Ignore(I)
---------------------------
错误,
原因是 CFormView 的导出类,需要与一个Dialog资源关联,这个Dialog的属性必须是ws_child,Style必须选 “下层”SystemMenu和TitleBar属性最好都设为False
参见 http://www.cnweblog.com/vcbird/archive/2005/10/10/36404.html
以前在出现
错误提示时,不知如何处理,在这次通过点击“重试”,debugger停在了
the debugge point to this line
Code:
ASSERT(FALSE); // invalid dialog template name
which appears in the following code snippet of the file VIEWFORM.cpp
Code:
BOOL CFormView::Create(LPCTSTR /*lpszClassName*/, LPCTSTR /*lpszWindowName*/,
DWORD dwRequestedStyle, const RECT& rect, CWnd* pParentWnd, UINT nID,
CCreateContext* pContext)
{
ASSERT(pParentWnd != NULL);
ASSERT(m_lpszTemplateName != NULL);
m_pCreateContext = pContext; // save state for later OnCreate
#ifdef _DEBUG
// dialog template must exist and be invisible with WS_CHILD set
if (!_AfxCheckDialogTemplate(m_lpszTemplateName, TRUE))
{
ASSERT(FALSE); //<====== debugger stops at this line // invalid dialog template name
PostNcDestroy(); // cleanup if Create fails too soon
return FALSE;
}
#endif //_DEBUG
// initialize common controls
VERIFY(AfxDeferRegisterClass(AFX_WNDCOMMCTLS_REG));
AfxDeferRegisterClass(AFX_WNDCOMMCTLSNEW_REG);
// call PreCreateWindow to get prefered extended style
CREATESTRUCT cs; memset(&cs, 0, sizeof(CREATESTRUCT));
if (dwRequestedStyle == 0)
dwRequestedStyle = AFX_WS_DEFAULT_VIEW;
cs.style = dwRequestedStyle;
if (!PreCreateWindow(cs))
return FALSE;
// create a modeless dialog
if (!CreateDlg(m_lpszTemplateName, pParentWnd))
return FALSE;
m_pCreateContext = NULL;
// we use the style from the template - but make sure that
// the WS_BORDER bit is correct
// the WS_BORDER bit will be whatever is in dwRequestedStyle
ModifyStyle(WS_BORDER|WS_CAPTION, cs.style & (WS_BORDER|WS_CAPTION));
ModifyStyleEx(WS_EX_CLIENTEDGE, cs.dwExStyle & WS_EX_CLIENTEDGE);
SetDlgCtrlID(nID);
CRect rectTemplate;
GetWindowRect(rectTemplate);
SetScrollSizes(MM_TEXT, rectTemplate.Size());
// initialize controls etc
if (!ExecuteDlgInit(m_lpszTemplateName))
return FALSE;
// force the size requested
SetWindowPos(NULL, rect.left, rect.top,
rect.right - rect.left, rect.bottom - rect.top,
SWP_NOZORDER|SWP_NOACTIVATE);
// make visible if requested
if (dwRequestedStyle & WS_VISIBLE)
ShowWindow(SW_NORMAL);
return TRUE;
}
如何,Google “dialog template must exist and be invisible with WS_CHILD set”发现网文
http://www.cnweblog.com/vcbird/archive/2005/10/10/36404.html
相关文章推荐
- 切换视时基于FormView的对话框属性设置与ASSERT报错的问题 (Debug Assertion Failed!)
- [存档]浅谈:切换视时基于FormView的对话框属性设置与ASSERT报错的问题
- 浅谈:切换视时基于FormView的对话框属性设置与ASSERT报错的问题
- 浅谈:切换视时基于FormView的对话框属性设置与ASSERT报错的问题
- Debug Assertion Failed! FILE viewform.cpp , line 69
- Debug Assertion Failed!问题怎么解决?
- Debug Assertion Failed问题解决
- 读书笔记——Windows核心编程(2)禁止C运行时触发的所有Debug Assertion Failed对话框
- net自动化测试之道基于反射的UI自动化测试—设置Form属性
- 对于 imagView 设置监听与 PAPER 左右滑动切换 VIEW 结合 会导致get不到TAB切换问题解决
- 窗体Form的FormStyle属性设置为fsStayOnTop时属性设置不起作用问题探讨。
- 读书笔记——Windows核心编程(2)禁止C运行时触发的所有Debug Assertion Failed对话框
- 在ActiveX控件对话框中添加系统自带的ocx控件出现Debug Assertion Failed
- 在代码中,子view设置的属性在viewGroup中无效的问题解决
- 安卓学习笔记(一)Android ImageButton、ImageView控件属性设置 图片显示问题
- debug assertion failed dbgheap.c line:1044 问题解决
- 出现问题"Debug Assertion Failed!"
- 窗体Form的FormStyle属性设置为fsStayOnTop时属性设置不起作用问题探讨。
- 关于Form窗体的StartPosition 属性如何设置的问题
- 对GridView、DetailsView 和 FormView 控件分页属性的PagerSettings类的设置