下面的程序实现了你所需的要求:(多文档的,单文档的原理也是一样的)
http://210.77.145.209/dev/Visual%20C++/source%20code/Bitmap/dibimage.zip
仔细阅读 MainFrm.cpp的OnViewFullScreen()。这个我在单文档下试过,可以。
具体代码:(你要添加变量m_bIsFullScreen,m_Menu等,并修改下面的代码)
// if the view is now full screen, change the view to normal size and state
if (m_bIsFullScreen)
{
// add the WS_CAPTION and WS_THICKFRAME styles to the frame window
ModifyStyle(0,WS_CAPTION);
ModifyStyle(0,WS_THICKFRAME); // restore the frame window to normal size and state
ShowWindow(SW_SHOWNORMAL); // restore the default menu and show it
SetMenu(&m_Menu);
m_Menu.Detach();
//re show the toolbars
ShowControlBar(&m_HistogramBar, m_bHistogramVisible, FALSE);
ShowControlBar(&m_PaletteBar, m_bPaletteVisible, FALSE);
ShowControlBar(&m_wndToolBar, m_bToolbarVisible, FALSE);
ShowControlBar(&m_wndStatusBar, m_bStatusbarVisible, FALSE);
ShowControlBar(&m_wndToolBar2, m_bToolbar2Visible, FALSE); // set flag to indicate that frame window is now NOT full screen
m_bIsFullScreen = 0;
}
// if the view is now normal, change the view to full screen
else
{
//remember each of the controlbars visibility before we hide them
m_bHistogramVisible = ((m_HistogramBar.GetStyle() & WS_VISIBLE) != 0);
m_bPaletteVisible = ((m_PaletteBar.GetStyle() & WS_VISIBLE) != 0);
m_bToolbarVisible = ((m_wndToolBar.GetStyle() & WS_VISIBLE) != 0);
m_bStatusbarVisible = ((m_wndStatusBar.GetStyle() & WS_VISIBLE) != 0);
m_bToolbar2Visible = ((m_wndToolBar2.GetStyle() & WS_VISIBLE) != 0);
m_Menu.Attach(GetMenu()->m_hMenu); // remove the WS_CAPTION and WS_THICKFRAME styles from the frame window
ModifyStyle(WS_CAPTION,0);
ModifyStyle(WS_THICKFRAME,0);
// remove the default menu and erase the menu
SetMenu(NULL);
// show the now menuless and frameless window full screen
ShowWindow(SW_MAXIMIZE); ShowControlBar(&m_HistogramBar, FALSE, FALSE);
ShowControlBar(&m_PaletteBar, FALSE, FALSE);
ShowControlBar(&m_wndToolBar, FALSE, FALSE);
ShowControlBar(&m_wndStatusBar, FALSE, FALSE);
ShowControlBar(&m_wndToolBar2, FALSE, FALSE); CFrameWnd* pFrame = GetActiveFrame();
if (pFrame)
pFrame->ShowWindow(SW_MAXIMIZE); //reset the flag to indicate that the view is now full screen
m_bIsFullScreen = 1;
}
http://210.77.145.209/dev/Visual%20C++/source%20code/Bitmap/dibimage.zip
仔细阅读 MainFrm.cpp的OnViewFullScreen()。这个我在单文档下试过,可以。
具体代码:(你要添加变量m_bIsFullScreen,m_Menu等,并修改下面的代码)
// if the view is now full screen, change the view to normal size and state
if (m_bIsFullScreen)
{
// add the WS_CAPTION and WS_THICKFRAME styles to the frame window
ModifyStyle(0,WS_CAPTION);
ModifyStyle(0,WS_THICKFRAME); // restore the frame window to normal size and state
ShowWindow(SW_SHOWNORMAL); // restore the default menu and show it
SetMenu(&m_Menu);
m_Menu.Detach();
//re show the toolbars
ShowControlBar(&m_HistogramBar, m_bHistogramVisible, FALSE);
ShowControlBar(&m_PaletteBar, m_bPaletteVisible, FALSE);
ShowControlBar(&m_wndToolBar, m_bToolbarVisible, FALSE);
ShowControlBar(&m_wndStatusBar, m_bStatusbarVisible, FALSE);
ShowControlBar(&m_wndToolBar2, m_bToolbar2Visible, FALSE); // set flag to indicate that frame window is now NOT full screen
m_bIsFullScreen = 0;
}
// if the view is now normal, change the view to full screen
else
{
//remember each of the controlbars visibility before we hide them
m_bHistogramVisible = ((m_HistogramBar.GetStyle() & WS_VISIBLE) != 0);
m_bPaletteVisible = ((m_PaletteBar.GetStyle() & WS_VISIBLE) != 0);
m_bToolbarVisible = ((m_wndToolBar.GetStyle() & WS_VISIBLE) != 0);
m_bStatusbarVisible = ((m_wndStatusBar.GetStyle() & WS_VISIBLE) != 0);
m_bToolbar2Visible = ((m_wndToolBar2.GetStyle() & WS_VISIBLE) != 0);
m_Menu.Attach(GetMenu()->m_hMenu); // remove the WS_CAPTION and WS_THICKFRAME styles from the frame window
ModifyStyle(WS_CAPTION,0);
ModifyStyle(WS_THICKFRAME,0);
// remove the default menu and erase the menu
SetMenu(NULL);
// show the now menuless and frameless window full screen
ShowWindow(SW_MAXIMIZE); ShowControlBar(&m_HistogramBar, FALSE, FALSE);
ShowControlBar(&m_PaletteBar, FALSE, FALSE);
ShowControlBar(&m_wndToolBar, FALSE, FALSE);
ShowControlBar(&m_wndStatusBar, FALSE, FALSE);
ShowControlBar(&m_wndToolBar2, FALSE, FALSE); CFrameWnd* pFrame = GetActiveFrame();
if (pFrame)
pFrame->ShowWindow(SW_MAXIMIZE); //reset the flag to indicate that the view is now full screen
m_bIsFullScreen = 1;
}
我利用GetWindowPlacement() and SetWindowPlacement()
可以实现全屏显示,
但在但文挡中,只能使工具条和状态条消失,而不能全屏显示,不只为什么?
谢谢你的回答!
声明:
BOOL m_bFullScreen;
CRect m_FullScreenRect;
WINDOWPLACEMENT m_OldWndpl;
void OnFullScreen();
函数:
void CMainFrame::OnFullScreen()
{
/*
BOOL m_bFullScreen;
CRect m_FullScreenRect;
WINDOWPLACEMENT m_OldWndpl;
void OnFullScreen();
*/
//保存原来的窗口
GetWindowPlacement(&m_OldWndpl);
//保存控制条位置
CRect WindowRect,ClientRect;
GetWindowRect(&WindowRect);
RepositionBars(0,0xffff, AFX_IDW_PANE_FIRST,reposQuery,&ClientRect);
ClientToScreen(&ClientRect);
//显示客户区
m_FullScreenRect.left =WindowRect.left -ClientRect.left ;
m_FullScreenRect.top =WindowRect.top -ClientRect.top ;
m_FullScreenRect.right =WindowRect.right -ClientRect.right +ScreenWidth ;
m_FullScreenRect.bottom =WindowRect.bottom -ClientRect.bottom +ScreenHeight;
//设置全屏显示标志
m_bFullScreen=TRUE;
//全屏显示
WINDOWPLACEMENT wndpl;
wndpl.length =sizeof(WINDOWPLACEMENT);
wndpl.flags =0;
wndpl.showCmd =SW_SHOWNORMAL;
wndpl.rcNormalPosition =m_FullScreenRect;
SetWindowPlacement(&wndpl);
}
void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
if(m_bFullScreen){
lpMMI->ptMaxSize.x = m_FullScreenRect.Width();
lpMMI->ptMaxSize.y = m_FullScreenRect.Height ();
lpMMI->ptMaxPosition.x = m_FullScreenRect.left;
lpMMI->ptMaxPosition.y = m_FullScreenRect.top ;
lpMMI->ptMaxTrackSize.x =m_FullScreenRect.Width();
lpMMI->ptMaxTrackSize.y =m_FullScreenRect.Height ();
}
CFrameWnd::OnGetMinMaxInfo(lpMMI);
}