//实现方案1
在CMainFrame类中添加成员变量,函数
public:
//全屏实现
WINDOWPLACEMENT m_OldWndPlacement;
CRect m_FullScreenRect;
BOOL m_bFullScreen;
void OnFullScreen();
void OnExitFullScreen();
构造函数中初始化m_bFullScreen = FALSE;
cpp文件中实现函数
void CMainFrame::OnFullScreen()
{
if(!m_bFullScreen)
{
GetWindowPlacement(&m_OldWndPlacement);
CRect WindowRect;
GetWindowRect(&WindowRect);
CRect ClientRect;
RepositionBars(0, 0xffff, AFX_IDW_PANE_FIRST, reposQuery, &ClientRect);
ClientToScreen(&ClientRect);// 获取屏幕的分辨率
int nFullWidth=GetSystemMetrics(SM_CXSCREEN);
int nFullHeight=GetSystemMetrics(SM_CYSCREEN);// 将除控制条外的客户区全屏显示到从(0,0)到(nFullWidth, nFullHeight)区
//域, 将(0,0)和(nFullWidth, nFullHeight)两个点外扩充原窗口和除控制条之外的 客
//户区位置间的差值, 就得到全屏显示的窗口位置
m_FullScreenRect.left=WindowRect.left-ClientRect.left-1;
m_FullScreenRect.top=WindowRect.top-ClientRect.top-1;
m_FullScreenRect.right=WindowRect.right-ClientRect.right+nFullWidth+2;
//m_FullScreenRect.bottom=WindowRect.bottom/*-ClientRect.bottom+nFullHeight+2*/; //这种保留任务栏
//m_FullScreenRect.bottom=WindowRect.bottom-ClientRect.bottom+nFullHeight+2; //原始默认
//m_FullScreenRect.bottom=nFullHeight; //这样也保留也任务栏
m_FullScreenRect.bottom=WindowRect.bottom-ClientRect.bottom+nFullHeight+2;
m_bFullScreen=TRUE; // 设置全屏显示标志为 TRUE
// 进入全屏显示状态
WINDOWPLACEMENT wndpl;
wndpl.length=sizeof(WINDOWPLACEMENT);
wndpl.flags=0;
wndpl.showCmd=SW_SHOWNORMAL;
wndpl.rcNormalPosition=m_FullScreenRect;
SetWindowPlacement(&wndpl);
}
//else//恢复显示,可以单独写成一个函数,如果用快捷键可以直接切换
//{
// m_bFullScreen=false;
// ShowWindow(SW_SHOW);
// SetWindowPlacement(&m_OldWndPlacement);
//}
}
void CMainFrame::OnExitFullScreen()
{
if(m_bFullScreen)//恢复显示,可以单独写成一个函数,如果用快捷键可以直接切换
{
m_bFullScreen=false;
ShowWindow(SW_SHOW);
SetWindowPlacement(&m_OldWndPlacement);
}
}
视图类中调用访法:
void CXxForm::OnBnClickedBtnFull()
{
ShowCtrl(SW_HIDE); //设置两状态下,相关控件的显隐状态
m_bFull = true;
CMainFrame *myFram = (CMainFrame*)AfxGetMainWnd();
myFram->OnFullScreen();
}
void CXxForm::OnBnClickedBtnExitfull()
{
ShowCtrl(SW_SHOW);
m_bFull = false;
CMainFrame *myFram = (CMainFrame*)AfxGetMainWnd();
myFram->OnExitFullScreen();
}
void CXxForm::OnSize(UINT nType, int cx, int cy) //用于动态设置控件的位置
{
CFormView::OnSize(nType, cx, cy);
if(!bFlag)
return;
CRect rect;
GetClientRect(&rect);
if (m_bFull)
{
m_ListCtrl.MoveWindow(0, 0, rect.Width(), rect.Height());
m_ListCtrl.RedrawItems(0, m_ListCtrl.GetItemCount()-1);
}
else
{
m_ListCtrl.MoveWindow(120, 0, rect.Width()-120, rect.Height());
m_ListCtrl.RedrawItems(0, m_ListCtrl.GetItemCount()-1);
}
}
//实现方案2
//方案2 .h
BOOL m_FullScreen;
WINDOWPLA