MFC隐藏(去除)客户区的边框以及隐藏非客户区

  我承认我被此问题困扰过,好在找到了解决方法,如下:

  1.在C****View::PreCreateWindow(CREATESTRUCT& cs)函数内增加:cs.style &= ~WS_BORDER; 

  2.在CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)函数内增加:ModifyStyleEx(WS_EX_CLIENTEDGE, 0, SWP_FRAMECHANGED);注意:要增加到OnCreate函数的最前面(即if (CFrameWnd::OnCreate(lpCreateStruct) == -1)前面)。

 

附1:网友解决办法:

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

先要去掉view的边框,代码如下:
BOOL CSDIView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs cs.style &=~WS_BORDER;//加入的代码 return CFormView::PreCreateWindow(cs); }

然后在去掉外部Frame的客户区边框,代码如下:
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { if( !CFrameWnd::PreCreateWindow(cs) ) return FALSE; // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs cs.dwExStyle&=~WS_EX_CLIENTEDGE;//加入的代码,一定要在CFrameWnd::PreCreateWindow(cs)之后执行 return TRUE; }

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

 

 附2:隐藏非客户区的方法:

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

在MainFrm.cpp的OnCreate()函数中加上如下代码可以隐藏窗口的非客户区
ModifyStyle(WS_CAPTION|WS_THICKFRAME,   0,   SWP_DRAWFRAME);//函数的第一行
SetMenu(NULL);//第二行
m_wndToolBar.ShowWindow(SW_HIDE);//在toolbar.Create的下面一行
m_wndStatusBar.ShowWindow(SW_HIDE);//在m_wndStatusbar.Create下面一行
整个函数如下:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { ModifyStyle(WS_CAPTION|WS_THICKFRAME, 0, SWP_DRAWFRAME);后加的 SetMenu(NULL);//后加的 if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; 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( "Failed to create toolbar/n "); return -1; // fail to create } m_wndToolBar.ShowWindow(SW_HIDE);//后加的 if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT))) { TRACE0( "Failed to create status bar/n "); return -1; // fail to create } m_wndStatusBar.ShowWindow(SW_HIDE);//后加的 // TODO: Delete these three lines if you don 't want the toolbar to // be dockable m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_wndToolBar); return 0; }
----------------------------------------------------------------------------------------------------------------

你可能感兴趣的:(程序技术)