Win32 框架文档视图(1)
2011-04-03 15:58
232 查看
5.1 如何禁止框架窗口在标题中显示文档名
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { if( !CMDIFrameWnd::PreCreateWindow(cs) ) return FALSE; //删除FWS_ADDTOTITLE风格 cs.style &= ~FWS_ADDTOTITLE; return TRUE; }
修改样式
5.2 如何设置文档的标题
SetTitle方法BOOL CDemoDoc::OnNewDocument() { if (!CDocument::OnNewDocument()) return FALSE; SetTitle(_T("NewDoc")); return TRUE; }
5.3 如何设置框架窗口的标题
两步BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs if( !CMDIChildWnd::PreCreateWindow(cs) ) return FALSE; //删除FWS_ADDTOTITLE风格 cs.style &= ~FWS_ADDTOTITLE; return TRUE; }
使用SetWindowText函数
int CChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1) return -1; SetWindowText(_T("Child Frame")); return 0; }
5.4 如何使主框架窗口初始时最大化或最小化
即ShowWindow函数的参数//最大化 m_nCmdShow = SW_SHOWMAXIMIZED; // //最小化 // m_nCmdShow = SW_SHOWMINIMIZED; pMainFrame->ShowWindow(m_nCmdShow);
5.5 如何使MDI子框架窗口初始时最大化或最小化
重写ActivateFrame方法void CChildFrame::ActivateFrame(int nCmdShow) { //最大化 nCmdShow = SW_SHOWMAXIMIZED; // //最小化 // nCmdShow = SW_SHOWMINIMIZED CMDIChildWnd::ActivateFrame(nCmdShow); }
5.6 如何使框架窗口保持最小化
同上方法//最小化 m_nCmdShow = SW_SHOWMINIMIZED; m_pMainWnd->ShowWindow(m_nCmdShow); m_pMainWnd->UpdateWindow();
5.7 如何设置框架窗口最大化时的大小和位置
OnGetMinMaxInfo方法,即WM_GETMINMAXINFO消息方法参考:http://blog.csdn.net/FlowShell/archive/2009/11/10/4795581.aspx
当最大化时则有如下限制
void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) { //设置窗口最大化时的大小 lpMMI->ptMaxSize.x = 800; lpMMI->ptMaxSize.y = 600; //设置窗口最大化时的位置 lpMMI->ptMaxPosition.x = 0; lpMMI->ptMaxPosition.y = 0; CFrameWnd::OnGetMinMaxInfo(lpMMI); }
5.8 如何设置框架窗口的大小范围
还是OnGetMinMaxInfo方法的使用,设置的参数发生了变化.犹如MaxWidth,MaxHeight和MixWidth,MixHeight
void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) { //设置窗口的最大尺寸 lpMMI->ptMaxTrackSize.x = 800; lpMMI->ptMaxTrackSize.y = 600; //设置窗口的最小尺寸 lpMMI->ptMinTrackSize.x = 400; lpMMI->ptMinTrackSize.y = 300; CFrameWnd::OnGetMinMaxInfo(lpMMI); }
5.9 如何保存或恢复框架窗口的状态
在关闭窗体时,将窗体相关状态信息写入注册表,下次初始化化时,读取注册表信息WriteProfileInt和GetProfileInt方法,
ActivateFrame事件和OnClose事件
void CMainFrame::ActivateFrame(int nCmdShow) { if (m_bFirst) { m_bFirst = FALSE; WINDOWPLACEMENT* pWndpl = new WINDOWPLACEMENT; pWndpl->length = sizeof(WINDOWPLACEMENT); CWinApp* pApp = AfxGetApp(); //恢复窗口位置 pWndpl->flags = pApp->GetProfileInt(_T("WINDOWPLACEMENT"), _T("FLAGS"), 0); pWndpl->showCmd = pApp->GetProfileInt(_T("WINDOWPLACEMENT"), _T("SHOWCMD"), 0); nCmdShow = pWndpl->showCmd; pWndpl->ptMinPosition.x = pApp->GetProfileInt(_T("WINDOWPLACEMENT"), _T("MINX"), 0); pWndpl->ptMinPosition.y = pApp->GetProfileInt(_T("WINDOWPLACEMENT"), _T("MINY"), 0); pWndpl->ptMaxPosition.x = pApp->GetProfileInt(_T("WINDOWPLACEMENT"), _T("MAXX"), 0); pWndpl->ptMaxPosition.y = pApp->GetProfileInt(_T("WINDOWPLACEMENT"), _T("MAXY"), 0); pWndpl->rcNormalPosition.top = pApp->GetProfileInt(_T("WINDOWPLACEMENT"), _T("TOP"), 0); pWndpl->rcNormalPosition.left = pApp->GetProfileInt(_T("WINDOWPLACEMENT"), _T("LEFT"), 0); pWndpl->rcNormalPosition.right = pApp->GetProfileInt(_T("WINDOWPLACEMENT"), _T("RIGHT"), 0); pWndpl->rcNormalPosition.bottom = pApp->GetProfileInt(_T("WINDOWPLACEMENT"), _T("BOTTOM"), 0); //设置窗口位置 SetWindowPlacement(pWndpl); delete pWndpl; } CFrameWnd::ActivateFrame(nCmdShow); } void CMainFrame::OnClose() { WINDOWPLACEMENT* pWndpl = new WINDOWPLACEMENT; pWndpl->length = sizeof(WINDOWPLACEMENT); //获得窗口位置 GetWindowPlacement(pWndpl); CWinApp* pApp = AfxGetApp(); //保存窗口位置 pApp->WriteProfileInt(_T("WINDOWPLACEMENT"), _T("FLAGS"), pWndpl->flags); pApp->WriteProfileInt(_T("WINDOWPLACEMENT"), _T("SHOWCMD"), pWndpl->showCmd); pApp->WriteProfileInt(_T("WINDOWPLACEMENT"), _T("MINX"), pWndpl->ptMinPosition.x); pApp->WriteProfileInt(_T("WINDOWPLACEMENT"), _T("MINY"), pWndpl->ptMinPosition.y); pApp->WriteProfileInt(_T("WINDOWPLACEMENT"), _T("MAXX"), pWndpl->ptMaxPosition.x); pApp->WriteProfileInt(_T("WINDOWPLACEMENT"), _T("MAXY"), pWndpl->ptMaxPosition.y); pApp->WriteProfileInt(_T("WINDOWPLACEMENT"), _T("TOP"), pWndpl->rcNormalPosition.left); pApp->WriteProfileInt(_T("WINDOWPLACEMENT"), _T("LEFT"), pWndpl->rcNormalPosition.top); pApp->WriteProfileInt(_T("WINDOWPLACEMENT"), _T("RIGHT"), pWndpl->rcNormalPosition.right); pApp->WriteProfileInt(_T("WINDOWPLACEMENT"), _T("BOTTOM"), pWndpl->rcNormalPosition.bottom); delete pWndpl; CFrameWnd::OnClose(); }
相关文章推荐
- Win32 框架文档视图(2)
- Win32 框架文档视图(3)
- MFC 框架文档视图关系
- vc++6.0中文档、视图与框架的互相调用
- MFC中获取各种类(文档、视图、框架、应用程序)指针的方法 .
- 详解MFC框架窗口、文档和视图
- MFC中文档视图框架和文档模板之间的关系
- 在基于对话框的程序中使用文档视图的框架,并将其用于打印
- VS2013/MFC编程入门之三十八(文档、视图和框架:分割窗口)
- (转)文档doc、视图view、框架frame相互之间的访问
- MFC中获取各种类(文档、视图、框架、应用程序)指针的方法
- 文档视图框架操作总结
- 框架窗口、文档和视图
- 获取主框架、子框架、文档、视图的指针
- VS2010/MFC编程入门之三十九(文档、视图和框架:概述)
- VS2010/MFC编程入门之四十一(文档、视图和框架:分割窗口)
- VS2010/MFC编程入门之四十(文档、视图和框架:各对象之间的关系)
- [MFC小笔记]框架/文档/视图之间的调用关系
- 文档、视图、框架窗口、文档模板之间的相互关系
- TN25 文档,视图和框架之创建