15,979
社区成员
发帖
与我相关
我的任务
分享
class CMainFrame : public CFrameWnd
{ private: //自己添加的三个成员变量
WINDOWPLACEMENT m_OldWndPlacement; //用来保存原窗口位置
BOOL m_bFullScreen; //全屏显示标志
CRect m_FullScreenRect; //表示全屏显示时的窗口位置
protected: CMainFrame();
DECLARE_DYNCREATE(CMainFrame)}
void CMainFrame::OnFullScreen()
{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;
m_FullScreenRect.top=WindowRect.top-ClientRect.top;
m_FullScreenRect.right=WindowRect.right-ClientRect.right+nFullWidth;
m_FullScreenRect.bottom=WindowRect.bottom-ClientRect.bottom+nFullHeight;
m_bFullScreen=TRUE; // 设置全屏显示标志为 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.Width();
lpMMI-> ptMaxPosition.y=m_FullScreenRect.Height();
// 最大的Track尺寸也要改变
lpMMI-> ptMaxTrackSize.x=m_FullScreenRect.Width();
lpMMI-> ptMaxTrackSize.y=m_FullScreenRect.Height();
}CFrameWnd::OnGetMinMaxInfo(lpMMI)
}
void CMainFrame::EndFullScreen()
{if(m_bFullScreen)
{// 退出全屏显示, 恢复原窗口显示
ShowWindow(SW_HIDE);
SetWindowPlacement(&m_OldWndPlace
ment);}}
void CFullScreenView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{if(nChar==VK_ESCAPE) // 如果按的键为Esc键
{// 获取主框架窗口的指针
CMainFrame *pFrame=(CMainFrame*)AfxGetApp()-> m_pMainWnd;
// 调用主窗口类的自定义函数 EndFullScreen ,便可退出全屏显示状态
pFrame-> EndFullScreen();}
CView::OnKeyDown(nChar, nRepCnt, nFlags);}
CRect rect;
GetClientRect(&rect); //取客户区大小
Old.x=rect.right-rect.left;
Old.y=rect.bottom-rect.top;
if(nType==SIZE_RESTORED||nType==SIZE_MAXIMIZED)//窗体大小发生变动。处理函数resize
{
resize();
}
void CDialogDlg::resize()
{
float fsp[2];
POINT Newp; //获取现在对话框的大小
CRect recta;
GetClientRect(&recta); //取客户区大小
Newp.x=recta.right-recta.left;
Newp.y=recta.bottom-recta.top;
fsp[0]=(float)Newp.x/Old.x;
fsp[1]=(float)Newp.y/Old.y;
CRect Rect;
int woc;
CPoint OldTLPoint,TLPoint; //左上角
CPoint OldBRPoint,BRPoint; //右下角
HWND hwndChild=::GetWindow(m_hWnd,GW_CHILD); //列出所有控件
while(hwndChild)
{
woc=::GetDlgCtrlID(hwndChild);//取得ID
GetDlgItem(woc)->GetWindowRect(Rect);
ScreenToClient(Rect);
OldTLPoint = Rect.TopLeft();
TLPoint.x = long(OldTLPoint.x*fsp[0]);
TLPoint.y = long(OldTLPoint.y*fsp[1]);
OldBRPoint = Rect.BottomRight();
BRPoint.x = long(OldBRPoint.x *fsp[0]);
BRPoint.y = long(OldBRPoint.y *fsp[1]);
Rect.SetRect(TLPoint,BRPoint);
GetDlgItem(woc)->MoveWindow(Rect,TRUE);
hwndChild=::GetWindow(hwndChild, GW_HWNDNEXT);
}
Old=Newp;
}