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; }
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));
AfxGetMainWnd()->SendMessage(WM_COMMAND,?);
pframe->SendMessage(WM_COMMAND,IDR_FULLSCREEN);
pframe->SendMessage(WM_COMMAND,IDR_FULLSCREEN);
OnCreate时Window还没建好,那么这段代码加到什么位置呢才能实现初始全屏呢?
因为执行全屏的函数必须在窗口正常创建好以后才能工作,
那么
AfxGetMainWnd()->SendMessage(WM_COMMAND,?);
放在代码中的什么位置才能保证在窗口正常创建好时执行呢?
{
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
cs.cx = GetSystemMetrics(SM_CXSCREEN);
cs.cy = GetSystemMetrics(SM_CYSCREEN);
试过了,好像不行啊这里指的是CView占满包括任务栏的整个屏幕
(不是最大化窗口)
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了。
是否可以详细解释一下
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));}
{
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();
}
}
你原来不是通过菜单栏命令全屏的吗,这是那个菜单id