⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subject_66843.htm

📁 vc
💻 HTM
字号:
<p>
序号:66843 发表者:孙赟 发表日期:2003-12-26 21:07:14
<br>主题:想在视图中生成一个窗口,但出错了,帮帮忙!
<br>内容:直接从CWnd继承来的<BR>void CMyWndView::OnInitialUpdate() <BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;CView::OnInitialUpdate();<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;// TODO: Add your specialized code here and/or call the base class<BR>&nbsp;&nbsp;&nbsp;&nbsp;if(m_pMyWnd==NULL)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CMyWnd *m_pMyWnd= new CMyWnd;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!m_pMyWnd) return;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LPCTSTR&nbsp;&nbsp;classname=&#34;CMyWnd&#34;;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LPCTSTR windowname=&#34;MyWnd&#34;;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CRect rect;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GetClientRect(rect);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rect.bottom=rect.bottom-100;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_pMyWnd-&gt;Create(classname,windowname,WS_OVERLAPPEDWINDOW,rect,this,333,NULL);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_pMyWnd-&gt;ShowWindow(SW_SHOW);//运行这一句时出错了,ASSERT(::IsWindow(m_hWnd));报警<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_pMyWnd-&gt;UpdateWindow();<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>}<BR>
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:孙赟 回复日期:2003-12-26 21:48:38
<br>内容:解决了!把<BR>m_pMyWnd-&gt;Create(classname,windowname,WS_OVERLAPPEDWINDOW,rect,this,333,NULL);<BR>改成<BR>m_pMyWnd-&gt;Create(NULL,windowname,WS_OVERLAPPEDWINDOW,rect,this,333,NULL);<BR>就行了,那位能告诉我为什么呀?<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:hurtmanzc 回复日期:2003-12-26 22:10:09
<br>内容:Create的第一个参数是已经注册的窗口类的名字,你的classname不是,<BR>如果为NULL,则用CWnd默认的窗口类名。<BR><BR>另外,你的这句<BR>CMyWnd *m_pMyWnd= new CMyWnd;<BR>有点问题,从if(m_pMyWnd==NULL)看m_pMyWnd应该是CMyWndView的成员变量,不需要重复定义。而且这样还有内存泄露。你可以将之该为<BR>m_pMyWnd= new CMyWnd;<BR>并在CMyWndView的析构函数里加入:<BR>if(m_pMyWnd!=NULL)<BR>&nbsp;&nbsp; delete m_pMyWnd;<BR><BR>以下摘自MSDN&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>CWnd::Create&nbsp;&nbsp;<BR>virtual BOOL Create( LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT&amp; rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL);<BR><BR>Return Value<BR><BR>Nonzero if successful; otherwise 0.<BR><BR>Parameters<BR><BR>lpszClassName<BR><BR>Points to a null-terminated character string that names the Windows class (a WNDCLASS structure). The class name can be any name registered with the global AfxRegisterWndClass function or any of the predefined control-class names. If NULL, uses the default CWnd attributes.<BR><BR>lpszWindowName<BR><BR>Points to a null-terminated character string that contains the window name.<BR><BR>dwStyle<BR><BR>Specifies the window style attributes.&nbsp;&nbsp;WS_POPUP cannot be used. If you wish to create a pop-up window, use CWnd::CreateEx instead.<BR><BR>rect<BR><BR>The size and position of the window, in client coordinates of pParentWnd.<BR><BR>pParentWnd<BR><BR>The parent window.<BR><BR>nID<BR><BR>The ID of the child window.<BR><BR>pContext<BR><BR>The create context of the window.<BR><BR>Remarks<BR><BR>Creates a Windows child window and attaches it to the CWnd object. <BR><BR>You construct a child window in two steps. First, call the constructor, which constructs the CWnd object. Then call Create, which creates the Windows child window and attaches it to CWnd. Create initializes the window’s class name and window name and registers values for its style, parent, and ID.<BR><BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:孙赟 回复日期:2003-12-27 00:15:27
<br>内容:多谢!<BR>我也发现问题了,我改成了m_pMyWnd= new CMyWnd;<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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -