您的位置:首页 > 其它

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();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: