subject_20141.htm

来自「一些关于vc的问答」· HTM 代码 · 共 42 行

HTM
42
字号
<p>
序号:20141 发表者:蜡笔大新 发表日期:2002-11-04 00:04:23
<br>主题:关于子窗口创建的问题
<br>内容:我为CMainFrame添加了成员CMyWnd m_wndSub;(CMyWnd derived from CWnd)<BR>在OnCreate使用 if (!m_wndSub.CreateEx(0,<BR>AfxRegisterWndClass(0),<BR>"子窗口",<BR>WS_POPUPWINDOW|WS_VISIBLE,<BR>rc,<BR>this,<BR>NULL))<BR>{<BR>TRACE0("无法创建子窗口\n");<BR>return FALSE;<BR>}<BR>子窗口可以正常显示,但是为什么关闭程序时总是提示<BR>Debug Assertion Failed<BR>file:dbgheap.c<BR>line:1017<BR>expression:_BLOCK_TYPE_IS_VALID(pHead-&gt;nBlockUse)<BR>请高手解释一下,我快急死了,为它我差点把mfc的源代码跟踪分析了个遍,但是还是一无所获,高手救救我吧
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:不说 回复日期:2002-11-04 02:27:18
<br>内容:你在关闭程序前先把这个popup的子窗口destroy掉,就是在CMainFrame的 OnClose里(没有?先虫灾一个),call一下m_wndSub.DestroyWindow()看看
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:蜡笔大新 回复日期:2002-11-04 21:30:42
<br>内容:好象加不加都一样,应该是自己调用的,加了以后问题一样,我跟踪到了<BR>BOOL CWnd::DestroyWindow()<BR>{<BR>&nbsp;&nbsp; .........<BR>&nbsp;&nbsp; if (m_pCtrlSite == NULL)<BR>到了这句出的问题&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bResult = ::DestroyWindow(m_hWnd);
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:不说 回复日期:2002-11-05 00:03:51
<br>内容:…………你在MSDN里找找这篇文章看看跟你有关系没有?<BR><BR>PRB: Modifying CWinApp Members Causes Error in DBGHEAP.C<BR><BR>The information in this article applies to:<BR><BR>The Microsoft Foundation Classes (MFC), used with:<BR>Microsoft Visual C++, 32-bit Editions, versions 4.2, 5.0, 6.0<BR><BR>--------------------------------------------------------------------------------<BR><BR><BR>SYMPTOMS<BR>The error below may occur in an MFC application where one of the following is assigned a value by the programmer: <BR><BR><BR>&nbsp;&nbsp; CWinApp::m_pszAppName<BR>&nbsp;&nbsp; CWinApp::m_pszRegistryKey<BR>&nbsp;&nbsp; CWinApp::m_pszExeName<BR>&nbsp;&nbsp; CWinApp::m_pszHelpFilePath<BR>&nbsp;&nbsp; CWinApp::m_pszProfileName <BR>The following error is displayed in a message box: <BR><BR>&nbsp;&nbsp; Debug Assertion failed<BR>&nbsp;&nbsp; Program: my.exe<BR>&nbsp;&nbsp; File: dbgheap.c<BR>&nbsp;&nbsp; Line: 1017<BR>&nbsp;&nbsp; Expression:_BLOCK_TYPE_IS_VALID(pHead-&gt;nBlockUse) <BR>In Visual C++ 6.0, the following error is displayed in a message box: <BR><BR>&nbsp;&nbsp; Debug Assertion failed<BR>&nbsp;&nbsp; Program: my.exe<BR>&nbsp;&nbsp; File: dbgheap.c<BR>&nbsp;&nbsp; Line: 1011<BR>&nbsp;&nbsp; Expression: _CrtIsValidHelpPointer(pUserData) <BR>You may see this error when you upgrade from an earlier version of Visual C++ to Visual C++ versions 4.2 or later. <BR><BR><BR><BR>CAUSE<BR>The CWinApp destructor in MFC included with Visual C++ 4.2 and later now frees the data assigned to the member variables shown above by passing the pointer to the free() function. Doing this prevents memory leaks, which would occur if an MFC regular DLL were dynamically loaded and unloaded. <BR><BR><BR><BR>RESOLUTION<BR>This behavior is by design. If you assign a value to m_pszAppName, m_pszRegistryKey, m_pszExeName, m_pszHelpFilePath, or m_pszProfileName, the data must be dynamically allocated on the heap. You may want to use the _tcsdup() run-time library function to do this.<BR><BR>Also, free the memory associated with the current pointer before assigning a new value. Here is an example: <BR><BR><BR>&nbsp;&nbsp; // First free the string that was allocated by MFC in the startup<BR>&nbsp;&nbsp; // of CWinApp. The string is allocated before InitInstance is<BR>&nbsp;&nbsp; // called.<BR>&nbsp;&nbsp; free((void*)m_pszProfileName);<BR><BR>&nbsp;&nbsp; // Change the name of the .INI file--CWinApp destructor will free<BR>&nbsp;&nbsp; // the memory.<BR>&nbsp;&nbsp; m_pszProfileName=_tcsdup(_T("d:\\somedir\\myini.ini")); <BR><BR>Additional query words: 4.10 port porting strdup <BR><BR>Keywords : kberrmsg kbMFC kbVC420 kbVC500 kbVC600 kbGrpMFCATL <BR>Version : winnt:4.2,5.0,6.0 <BR>Platform : winnt <BR>Issue type : kbprb <BR>Technology : kbvc <BR><BR><BR>Last Reviewed: March 14, 2000<BR>&copy; 2000 Microsoft Corporation. All rights reserved. Terms of Use.<BR> <BR><BR><BR><BR>--------------------------------------------------------------------------------<BR>Send feedback to MSDN.Look here for MSDN Online resources. 
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:蜡笔大新 回复日期:2002-11-06 20:53:37
<br>内容:谢谢,我把m_wndSub类型改为CMyWnd*,然后在oncreate中动态分配内存,不用调用destroywindow()就正常了,如果调用反而会出别的错,不知什么原因。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:不说 回复日期:2002-11-06 21:20:43
<br>内容:那个是我错了,我把你的问题跟我曾经碰到过的一个问题给搞混了,child window的OnDestroy()会被父窗口自动调用的,如果再调的话的确会出问题的,呵呵……不好意思
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:蜡笔大新 回复日期:2002-11-08 21:13:04
<br>内容:非常感谢你的热心帮助
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?