关闭主界面的问题,up有分

xiaoliuzi 2003-08-15 11:16:55
在SDI的程序中,我想关闭一个窗口界面,同时主进程不会结束,以便新生成一个窗口界面,好像发送WM_CLOSE,不行,那会结束整个APP。
挺简单的问题,望大虾们,动动键盘。呵呵。
...全文
93 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
feeboby 2003-08-16
  • 打赏
  • 举报
回复
up
xiaoliuzi 2003-08-16
  • 打赏
  • 举报
回复
不好意思,麻烦了大家,问题我已解决。主要原因是我没仔细看msdn上的东东。实际上用m_pMainWnd的DestroyWindow();完全可行。当然标准的调用是:OnClose ();呵呵,msdn上的原话如下:
Destroying Frame WindowsSee Also
Using Frame Windows
The MFC framework manages window destruction as well as creation for those windows associated with framework documents and views. If you create additional windows, you are responsible for destroying them.

In the framework, when the user closes the frame window, the window's default OnClose handler calls DestroyWindow. The last member function called when the Windows window is destroyed is OnNcDestroy, which does some cleanup, calls the Default member function to perform Windows cleanup, and lastly calls the virtual member function PostNcDestroy. The CFrameWnd implementation of PostNcDestroy deletes the C++ window object. You should never use the C++ delete operator on a frame window. Use DestroyWindow instead.

When the main window closes, the application closes. If there are modified unsaved documents, the framework displays a message box to ask if the documents should be saved and ensures that the appropriate documents are saved if necessary.
我多希望自己能给自己加分。呵呵。结铁吧

rabithao 2003-08-15
  • 打赏
  • 举报
回复
m_pMainWnd->ShowWindow(SW_HIDE);
马丁当 2003-08-15
  • 打赏
  • 举报
回复
你说的不是太明白。
因为SDI结构的程序在CWinApp的InitInstance函数中将CWinApp的m_pMainWnd
指针指到了SDI的框架类中。因此如果你的m_pMainWnd关闭,则CWinApp也就关了。
CWinApp是个主线程类(CWinThread),用来处理你的消息
AkiraChing 2003-08-15
  • 打赏
  • 举报
回复
void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam)
{
if(nID==SC_CLOSE)
{
ShowWindow(SW_HIDE);
return;
}


CFrameWnd::OnSysCommand(nID, lParam);

}
zerphy 2003-08-15
  • 打赏
  • 举报
回复
楼上有理,关闭一个界面会关闭整个程序的,不如用MDI了
akiko 2003-08-15
  • 打赏
  • 举报
回复
AfxGetMainWnd()->ShowWindow(SW_HIDE);
xiaoliuzi 2003-08-15
  • 打赏
  • 举报
回复
还有刚才,我说的这番话,也就是通过CDocTemplate生成一套CDocument/CView/CFramae的方法,感兴趣的可以在msdn中通过在Index中输入GetFirstDocTemplatePosition,可以看到。直接在Index中输入CDocMange好像不行。
xiaoliuzi 2003-08-15
  • 打赏
  • 举报
回复
hehe,多谢这么多高手指教。现在问题是我想让App中的m_pMainWnd指针换一个内容,不知道你们知道我的意思吗,我通过App中的m_pDocManager找到一个CDocTemplate,然后重新生成一个CDocument/CView/CFramae,当然我的在App的Initinstance中我用AddDocTemplate了两次。(不好意思这段话我知道很拗口,希望大虾们耐心点看)
所以用m_pMainWnd->ShowWindow(SW_HIDE)不行,我现在的需求不允许我隐藏,涉及到共享冲突等等,在我通过CDocTemplate指针生成一套CDocument/CView/CFramae前,m_pMainWnd中的东东必须清空,所以用DestroyWindow()也不行,DestroyWindow是CWnd的成员函数,他用来清空CDialog的东东还行,可是大虾们,我现在是要清空CDocument/CView/CFramae这一套东东。
还有我的思路肯定可行,既然我都可以通过CDocTemplate生成一套CDocument/CView/CFramae东东,那个MFC老人家肯定有办法让我摧毁这一套东东。
呵呵,请大虾们耐心的看完我的话,如果是一个消息就可以搞定,请直接告诉我,如果需要一套动作,请给我提示,我会在你的提示下完成这一套动作的。
lygfqy 2003-08-15
  • 打赏
  • 举报
回复
DestroyWindow();
ejiue 2003-08-15
  • 打赏
  • 举报
回复
up。
AkiraChing(水银)写的那个也记下了。
是作了消息拦截吧。good。
cnhome 2003-08-15
  • 打赏
  • 举报
回复
只管up

--------------------------------------

玫瑰花的艳红是拿来给女子装饰的;
薄荷酒的翠绿是拿来给男子点缀的;
高楼上的灯火是拿来给旅人凝视的;
我的寂寞是拿来给我等的人挥霍的.
笑面佛_正版 2003-08-15
  • 打赏
  • 举报
回复
谁都懂得 隐藏不就得了吗
gzshd 2003-08-15
  • 打赏
  • 举报
回复
来晚了
m_pMainWnd->ShowWindow(SW_HIDE);

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧