在mfc中,设置一个隐藏菜单栏,工具栏,状态栏,最大化、最小化、关闭按钮的窗体

作者在 2011-11-09 23:44:37 发布以下内容
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
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))
*/
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC))
{
   TRACE0("Failed to create toolbar\n");
  return -1;      // fail to create
}

// 去掉状态栏
/*

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
}
*/

// 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);

// 设置标题--标题显示为:无标题-天志的导航
//this->SetTitle("天志的导航");


// 隐藏最大化,最小化,关闭按钮
ModifyStyle(WS_SYSMENU, 0);


// 隐藏标题栏
ModifyStyle(WS_CAPTION, 0);

// 去掉菜单栏
SetMenu(NULL);

// 全屏显示
RECT rc;
::GetWindowRect(::GetDesktopWindow(), &rc);  
this->MoveWindow(&rc);

return 0;
}
 
去掉标题栏:

在OnCreate函数中,添加如下代码:
ModifyStyle(WS_CAPTION, 0, SWP_FRAMECHANGED);

单文档,多文档中都是如此

子窗体为:CMDIChildWnd的子类。
在多文档界面中,去掉菜单栏:
在子窗体的OnMDIActivate函数中,添加如下行:
AfxGetMainWnd()->SetMenu(NULL);

父窗体的最大化显示:
在子窗体的OnCreateClient函数中,添加如下行:
RECT rc;
::GetWindowRect(::GetDesktopWindow(), &rc); 
this->MoveWindow(&rc);

子窗体的最大化显示:
重写ActivateFrame函数,在行数中添加:
nCmdShow = SW_SHOWMAXIMIZED;   

关闭子窗体是去掉保存提示:
在Doc类中,重写SaveModified函数,代码为:
return TRUE;


下面是自己实验后的代码

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    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
    }

    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
    }

    // 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;
*/
}
 

窗口程序 | 阅读 4499 次
文章评论,共0条
游客请输入验证码