分类: C/C++
2008-03-10 21:12:21
// 对于SDI的 PreCreateWindow
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
cs.style &= ~FWS_ADDTOTITLE;
cs.style &= ~( WS_SIZEBOX | WS_MINIMIZEBOX | WS_MAXIMIZEBOX );
if ( cs.hMenu != NULL )
{
DestroyMenu( cs.hMenu );
cs.hMenu = NULL;
}
if( ! CFrameWnd::PreCreateWindow( cs ) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return TRUE;
} 多文档的开始销毁菜单的方法:// CMainFrame 中重载 LoadFrame
//
// virtual BOOL LoadFrame( UINT nIDResource,
// DWORD dwDefaultStyle = WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE,
// CWnd* pParentWnd = NULL, CCreateContext* pContext = NULL );
BOOL CMainFrame::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle,
CWnd* pParentWnd, CCreateContext* pContext)
{
return CFrameWnd::LoadFrame(nIDResource,dwDefaultStyle,
pParentWnd,pContext);
}
// CMainFrame 中重载 OnCreateClient, 实现禁止菜单切换
// virtual BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs,
// CCreateContext* /*pContext*/);
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs,
CCreateContext* /*pContext*/)
{
return CreateClient(lpcs,NULL);
}
// 添加以下代码:
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
cs.style &= ~FWS_ADDTOTITLE;
cs.style &= ~( WS_SIZEBOX | WS_MINIMIZEBOX | WS_MAXIMIZEBOX );
if ( cs.hMenu != NULL )
{
DestroyMenu( cs.hMenu );
cs.hMenu = NULL;
}
if( ! CFrameWnd::PreCreateWindow( cs ) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return TRUE;
} 以上的代码分别实现了SDI和MDI一开始的销毁了菜单资源!这样就可以为SDI和MDI的多模式显示作好了准备!利用 SetMenu 这 API 就可以实现动态加载菜单,呵,是不是很简单!剩下的就是参考徐景周的代码就行了。

多文档显示的正常模式

多文档显示的简单模式(单文档与此相同)

多文档显示的简洁模式(单文档与此相同)