MFC中希望程序启动时直接进入全屏状态或普通状态(通过启动参数控制)这里指的是CView占满包括任务栏的整个屏幕
(不是最大化窗口)原先的贴子中的方法必须在普通窗口创建好以后才能通过菜单进入全屏状态
所以不能直接解决这个问题还请高手指教: )

解决方案 »

  1.   

    WINDOWPLACEMENT wpNew;

    if (!IsFullScreen())
    {
    // We'll need these to restore the original state.
    m_wpPrev.length = sizeof m_wpPrev;
    GetWindowPlacement(&m_wpPrev);

    CMDIChildWnd* pChildWnd = MDIGetActive();
    CWnd* pViewWnd = pChildWnd->GetActiveView();
    if (pViewWnd == NULL)
    return; CRect rectDesktop, rectFrame, rectView; // Adjust RECT to new size of window
    VERIFY(::GetWindowRect(::GetDesktopWindow(), &rectDesktop));
    GetWindowRect(&rectFrame);
    pViewWnd->GetWindowRect(&rectView);
    rectFrame.InflateRect(
    rectView.left - rectDesktop.left,
    rectView.top - rectDesktop.top,
    rectDesktop.right - rectView.right,
    rectDesktop.bottom - rectView.bottom);

    // Remember this for OnGetMinMaxInfo()
    m_rectFullScreenWindow = rectFrame;

    wpNew = m_wpPrev;
    wpNew.showCmd = SW_SHOWNORMAL;
    wpNew.rcNormalPosition = rectFrame;

    m_pwndFullScreenBar = new CBCGPToolBar;

    if (!m_pwndFullScreenBar->Create(this))
    {
                TRACE0("Failed to create toolbar\n");
    return;      // fail to create
    }

    //don't allow the toolbar to dock
    CBCGPToolbarButton button(ID_VIEW_FULLSCREEN, -1, _T("Close Full Screen"), FALSE, TRUE);
    m_pwndFullScreenBar->InsertButton(button);
    m_pwndFullScreenBar->EnableDocking(0);
    m_pwndFullScreenBar->SetWindowPos(0, 100, 100, 100, 100, SWP_NOZORDER | SWP_NOACTIVATE | SWP_SHOWWINDOW);
    m_pwndFullScreenBar->SetWindowText(_T("Full Screen"));
    m_pwndFullScreenBar->FloatControlBar(CRect(100, 100, 200, 200));
    m_bFullScreen = true;
    }
    else
    {
    // Destroy the toolbar
    CWnd* pWnd = m_pwndFullScreenBar->GetParentMiniFrame();
    if (pWnd == NULL)
    pWnd = m_pwndFullScreenBar;
    VERIFY(pWnd->DestroyWindow()); delete m_pwndFullScreenBar; m_pwndFullScreenBar = NULL; // !!!! This was the code that was needed in MFC and BCG Standard !!!!
    //m_pwndFullScreenBar->DestroyWindow();
    //delete m_pwndFullScreenBar; m_pwndFullScreenBar = NULL;
    // !!!!!!!!

    m_bFullScreen = false;

    { // This is a workaround to prevent the toolbars from being broken
    // into different rows, when the window is maximized and
    // the restored position is too small.
    WINDOWPLACEMENT wpNew(m_wpPrev);
    VERIFY(::CopyRect(&wpNew.rcNormalPosition, &m_rectFullScreenWindow));
    VERIFY(SetWindowPlacement(&wpNew));
    } wpNew = m_wpPrev;
    }

    VERIFY(SetWindowPlacement(&wpNew));
      

  2.   

    模拟菜单命令?
    AfxGetMainWnd()->SendMessage(WM_COMMAND,?);
      

  3.   

    CMainFrame * pframe = (CMainFrame*)GetMainWnd();
    pframe->SendMessage(WM_COMMAND,IDR_FULLSCREEN);
      

  4.   

    在InitInstance()函数中添加CMainFrame * pframe = (CMainFrame*)GetMainWnd();
    pframe->SendMessage(WM_COMMAND,IDR_FULLSCREEN);
      

  5.   

    to:etre(林荃)
    OnCreate时Window还没建好,那么这段代码加到什么位置呢才能实现初始全屏呢?
      

  6.   

    To: DentistryDoctor
    因为执行全屏的函数必须在窗口正常创建好以后才能工作,
    那么
    AfxGetMainWnd()->SendMessage(WM_COMMAND,?);
    放在代码中的什么位置才能保证在窗口正常创建好时执行呢?
      

  7.   

    在CWinCpp::InitInstance()中有这样的一段代码啊,
    {
             CMainFrame* pMainFrame = new CMainFrame;
    if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
    return FALSE;
    m_pMainWnd = pMainFrame;
    pMainFrame->ShowWindow(SW_SHOWMAXIMIZED);
    pMainFrame->UpdateWindow();
             pMainFrame->SendMessage(WM_COMMAND,0,0);
    }
    在CMainFrame中响应这个消息WM_COMMAND
      

  8.   

    在BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)函数中添加如下代码 
           cs.cx = GetSystemMetrics(SM_CXSCREEN);
    cs.cy = GetSystemMetrics(SM_CYSCREEN);
      

  9.   

    To:huaboy408(闭关修练)
    试过了,好像不行啊这里指的是CView占满包括任务栏的整个屏幕
    (不是最大化窗口)
      

  10.   

    CRect rc;
    GetWindowRect(&rc);
    SetWindowLong(m_hWnd, GWL_STYLE, 
    GetWindowLong(m_hWnd, GWL_STYLE) & 
    (~(WS_CAPTION | WS_BORDER)));  MoveWindow( -5 , -5 ,
    GetSystemMetrics(SM_CXSCREEN)+10,
    GetSystemMetrics(SM_CYSCREEN)+10,
    TRUE);把上面这段代码放到CMainFrame中的OnShowWindow(BOOL bShow, UINT nStatus)中去就OK了。
      

  11.   

    To: etre>>在CMainFrame中响应这个消息WM_COMMAND
    是否可以详细解释一下
      

  12.   

    这里指的是CView占满包括任务栏的整个屏幕:   如果有任务栏和状态栏,调用上面语句前把他们隐藏起来就上了。
      

  13.   

    #define IMF_FULLSCREEN WM_USER+110         CMainFrame* pMainFrame = new CMainFrame;
    if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
    return FALSE;
    m_pMainWnd = pMainFrame;
    pMainFrame->ShowWindow(SW_SHOWMAXIMIZED);
    pMainFrame->UpdateWindow();
             pMainFrame->SendMessage(IMF_FULLSCREEN,0,0);MainFrame.h
    WINDOWPLACEMENT m_wpPrev;
    CRect m_rectFullScreenWindow
    BOOL m_fullScreen
    afx_msg LRESULT OnFullScreen(WPARAM wParam, LPARAM lParam)ON_MESSAGE(IMF_FULLSCREEN,OnFullScreen)LRESULT  CMainFrame::OnFullScreen()
    {
      FullScreen();
    }void CMainFrame::FullScreen()
    {  
             WINDOWPLACEMENT wpNew;
    if (m_fullScreen)
    {
    m_wpPrev.length = sizeof m_wpPrev;
    GetWindowPlacement(&m_wpPrev);

    CMDIChildWnd* pChildWnd = MDIGetActive();
    CWnd* pViewWnd = pChildWnd->GetActiveView();
    if (pViewWnd == NULL)
    return; CRect rectDesktop, rectFrame, rectView; // Adjust RECT to new size of window
    VERIFY(::GetWindowRect(::GetDesktopWindow(), &rectDesktop));
    GetWindowRect(&rectFrame);
    pViewWnd->GetWindowRect(&rectView);
    rectFrame.InflateRect(
    rectView.left - rectDesktop.left,
    rectView.top - rectDesktop.top,
    rectDesktop.right - rectView.right,
    rectDesktop.bottom - rectView.bottom);//这里可以根据你需要自己设置变化啊

    // Remember this for OnGetMinMaxInfo()
    m_rectFullScreenWindow = rectFrame;

    wpNew = m_wpPrev;
    wpNew.showCmd = SW_SHOWNORMAL;
    wpNew.rcNormalPosition = rectFrame;
    m_fullScreen = true;
    }
    else
    {
    m_fullScreen = false;
    WINDOWPLACEMENT wpNew(m_wpPrev);
    VERIFY(::CopyRect(&wpNew.rcNormalPosition, &m_rectFullScreenWindow));
    VERIFY(SetWindowPlacement(&wpNew));
    wpNew = m_wpPrev;
    }

    VERIFY(SetWindowPlacement(&wpNew));}
      

  14.   

    在OnGetMinMaxInfo这个方法中加入CMainFrame::OnGetMinMaxInfo()
    {
    if(m_fullScreen)
    {
    lpMMI->ptMaxSize.x =
    lpMMI->ptMaxTrackSize.x = m_rectFullScreenWindow.Width(); lpMMI->ptMaxSize.y =
    lpMMI->ptMaxTrackSize.y = m_rectFullScreenWindow.Height();
    }
    }BOOL CMainFrame::PreTranslateMessage(MSG* pMsg) //ESC键退出
    {
    if(pMsg->wParam == VK_ESCAPE)
    {
    if(m_fullScreen)
    FullScreen();
              }
    }
      

  15.   

    IDR_FULLSCREEN
    你原来不是通过菜单栏命令全屏的吗,这是那个菜单id
      

  16.   

    问题搞定了,把全屏的调用加到OnCreate中就行了,怎么当时试的没成功呢?谢谢大家啦