本文介绍了在MFC中保存窗口大小的位置和状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我调出GUI,然后调整大小并关闭它,当我再次启动它时它会恢复原来的大小。

它应该记住旧值



我尝试了什么:



以下方法将在关闭GUI时启动它会写出大小

void CMainFrame :: OnDestroy()

{

m_bShuttingDown = true;



WINDOWPLACEMENT wp;

GetWindowPlacement(& wp);

AfxGetApp() - > WriteProfileBinary(_T(MainFrame),_ T( WP),(LPBYTE)& wp,sizeof(wp));

CFrameWndEx :: OnDestroy();

}



以下方法将在加载GUI时调用



If I bring up the GUI, and then I resize and close it, when I start it up again it reverts back to the original size.
it should remember the old values

What I have tried:

the below method will get intiate while closing GUI and it will write the size
void CMainFrame::OnDestroy()
{
m_bShuttingDown = true;

WINDOWPLACEMENT wp;
GetWindowPlacement(&wp);
AfxGetApp()->WriteProfileBinary(_T("MainFrame"), _T("WP"), (LPBYTE)&wp, sizeof(wp));
CFrameWndEx::OnDestroy();
}

the below method will get call while loading GUI

oid CMainFrame::OnShowWindow(BOOL bShow, UINT nStatus)
{
    CFrameWndEx::OnShowWindow(bShow, nStatus);

    if (bShow && !IsWindowVisible()) //The formal parameter bShow is true when the window is about to be shown,
                                        //and false when it is about to be hidden

    {

        WINDOWPLACEMENT *lwp;
        UINT nl;

        if (AfxGetApp()->GetProfileBinary(_T("MainFrame"), _T("WP"), (LPBYTE*)&lwp, &nl))
        {
            SetWindowPlacement(lwp);

            UpdateWindow();
            delete[] lwp;
        }
}the above method its returning old values but gui is positioning as per that values
could you please tell me if anything is wrong here

推荐答案

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    // ... (call OnCreate of base class)

    WINDOWPLACEMENT *lwp;
    UINT nl;
    if (AfxGetApp()->GetProfileBinary(_T("MainFrame"), _T("WP"), (LPBYTE*)&lwp, &nl))
    {
        // save show state
        m_nCmdShow = lwp->showCmd;
        // must set this to normal here
        lwp->showCmd = SW_SHOWNORMAL;
        SetWindowPlacement(lwp);
        delete[] lwp;
    }

    // ...
}

// To be called from InitInstance()
void CMainFrame::ShowWindowInitial()
{
    ShowWindow(m_nCmdShow);
    UpdateWindow();
}

BOOL CMyApp::InitInstance()
{
    // ...
    //CMainFrame pMainFrame = new CMainFrame;
    pMainFrame->ShowWindowInitial();
    // ...
}

[/ EDIT]


这篇关于在MFC中保存窗口大小的位置和状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 08:39
查看更多