MFC memory window position

1. WINDOWPLACEMENT (record can maximize, minimize, normal window position)

BOOL CtestDialogDlg::ReadWndPosition()
{
    WINDOWPLACEMENT wp;
    CFile file;
    if (!file.Open(_T("testDialog.position"), CFile::modeRead))
        return FALSE;
    UINT nByteRead = file.Read(&wp, sizeof(wp));
    if (sizeof(wp) != nByteRead)
        return FALSE;
    if(!::SetWindowPlacement(this->GetSafeHwnd(), &wp))
        return FALSE;
    file.Close();
    return TRUE;
}


BOOL CtestDialogDlg::WriteWndPosition()
{
    WINDOWPLACEMENT wp = { sizeof(wp) };
    ::GetWindowPlacement(this->GetSafeHwnd(), &wp);
    CFile file;
    if (!file.Open(_T("testDialog.position"), CFile::modeCreate | CFile::modeWrite))
        return FALSE;
    file.Write(&wp, sizeof(wp));
    file.Close();
    return TRUE;
}
//然后在OnInitDialog()中调用 ReadWndPosition()
//在OnDestroy()中调用 WriteWndPosition()
struct {tagWINDOWPLACEMENT typedef 
    UINT length; 
    UINT the flags; 
    UINT ShowCmd; 
    the POINT ptMinPosition; 
    the POINT ptMaxPosition; 
    the RECT rcNormalPosition; 
} WINDOWPLACEMENT; 
// When used, typically first length = sizeof (WINDOWPLACEMENT) 

normal window closes, length = 44, flags = 0, showCmd = 1, ptMinPosition = ptMaxPosition = {- 1, -1}, rcNormalPosition = window size when closed position. 
Minimized closed, length = 44, flags = 0 , showCmd = 2, ptMinPosition = {- 3200, -3200}, ptMaxPosition = {- 1, -1}, the position rcNormalPosition = minimize the size of the front window. 
Close maximized, length = 44, flags = 2 , showCmd = 3, ptMinPosition = ptMaxPosition = {- 1, -1}, rcNormalPosition = maximize the size of the front window position. 

showCmd values SW_SHOWNORMAL = 1 SW_HIDE = 0 SW_SHOWMAXIMIZED = 3 SW_SHOWMINIZED = 2

Guess you like

Origin www.cnblogs.com/htj10/p/12169081.html