一、宏定义
//窗口属性修改宏
AFX_STATIC BOOL AFXAPI _AfxModifyStyle(HWND hWnd, int nStyleOffset, DWORD dwRemove, DWORD dwAdd, UINT nFlags);#define DELETE_BORDER_CWND(pCWndClass) \
{\
pCWndClass->ModifyStyleEx(WS_EX_CLIENTEDGE|WS_EX_WINDOWEDGE|WS_EX_STATICEDGE,0,SWP_DRAWFRAME);\
pCWndClass->ModifyStyle(WS_THICKFRAME|WS_CAPTION|WS_BORDER|WS_SYSMENU , 0, SWP_DRAWFRAME);\
pCWndClass->ModifyStyleEx(WS_EX_APPWINDOW,WS_EX_TOOLWINDOW);\
}
#define DELETE_BORDER_CS(cs) \
{\
cs.dwExStyle &= ~(WS_EX_CLIENTEDGE|WS_EX_WINDOWEDGE|WS_EX_STATICEDGE);\
cs.style &= ~(WS_THICKFRAME|WS_CAPTION|WS_BORDER|WS_SYSMENU);\
}
#define DELETE_BORDER_HWND(hWnd) \
{\
_AfxModifyStyle(hWnd, GWL_EXSTYLE, WS_EX_CLIENTEDGE|WS_EX_WINDOWEDGE|WS_EX_STATICEDGE,0,SWP_DRAWFRAME);\
_AfxModifyStyle(hWnd, GWL_STYLE, WS_THICKFRAME|WS_CAPTION|WS_BORDER|WS_SYSMENU, 0, SWP_DRAWFRAME);\
}
放在头文件stdafx.h或其他头文件都可以。
二、CXXApp::InitInstance()函数内容修改,在pMainFrame->ShowWindow(m_nCmdShow);前面和后面修改
1.m_pMainWnd = pMainFrame;后面添加
pDocTemplate->m_hMenuShared=NULL; //屏蔽掉共享菜单
pMainFrame->ModifyStyleEx(WS_EX_CLIENTEDGE|WS_EX_WINDOWEDGE|WS_EX_STATICEDGE,0,SWP_DRAWFRAME); //屏蔽主窗口的边框、标题和菜单
pMainFrame->ModifyStyle(WS_THICKFRAME|WS_CAPTION|WS_BORDER|WS_SYSMENU , 0, SWP_DRAWFRAME); //屏蔽主窗口的边框、标题和菜单
pMainFrame->ModifyStyleEx(WS_EX_APPWINDOW,WS_EX_TOOLWINDOW); //屏蔽任务栏显示
2.pMainFrame->UpdateWindow();后面添加
//屏蔽MDIClient窗口的边框、标题和菜单
AFX_STATIC BOOL AFXAPI _AfxModifyStyle(HWND hWnd, int nStyleOffset, DWORD dwRemove, DWORD dwAdd, UINT nFlags);
_AfxModifyStyle(pMainFrame->m_hWndMDIClient, GWL_EXSTYLE, WS_EX_CLIENTEDGE|WS_EX_WINDOWEDGE|WS_EX_STATICEDGE,0,SWP_DRAWFRAME);\
_AfxModifyStyle(pMainFrame->m_hWndMDIClient, GWL_STYLE, WS_THICKFRAME|WS_CAPTION|WS_BORDER|WS_SYSMENU, 0, SWP_DRAWFRAME);\
三、MainFrame.cpp中CMainFrame::OnCreate里面屏蔽掉工具栏、任务拦、菜单
//屏蔽工具栏、状态栏
#if 0
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("未能创建工具栏\n");
return -1; // 未能创建
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("未能创建状态栏\n");
return -1; // 未能创建
}
// TODO: 如果不需要工具栏可停靠,则删除这三行
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
#endif
SetMenu(NULL);//屏蔽菜单
四 、BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)后面的CMDIChildWnd::PreCreateWindow(cs)后面添加
//屏蔽3D边框
cs.style = WS_CHILD | WS_VISIBLE;
cs.dwExStyle &=~WS_EX_CLIENTEDGE;
五、激活框时执行
1.ChildFrm.h中添加virtual void ActivateFrame(int nCmdShow = -1);
2.在ChildFrm.cpp中添加一个函数
//激活框架时执行
void CChildFrame::ActivateFrame(int nCmdShow)
{
nCmdShow = SW_MAXIMIZE;
CMDIChildWnd::ActivateFrame(nCmdShow);
}
六、在BOOL CXXXView::PreCreateWindow(CREATESTRUCT& cs)中添加
DELETE_BORDER_CS(cs);
cs.style = WS_CHILD | WS_VISIBLE;